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

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

parent 4376f915
......@@ -11,7 +11,6 @@
#define BOB_LEARN_LIBSVM_TRAINER_H
#include <vector>
#include <memory>
#include "machine.h"
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
* 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.
*
* 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;
/**
* This version accepts scaling parameters that will be applied
* 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 blitz::Array<double,1>& input_subtract,
const blitz::Array<double,1>& input_division) const;
......
......@@ -649,17 +649,17 @@ static PyObject* PyBobLearnLibsvmTrainer_train
/** all basic checks are done, can call the machine now **/
try {
bob::learn::libsvm::Machine* machine;
if (subtract && divide) {
auto machine = self->cxx->train(Xseq,
machine = self->cxx->train(Xseq,
*PyBlitzArrayCxx_AsBlitz<double,1>(subtract),
*PyBlitzArrayCxx_AsBlitz<double,1>(divide)
);
return PyBobLearnLibsvmMachine_NewFromMachine(machine.release());
}
else {
auto machine = self->cxx->train(Xseq);
return PyBobLearnLibsvmMachine_NewFromMachine(machine.release());
machine = self->cxx->train(Xseq);
}
return PyBobLearnLibsvmMachine_NewFromMachine(machine);
}
catch (std::exception& e) {
PyErr_SetString(PyExc_RuntimeError, e.what());
......
......@@ -202,7 +202,7 @@ static void svm_model_free(svm_model*& m) {
#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 blitz::Array<double,1>& input_subtraction,
const blitz::Array<double,1>& input_division) const {
......@@ -253,8 +253,7 @@ std::unique_ptr<bob::learn::libsvm::Machine> bob::learn::libsvm::Trainer::train
boost::shared_ptr<svm_model> new_model =
bob::learn::libsvm::svm_unpickle(bob::learn::libsvm::svm_pickle(model));
std::unique_ptr<bob::learn::libsvm::Machine> retval
(new bob::learn::libsvm::Machine(new_model));
auto retval = new bob::learn::libsvm::Machine(new_model);
//sets up the scaling parameters given as input
retval->setInputSubtraction(input_subtraction);
......@@ -263,7 +262,7 @@ std::unique_ptr<bob::learn::libsvm::Machine> bob::learn::libsvm::Trainer::train
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 {
int n_features = data[0].extent(blitz::secondDim);
blitz::Array<double,1> sub(n_features);
......
Markdown is supported
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