Skip to content

Commit

Permalink
Solved more memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagofrepereira2012 committed Mar 1, 2015
1 parent e6470b3 commit c9ae99c
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bob/learn/em/empca_trainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ PyObject* PyBobLearnEMEMPCATrainer_getRng(PyBobLearnEMEMPCATrainerObject* self,
(PyBoostMt19937Object*)PyBoostMt19937_Type.tp_alloc(&PyBoostMt19937_Type, 0);

retval->rng = self->cxx->getRng().get();
return Py_BuildValue("O", retval);
return Py_BuildValue("N", retval);
BOB_CATCH_MEMBER("Rng method could not be read", 0)
}
int PyBobLearnEMEMPCATrainer_setRng(PyBobLearnEMEMPCATrainerObject* self, PyObject* value, void*) {
Expand Down
2 changes: 1 addition & 1 deletion bob/learn/em/isv_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ PyObject* PyBobLearnEMISVBase_getUBM(PyBobLearnEMISVBaseObject* self, void*){
(PyBobLearnEMGMMMachineObject*)PyBobLearnEMGMMMachine_Type.tp_alloc(&PyBobLearnEMGMMMachine_Type, 0);
retval->cxx = ubm_gmmMachine;

return Py_BuildValue("O",retval);
return Py_BuildValue("N",retval);
BOB_CATCH_MEMBER("ubm could not be read", 0)
}
int PyBobLearnEMISVBase_setUBM(PyBobLearnEMISVBaseObject* self, PyObject* value, void*){
Expand Down
2 changes: 1 addition & 1 deletion bob/learn/em/isv_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ PyObject* PyBobLearnEMISVMachine_getISVBase(PyBobLearnEMISVMachineObject* self,
(PyBobLearnEMISVBaseObject*)PyBobLearnEMISVBase_Type.tp_alloc(&PyBobLearnEMISVBase_Type, 0);
retval->cxx = isv_base_o;

return Py_BuildValue("O",retval);
return Py_BuildValue("N",retval);
BOB_CATCH_MEMBER("isv_base could not be read", 0)
}
int PyBobLearnEMISVMachine_setISVBase(PyBobLearnEMISVMachineObject* self, PyObject* value, void*){
Expand Down
2 changes: 1 addition & 1 deletion bob/learn/em/isv_trainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ PyObject* PyBobLearnEMISVTrainer_getRng(PyBobLearnEMISVTrainerObject* self, void
(PyBoostMt19937Object*)PyBoostMt19937_Type.tp_alloc(&PyBoostMt19937_Type, 0);

retval->rng = self->cxx->getRng().get();
return Py_BuildValue("O", retval);
return Py_BuildValue("N", retval);
BOB_CATCH_MEMBER("Rng method could not be read", 0)
}
int PyBobLearnEMISVTrainer_setRng(PyBobLearnEMISVTrainerObject* self, PyObject* value, void*) {
Expand Down
2 changes: 1 addition & 1 deletion bob/learn/em/jfa_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ PyObject* PyBobLearnEMJFABase_getUBM(PyBobLearnEMJFABaseObject* self, void*){
(PyBobLearnEMGMMMachineObject*)PyBobLearnEMGMMMachine_Type.tp_alloc(&PyBobLearnEMGMMMachine_Type, 0);
retval->cxx = ubm_gmmMachine;

return Py_BuildValue("O",retval);
return Py_BuildValue("N",retval);
BOB_CATCH_MEMBER("ubm could not be read", 0)
}
int PyBobLearnEMJFABase_setUBM(PyBobLearnEMJFABaseObject* self, PyObject* value, void*){
Expand Down
2 changes: 1 addition & 1 deletion bob/learn/em/jfa_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ PyObject* PyBobLearnEMJFAMachine_getJFABase(PyBobLearnEMJFAMachineObject* self,
(PyBobLearnEMJFABaseObject*)PyBobLearnEMJFABase_Type.tp_alloc(&PyBobLearnEMJFABase_Type, 0);
retval->cxx = jfa_base_o;

return Py_BuildValue("O",retval);
return Py_BuildValue("N",retval);
BOB_CATCH_MEMBER("jfa_base could not be read", 0)
}
int PyBobLearnEMJFAMachine_setJFABase(PyBobLearnEMJFAMachineObject* self, PyObject* value, void*){
Expand Down
2 changes: 1 addition & 1 deletion bob/learn/em/jfa_trainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ PyObject* PyBobLearnEMJFATrainer_getRng(PyBobLearnEMJFATrainerObject* self, void
(PyBoostMt19937Object*)PyBoostMt19937_Type.tp_alloc(&PyBoostMt19937_Type, 0);

retval->rng = self->cxx->getRng().get();
return Py_BuildValue("O", retval);
return Py_BuildValue("N", retval);
BOB_CATCH_MEMBER("Rng method could not be read", 0)
}
int PyBobLearnEMJFATrainer_setRng(PyBobLearnEMJFATrainerObject* self, PyObject* value, void*) {
Expand Down
2 changes: 1 addition & 1 deletion bob/learn/em/kmeans_trainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ PyObject* PyBobLearnEMKMeansTrainer_getRng(PyBobLearnEMKMeansTrainerObject* self
(PyBoostMt19937Object*)PyBoostMt19937_Type.tp_alloc(&PyBoostMt19937_Type, 0);

retval->rng = self->cxx->getRng().get();
return Py_BuildValue("O", retval);
return Py_BuildValue("N", retval);
BOB_CATCH_MEMBER("Rng method could not be read", 0)
}
int PyBobLearnEMKMeansTrainer_setRng(PyBobLearnEMKMeansTrainerObject* self, PyObject* value, void*) {
Expand Down
38 changes: 26 additions & 12 deletions bob/learn/em/plda_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ PyObject* PyBobLearnEMPLDAMachine_getPLDABase(PyBobLearnEMPLDAMachineObject* sel
(PyBobLearnEMPLDABaseObject*)PyBobLearnEMPLDABase_Type.tp_alloc(&PyBobLearnEMPLDABase_Type, 0);
retval->cxx = plda_base_o;

return Py_BuildValue("O",retval);
return Py_BuildValue("N",retval);
BOB_CATCH_MEMBER("plda_base could not be read", 0)
}
int PyBobLearnEMPLDAMachine_setPLDABase(PyBobLearnEMPLDAMachineObject* self, PyObject* value, void*){
Expand Down Expand Up @@ -642,21 +642,28 @@ static PyObject* PyBobLearnEMPLDAMachine_computeLogLikelihood(PyBobLearnEMPLDAMa
BOB_TRY

char** kwlist = compute_log_likelihood.kwlist(0);

PyBlitzArrayObject* samples;
PyArrayObject* numpy_samples;
PyObject* with_enrolled_samples = Py_True;

/*Convert to PyObject first to access the number of dimensions*/
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|O!", kwlist, &PyArray_Type, &numpy_samples,
&PyBool_Type, &with_enrolled_samples)) return 0;
auto numpy_samples_ = make_safe(numpy_samples);
Py_INCREF(numpy_samples);
int dim = PyArray_NDIM(numpy_samples);

if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|O!", kwlist, &PyBlitzArray_Converter, &samples,
&PyBool_Type, &with_enrolled_samples)) return 0;
/*Now converting to PyBlitzArrayObject*/
samples = reinterpret_cast<PyBlitzArrayObject*>(PyBlitzArray_FromNumpyArray(numpy_samples));
auto samples_ = make_safe(samples);

blitz::Array<double,2> blitz_test = *PyBlitzArrayCxx_AsBlitz<double,2>(samples);

//There are 2 methods in C++, one <double,1> and the another <double,2>
if (blitz_test.extent(1)==0)

/*Using the proper method according to the dimension*/
if (dim==1)
return Py_BuildValue("d",self->cxx->computeLogLikelihood(*PyBlitzArrayCxx_AsBlitz<double,1>(samples), f(with_enrolled_samples)));
else
return Py_BuildValue("d",self->cxx->computeLogLikelihood(*PyBlitzArrayCxx_AsBlitz<double,2>(samples), f(with_enrolled_samples)));


BOB_CATCH_MEMBER("`compute_log_likelihood` could not be read", 0)
}
Expand All @@ -678,13 +685,20 @@ static PyObject* PyBobLearnEMPLDAMachine_forward(PyBobLearnEMPLDAMachineObject*
char** kwlist = forward.kwlist(0);

PyBlitzArrayObject* samples;
PyArrayObject* numpy_samples;

if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&", kwlist, &PyBlitzArray_Converter, &samples)) return 0;
/*Convert to PyObject first to access the number of dimensions*/
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!", kwlist, &PyArray_Type, &numpy_samples)) return 0;
auto numpy_samples_ = make_safe(numpy_samples);
Py_INCREF(numpy_samples);
int dim = PyArray_NDIM(numpy_samples);

/*Now converting to PyBlitzArrayObject*/
samples = reinterpret_cast<PyBlitzArrayObject*>(PyBlitzArray_FromNumpyArray(numpy_samples));
auto samples_ = make_safe(samples);
blitz::Array<double,2> blitz_test = *PyBlitzArrayCxx_AsBlitz<double,2>(samples);

//There are 2 methods in C++, one <double,1> and the another <double,2>
if (blitz_test.extent(1)==0)
if(dim==1)
return Py_BuildValue("d",self->cxx->forward(*PyBlitzArrayCxx_AsBlitz<double,1>(samples)));
else
return Py_BuildValue("d",self->cxx->forward(*PyBlitzArrayCxx_AsBlitz<double,2>(samples)));
Expand Down
4 changes: 4 additions & 0 deletions bob/learn/em/test/test_plda.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ def test_plda_machine_log_likelihood_Python():
ar_s = numpy.vstack([ar_e, ar_p])
assert abs(m.compute_log_likelihood(ar_s, False) - compute_log_likelihood(ar_s, mu, C_F, C_G, sigma)) < 1e-10
ar_p2d = numpy.reshape(ar_p, (1,C_dim_d))

print ar_p.shape
a = m.compute_log_likelihood(ar_p, False)

assert abs(m.compute_log_likelihood(ar_p, False) - compute_log_likelihood(ar_p2d, mu, C_F, C_G, sigma)) < 1e-10

# Defines (random) samples and check forward method
Expand Down

0 comments on commit c9ae99c

Please sign in to comment.