Commit c67254c4 authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira

Merge pull request #9 from tiagofrepereira2012/master

Fixed issue #8. Segmentation fault when using the __repr__ method
parents 59e3341c 70b73aa5
......@@ -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_STR(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():
......
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