Skip to content
Snippets Groups Projects
Commit 6062ded3 authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

Merge branch 'PyBobIo_FilenameConverter' into 'master'

Switched to new API of FilenameConverter

See merge request !6
parents 521fe146 f28817da
Branches
Tags
1 merge request!6Switched to new API of FilenameConverter
Pipeline #
......@@ -56,22 +56,14 @@ static int PyBobLearnLibsvmFile_init
static const char* const_kwlist[] = {"path", 0};
static char** kwlist = const_cast<char**>(const_kwlist);
PyObject* filename = 0;
const char* filename = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kwlist,
&PyBobIo_FilenameConverter, &filename))
return -1;
auto filename_ = make_safe(filename);
#if PY_VERSION_HEX >= 0x03000000
const char* c_filename = PyBytes_AS_STRING(filename);
#else
const char* c_filename = PyString_AS_STRING(filename);
#endif
try {
self->cxx = new bob::learn::libsvm::File(c_filename);
self->cxx = new bob::learn::libsvm::File(filename);
}
catch (std::exception& ex) {
PyErr_SetString(PyExc_RuntimeError, ex.what());
......@@ -488,10 +480,10 @@ static PyObject* PyBobLearnLibsvmFile_read_all
auto bzval = PyBlitzArrayCxx_AsBlitz<double,2>(values);
blitz::Range all = blitz::Range::all();
int k = 0;
while ((self->cxx->good()) && ((size_t)k < self->cxx->samples())) {
blitz::Array<double,1> v_ = (*bzval)(k, all);
int label = 0;
bool ok = self->cxx->read_(label, v_);
if (ok) (*bzlab)(k) = label;
......
......@@ -69,22 +69,14 @@ static int PyBobLearnLibsvmMachine_init_svmfile
static const char* const_kwlist[] = {"filename", 0};
static char** kwlist = const_cast<char**>(const_kwlist);
PyObject* filename = 0;
const char* filename = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kwlist,
&PyBobIo_FilenameConverter, &filename))
return -1;
auto filename_ = make_safe(filename);
#if PY_VERSION_HEX >= 0x03000000
const char* c_filename = PyBytes_AS_STRING(filename);
#else
const char* c_filename = PyString_AS_STRING(filename);
#endif
try {
self->cxx = new bob::learn::libsvm::Machine(c_filename);
self->cxx = new bob::learn::libsvm::Machine(filename);
}
catch (std::exception& ex) {
PyErr_SetString(PyExc_RuntimeError, ex.what());
......@@ -985,31 +977,22 @@ static PyObject* PyBobLearnLibsvmMachine_Save
}
// try a filename conversion and use libsvm's original file format
PyObject* filename = 0;
const char* filename = 0;
int ok = PyBobIo_FilenameConverter(f, &filename);
if (!ok) {
PyErr_Format(PyExc_TypeError, "cannot convert `%s' into a valid string for a file path - objects of type `%s' can only save to HDF5 files or text files using LIBSVM's original file format (pass a string referring to a valid filesystem path in this case)", Py_TYPE(f)->tp_name, Py_TYPE(self)->tp_name);
return 0;
}
// at this point we know we have a valid file system string
auto filename_ = make_safe(filename);
#if PY_VERSION_HEX >= 0x03000000
const char* c_filename = PyBytes_AS_STRING(filename);
#else
const char* c_filename = PyString_AS_STRING(filename);
#endif
try {
self->cxx->save(c_filename);
self->cxx->save(filename);
}
catch (std::exception& ex) {
PyErr_SetString(PyExc_RuntimeError, ex.what());
return 0;
}
catch (...) {
PyErr_Format(PyExc_RuntimeError, "`%s' cannot write data to file `%s' (using LIBSVM's original text format): unknown exception caught", Py_TYPE(self)->tp_name, c_filename);
PyErr_Format(PyExc_RuntimeError, "`%s' cannot write data to file `%s' (using LIBSVM's original text format): unknown exception caught", Py_TYPE(self)->tp_name, filename);
return 0;
}
......
......@@ -2,4 +2,4 @@ setuptools
bob.extension
bob.blitz
bob.core
bob.io.base
bob.io.base > 2.1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment