Commit c3af3cf7 authored by Manuel Günther's avatar Manuel Günther
Browse files

Fixed memory leaks.

parent 1ddc74dc
......@@ -441,6 +441,9 @@ static PyObject* PyBobLearnMLPBackProp_train
&PyBlitzArray_Converter, &input,
&PyBlitzArray_Converter, &target)) return 0;
auto input_ = make_safe(input);
auto target_ = make_safe(target);
if (input->type_num != NPY_FLOAT64 || input->ndim != 2) {
PyErr_Format(PyExc_TypeError, "`%s' only supports 2D 64-bit float arrays for input array `input'", Py_TYPE(self)->tp_name);
return 0;
......
......@@ -253,8 +253,7 @@ static PyObject* apply_array(PyBobLearnCostObject* self, const char* fname,
}
Py_INCREF(result);
return PyBlitzArray_NUMPY_WRAP(reinterpret_cast<PyObject*>(result));
return PyBlitzArray_NUMPY_WRAP(Py_BuildValue("O", result));
}
......
......@@ -268,8 +268,7 @@ static PyObject* PyBobLearnMLPMachine_getWeights
PyTuple_SET_ITEM(retval, k, tmp);
}
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
......@@ -355,8 +354,7 @@ static PyObject* PyBobLearnMLPMachine_getBiases
PyTuple_SET_ITEM(retval, k, tmp);
}
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
......@@ -540,8 +538,7 @@ static PyObject* PyBobLearnMLPMachine_getShape
PyTuple_SET_ITEM(retval, k, Py_BuildValue("n", i->extent(0)));
}
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
static int PyBobLearnMLPMachine_setShape
......@@ -863,8 +860,7 @@ static PyObject* PyBobLearnMLPMachine_forward
return 0;
}
Py_INCREF(output);
return PyBlitzArray_NUMPY_WRAP(reinterpret_cast<PyObject*>(output));
return PyBlitzArray_NUMPY_WRAP(Py_BuildValue("O", output));
}
......
......@@ -378,8 +378,7 @@ static PyObject* create_module (void) {
return 0;
}
Py_INCREF(m);
return m;
return Py_BuildValue("O", m);
}
......
......@@ -67,8 +67,7 @@ static PyObject* unroll_from_machine(PyObject* args, PyObject* kwds) {
return 0;
}
Py_INCREF(parameters);
return PyBlitzArray_NUMPY_WRAP((PyObject*)parameters);
return PyBlitzArray_NUMPY_WRAP(Py_BuildValue("O", parameters));
}
......@@ -163,8 +162,7 @@ static PyObject* unroll_from_values(PyObject* args, PyObject* kwds) {
return 0;
}
Py_INCREF(parameters);
return PyBlitzArray_NUMPY_WRAP((PyObject*)parameters);
return PyBlitzArray_NUMPY_WRAP(Py_BuildValue("O", parameters));
}
......
......@@ -625,6 +625,9 @@ static PyObject* PyBobLearnMLPRProp_train
&PyBlitzArray_Converter, &input,
&PyBlitzArray_Converter, &target)) return 0;
auto input_ = make_safe(input);
auto target_ = make_safe(target);
if (input->type_num != NPY_FLOAT64 || input->ndim != 2) {
PyErr_Format(PyExc_TypeError, "`%s' only supports 2D 64-bit float arrays for input array `input'", Py_TYPE(self)->tp_name);
return 0;
......
......@@ -156,6 +156,13 @@ int PyBobLearnDataShuffler_Check(PyObject* o) {
return PyObject_IsInstance(o, reinterpret_cast<PyObject*>(&PyBobLearnDataShuffler_Type));
}
static void PyBobLearnDataShuffler_delete(PyBobLearnDataShufflerObject* self) {
delete self->cxx;
Py_TYPE(self)->tp_free((PyObject*)self);
}
PyDoc_STRVAR(s_draw_str, "draw");
PyDoc_STRVAR(s_draw_doc,
"o.draw([n, [data, [target, [rng]]]]) -> (data, target)\n\
......@@ -303,11 +310,9 @@ static PyObject* PyBobLearnDataShuffler_Call
}
//and finally we return...
Py_INCREF(data);
Py_INCREF(target);
return Py_BuildValue("OO",
PyBlitzArray_NUMPY_WRAP(reinterpret_cast<PyObject*>(data)),
PyBlitzArray_NUMPY_WRAP(reinterpret_cast<PyObject*>(target))
return Py_BuildValue("NN",
PyBlitzArray_NUMPY_WRAP(Py_BuildValue("O", data)),
PyBlitzArray_NUMPY_WRAP(Py_BuildValue("O", target))
);
}
......@@ -333,10 +338,10 @@ static PyObject* PyBobLearnDataShuffler_GetStdNorm
self->cxx->getStdNorm(*PyBlitzArrayCxx_AsBlitz<double,1>(mean),
*PyBlitzArrayCxx_AsBlitz<double,1>(std));
return Py_BuildValue("OO",
return Py_BuildValue("NN",
PyBlitzArray_NUMPY_WRAP((PyObject*)mean),
PyBlitzArray_NUMPY_WRAP((PyObject*)std)
);
);
}
......@@ -420,7 +425,7 @@ PyTypeObject PyBobLearnDataShuffler_Type = {
s_shuffler_str, /* tp_name */
sizeof(PyBobLearnDataShufflerObject), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
(destructor)PyBobLearnDataShuffler_delete,/* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
......
......@@ -558,6 +558,9 @@ static PyObject* PyBobLearnMLPTrainer_backwardStep
&PyBlitzArray_Converter, &input,
&PyBlitzArray_Converter, &target)) return 0;
auto input_ = make_safe(input);
auto target_ = make_safe(target);
if (input->type_num != NPY_FLOAT64 || input->ndim != 2) {
PyErr_Format(PyExc_TypeError, "`%s' only supports 2D 64-bit float arrays for input array `input'", Py_TYPE(self)->tp_name);
return 0;
......@@ -634,6 +637,9 @@ static PyObject* PyBobLearnMLPTrainer_cost
&PyBlitzArray_Converter, &target)) return 0;
}
auto input_ = make_xsafe(input);
auto target_ = make_safe(target);
/* Parses input arguments in a single shot */
if ((machine && !input) || (input && !machine)) {
......
......@@ -32,8 +32,7 @@ PyObject* convert_vector(const std::vector<blitz::Array<double,N>>& v) {
if (!arr) return 0;
PyTuple_SET_ITEM(retval, k, PyBlitzArray_NUMPY_WRAP(arr));
}
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
/**
......
......@@ -143,8 +143,7 @@ static PyObject* build_version_dictionary() {
if (!dict_steal(retval, "bob.io.base", bob_io_base_version())) return 0;
if (!dict_steal(retval, "bob.learn.activation", bob_learn_activation_version())) return 0;
Py_INCREF(retval);
return retval;
return Py_BuildValue("O", retval);
}
static PyMethodDef module_methods[] = {
......@@ -193,8 +192,7 @@ static PyObject* create_module (void) {
return 0;
}
Py_INCREF(m);
return m;
return Py_BuildValue("O", m);
}
......
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