Skip to content
Snippets Groups Projects
Commit c07029b3 authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira
Browse files

Fixed issue #8. Segmentation fault when using the __repr__ method

parent 59e3341c
Branches
Tags
No related merge requests found
......@@ -444,11 +444,11 @@ PyObject* PyBobLearnLibsvmMachine_Repr(PyBobLearnLibsvmMachineObject* self) {
* <bob.learn.libsvm.Machine float64@(3, 2)>
*/
auto shape = make_safe(PyObject_GetAttrString((PyObject*)self, "shape"));
auto shape_str = make_safe(PyObject_Str(shape.get()));
PyObject* shape = Py_BuildValue("(nn)", self->cxx->inputSize(),
self->cxx->outputSize());
PyObject* retval = PyUnicode_FromFormat("<%s float64@%U>",
Py_TYPE(self)->tp_name, shape_str.get());
Py_TYPE(self)->tp_name, PyObject_Unicode(shape));
#if PYTHON_VERSION_HEX < 0x03000000
if (!retval) return 0;
......
......@@ -79,6 +79,7 @@ def test_can_load():
assert -1 in machine.labels
assert +1 in machine.labels
assert abs(machine.gamma - 0.0769231) < 1e-6
assert type(machine.__repr__()) is str
def test_can_save():
......@@ -251,6 +252,7 @@ def test_correctness_iris():
pred_labels, pred_probs = machine.predict_class_and_probabilities(data)
assert numpy.array_equal(pred_labels, real_labels)
assert numpy.all(abs(numpy.vstack(pred_probs) - numpy.vstack(real_probs)) < 1e-6)
@nose.tools.raises(RuntimeError)
def test_correctness_inputsize_exceeds():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment