Commit ecab6dfa authored by André Anjos's avatar André Anjos 💬
Browse files

Remove requirement for std::unique_ptr (fix OSX 10.8.x builds)

parent 4376f915
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#define BOB_LEARN_LIBSVM_TRAINER_H #define BOB_LEARN_LIBSVM_TRAINER_H
#include <vector> #include <vector>
#include <memory>
#include "machine.h" #include "machine.h"
namespace bob { namespace learn { namespace libsvm { namespace bob { namespace learn { namespace libsvm {
...@@ -55,15 +54,17 @@ namespace bob { namespace learn { namespace libsvm { ...@@ -55,15 +54,17 @@ namespace bob { namespace learn { namespace libsvm {
* the number of classes is greater than 2, labels are picked starting * the number of classes is greater than 2, labels are picked starting
* from 1 (i.e., 1, 2, 3, 4, etc.). If what you want is regression, the * from 1 (i.e., 1, 2, 3, 4, etc.). If what you want is regression, the
* size of the input data array should be 1. * size of the input data array should be 1.
*
* Returns a new object you must deallocate yourself.
*/ */
std::unique_ptr<bob::learn::libsvm::Machine> train bob::learn::libsvm::Machine* train
(const std::vector<blitz::Array<double,2> >& data) const; (const std::vector<blitz::Array<double,2> >& data) const;
/** /**
* This version accepts scaling parameters that will be applied * This version accepts scaling parameters that will be applied
* column-wise to the input data. * column-wise to the input data.
*/ */
std::unique_ptr<bob::learn::libsvm::Machine> train bob::learn::libsvm::Machine* train
(const std::vector<blitz::Array<double,2> >& data, (const std::vector<blitz::Array<double,2> >& data,
const blitz::Array<double,1>& input_subtract, const blitz::Array<double,1>& input_subtract,
const blitz::Array<double,1>& input_division) const; const blitz::Array<double,1>& input_division) const;
......
...@@ -649,17 +649,17 @@ static PyObject* PyBobLearnLibsvmTrainer_train ...@@ -649,17 +649,17 @@ static PyObject* PyBobLearnLibsvmTrainer_train
/** all basic checks are done, can call the machine now **/ /** all basic checks are done, can call the machine now **/
try { try {
bob::learn::libsvm::Machine* machine;
if (subtract && divide) { if (subtract && divide) {
auto machine = self->cxx->train(Xseq, machine = self->cxx->train(Xseq,
*PyBlitzArrayCxx_AsBlitz<double,1>(subtract), *PyBlitzArrayCxx_AsBlitz<double,1>(subtract),
*PyBlitzArrayCxx_AsBlitz<double,1>(divide) *PyBlitzArrayCxx_AsBlitz<double,1>(divide)
); );
return PyBobLearnLibsvmMachine_NewFromMachine(machine.release());
} }
else { else {
auto machine = self->cxx->train(Xseq); machine = self->cxx->train(Xseq);
return PyBobLearnLibsvmMachine_NewFromMachine(machine.release());
} }
return PyBobLearnLibsvmMachine_NewFromMachine(machine);
} }
catch (std::exception& e) { catch (std::exception& e) {
PyErr_SetString(PyExc_RuntimeError, e.what()); PyErr_SetString(PyExc_RuntimeError, e.what());
......
...@@ -202,7 +202,7 @@ static void svm_model_free(svm_model*& m) { ...@@ -202,7 +202,7 @@ static void svm_model_free(svm_model*& m) {
#endif #endif
} }
std::unique_ptr<bob::learn::libsvm::Machine> bob::learn::libsvm::Trainer::train bob::learn::libsvm::Machine* bob::learn::libsvm::Trainer::train
(const std::vector<blitz::Array<double, 2> >& data, (const std::vector<blitz::Array<double, 2> >& data,
const blitz::Array<double,1>& input_subtraction, const blitz::Array<double,1>& input_subtraction,
const blitz::Array<double,1>& input_division) const { const blitz::Array<double,1>& input_division) const {
...@@ -253,8 +253,7 @@ std::unique_ptr<bob::learn::libsvm::Machine> bob::learn::libsvm::Trainer::train ...@@ -253,8 +253,7 @@ std::unique_ptr<bob::learn::libsvm::Machine> bob::learn::libsvm::Trainer::train
boost::shared_ptr<svm_model> new_model = boost::shared_ptr<svm_model> new_model =
bob::learn::libsvm::svm_unpickle(bob::learn::libsvm::svm_pickle(model)); bob::learn::libsvm::svm_unpickle(bob::learn::libsvm::svm_pickle(model));
std::unique_ptr<bob::learn::libsvm::Machine> retval auto retval = new bob::learn::libsvm::Machine(new_model);
(new bob::learn::libsvm::Machine(new_model));
//sets up the scaling parameters given as input //sets up the scaling parameters given as input
retval->setInputSubtraction(input_subtraction); retval->setInputSubtraction(input_subtraction);
...@@ -263,7 +262,7 @@ std::unique_ptr<bob::learn::libsvm::Machine> bob::learn::libsvm::Trainer::train ...@@ -263,7 +262,7 @@ std::unique_ptr<bob::learn::libsvm::Machine> bob::learn::libsvm::Trainer::train
return retval; return retval;
} }
std::unique_ptr<bob::learn::libsvm::Machine> bob::learn::libsvm::Trainer::train bob::learn::libsvm::Machine* bob::learn::libsvm::Trainer::train
(const std::vector<blitz::Array<double,2> >& data) const { (const std::vector<blitz::Array<double,2> >& data) const {
int n_features = data[0].extent(blitz::secondDim); int n_features = data[0].extent(blitz::secondDim);
blitz::Array<double,1> sub(n_features); blitz::Array<double,1> sub(n_features);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment