Skip to content

Commit

Permalink
Replaced mStep with more pythonic m_step; replaces m_step1 with m_ste…
Browse files Browse the repository at this point in the history
…p_v (and accordingly) to be more precise
  • Loading branch information
Manuel Guenther committed Mar 6, 2015
1 parent 3e1e1fa commit 7dbafb3
Show file tree
Hide file tree
Showing 14 changed files with 255 additions and 261 deletions.
43 changes: 21 additions & 22 deletions bob/learn/em/empca_trainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static PyObject* PyBobLearnEMEMPCATrainer_RichCompare(PyBobLearnEMEMPCATrainerOb
/************ Variables Section ***********************************/
/******************************************************************/

static PyGetSetDef PyBobLearnEMEMPCATrainer_getseters[] = {
static PyGetSetDef PyBobLearnEMEMPCATrainer_getseters[] = {
{0} // Sentinel
};

Expand Down Expand Up @@ -173,12 +173,12 @@ static PyObject* PyBobLearnEMEMPCATrainer_initialize(PyBobLearnEMEMPCATrainerObj
&PyBlitzArray_Converter, &data,
&PyBoostMt19937_Type, &rng)) return 0;
auto data_ = make_safe(data);

if(rng){
boost::shared_ptr<boost::mt19937> rng_cpy = (boost::shared_ptr<boost::mt19937>)new boost::mt19937(*rng->rng);
self->cxx->setRng(rng_cpy);
}


self->cxx->initialize(*linear_machine->cxx, *PyBlitzArrayCxx_AsBlitz<double,2>(data));

Expand All @@ -188,21 +188,21 @@ static PyObject* PyBobLearnEMEMPCATrainer_initialize(PyBobLearnEMEMPCATrainerObj
}


/*** eStep ***/
static auto eStep = bob::extension::FunctionDoc(
"eStep",
/*** e_step ***/
static auto e_step = bob::extension::FunctionDoc(
"e_step",
"",
"",
true
)
.add_prototype("linear_machine,data")
.add_parameter("linear_machine", ":py:class:`bob.learn.linear.Machine`", "LinearMachine Object")
.add_parameter("data", "array_like <float, 2D>", "Input data");
static PyObject* PyBobLearnEMEMPCATrainer_eStep(PyBobLearnEMEMPCATrainerObject* self, PyObject* args, PyObject* kwargs) {
static PyObject* PyBobLearnEMEMPCATrainer_e_step(PyBobLearnEMEMPCATrainerObject* self, PyObject* args, PyObject* kwargs) {
BOB_TRY

/* Parses input arguments in a single shot */
char** kwlist = eStep.kwlist(0);
char** kwlist = e_step.kwlist(0);

PyBobLearnLinearMachineObject* linear_machine;
PyBlitzArrayObject* data = 0;
Expand All @@ -213,27 +213,27 @@ static PyObject* PyBobLearnEMEMPCATrainer_eStep(PyBobLearnEMEMPCATrainerObject*
self->cxx->eStep(*linear_machine->cxx, *PyBlitzArrayCxx_AsBlitz<double,2>(data));


BOB_CATCH_MEMBER("cannot perform the eStep method", 0)
BOB_CATCH_MEMBER("cannot perform the e_step method", 0)

Py_RETURN_NONE;
}


/*** mStep ***/
static auto mStep = bob::extension::FunctionDoc(
"mStep",
/*** m_step ***/
static auto m_step = bob::extension::FunctionDoc(
"m_step",
"",
0,
true
)
.add_prototype("linear_machine,data")
.add_parameter("linear_machine", ":py:class:`bob.learn.em.LinearMachine`", "LinearMachine Object")
.add_parameter("data", "array_like <float, 2D>", "Input data");
static PyObject* PyBobLearnEMEMPCATrainer_mStep(PyBobLearnEMEMPCATrainerObject* self, PyObject* args, PyObject* kwargs) {
static PyObject* PyBobLearnEMEMPCATrainer_m_step(PyBobLearnEMEMPCATrainerObject* self, PyObject* args, PyObject* kwargs) {
BOB_TRY

/* Parses input arguments in a single shot */
char** kwlist = mStep.kwlist(0);
char** kwlist = m_step.kwlist(0);

PyBobLearnLinearMachineObject* linear_machine;
PyBlitzArrayObject* data = 0;
Expand All @@ -244,7 +244,7 @@ static PyObject* PyBobLearnEMEMPCATrainer_mStep(PyBobLearnEMEMPCATrainerObject*
self->cxx->mStep(*linear_machine->cxx, *PyBlitzArrayCxx_AsBlitz<double,2>(data));


BOB_CATCH_MEMBER("cannot perform the mStep method", 0)
BOB_CATCH_MEMBER("cannot perform the m_step method", 0)

Py_RETURN_NONE;
}
Expand Down Expand Up @@ -284,16 +284,16 @@ static PyMethodDef PyBobLearnEMEMPCATrainer_methods[] = {
initialize.doc()
},
{
eStep.name(),
(PyCFunction)PyBobLearnEMEMPCATrainer_eStep,
e_step.name(),
(PyCFunction)PyBobLearnEMEMPCATrainer_e_step,
METH_VARARGS|METH_KEYWORDS,
eStep.doc()
e_step.doc()
},
{
mStep.name(),
(PyCFunction)PyBobLearnEMEMPCATrainer_mStep,
m_step.name(),
(PyCFunction)PyBobLearnEMEMPCATrainer_m_step,
METH_VARARGS|METH_KEYWORDS,
mStep.doc()
m_step.doc()
},
{
compute_likelihood.name(),
Expand Down Expand Up @@ -340,4 +340,3 @@ bool init_BobLearnEMEMPCATrainer(PyObject* module)
Py_INCREF(&PyBobLearnEMEMPCATrainer_Type);
return PyModule_AddObject(module, "EMPCATrainer", (PyObject*)&PyBobLearnEMEMPCATrainer_Type) >= 0;
}

4 changes: 2 additions & 2 deletions bob/learn/em/isv_trainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ static PyObject* PyBobLearnEMISVTrainer_initialize(PyBobLearnEMISVTrainerObject*

/*** e_step ***/
static auto e_step = bob::extension::FunctionDoc(
"eStep",
"e_step",
"Call the e-step procedure (for the U subspace).",
"",
true
Expand Down Expand Up @@ -473,7 +473,7 @@ static PyObject* PyBobLearnEMISVTrainer_e_step(PyBobLearnEMISVTrainerObject* sel

/*** m_step ***/
static auto m_step = bob::extension::FunctionDoc(
"mStep",
"m_step",
"Call the m-step procedure (for the U subspace).",
"",
true
Expand Down
21 changes: 10 additions & 11 deletions bob/learn/em/ivector_trainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static int extract_GMMStats_1d(PyObject *list,
std::vector<bob::learn::em::GMMStats>& training_data)
{
for (int i=0; i<PyList_GET_SIZE(list); i++){

PyBobLearnEMGMMStatsObject* stats;
if (!PyArg_Parse(PyList_GetItem(list, i), "O!", &PyBobLearnEMGMMStats_Type, &stats)){
PyErr_Format(PyExc_RuntimeError, "Expected GMMStats objects");
Expand Down Expand Up @@ -76,7 +76,7 @@ static int PyBobLearnEMIVectorTrainer_init_bool(PyBobLearnEMIVectorTrainerObject
//Parsing the input argments
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!", kwlist, &PyBool_Type, &update_sigma))
return -1;

self->cxx.reset(new bob::learn::em::IVectorTrainer(f(update_sigma)));
return 0;
}
Expand Down Expand Up @@ -105,11 +105,11 @@ static int PyBobLearnEMIVectorTrainer_init(PyBobLearnEMIVectorTrainerObject* sel
}

// If the constructor input is IVectorTrainer object
if(PyBobLearnEMIVectorTrainer_Check(arg))
if(PyBobLearnEMIVectorTrainer_Check(arg))
return PyBobLearnEMIVectorTrainer_init_copy(self, args, kwargs);
else
return PyBobLearnEMIVectorTrainer_init_bool(self, args, kwargs);
return PyBobLearnEMIVectorTrainer_init_bool(self, args, kwargs);

}
default:{
PyErr_Format(PyExc_RuntimeError, "number of arguments mismatch - %s requires only 0 or 1 arguments, but you provided %d (see help)", Py_TYPE(self)->tp_name, nargs);
Expand Down Expand Up @@ -268,14 +268,14 @@ int PyBobLearnEMIVectorTrainer_set_acc_snormij(PyBobLearnEMIVectorTrainerObject*



static PyGetSetDef PyBobLearnEMIVectorTrainer_getseters[] = {
static PyGetSetDef PyBobLearnEMIVectorTrainer_getseters[] = {
{
acc_nij_wij2.name(),
(getter)PyBobLearnEMIVectorTrainer_get_acc_nij_wij2,
(setter)PyBobLearnEMIVectorTrainer_set_acc_nij_wij2,
acc_nij_wij2.doc(),
0
},
},
{
acc_fnormij_wij.name(),
(getter)PyBobLearnEMIVectorTrainer_get_acc_fnormij_wij,
Expand Down Expand Up @@ -338,7 +338,7 @@ static PyObject* PyBobLearnEMIVectorTrainer_initialize(PyBobLearnEMIVectorTraine

/*** e_step ***/
static auto e_step = bob::extension::FunctionDoc(
"eStep",
"e_step",
"Call the e-step procedure (for the U subspace).",
"",
true
Expand Down Expand Up @@ -369,7 +369,7 @@ static PyObject* PyBobLearnEMIVectorTrainer_e_step(PyBobLearnEMIVectorTrainerObj

/*** m_step ***/
static auto m_step = bob::extension::FunctionDoc(
"mStep",
"m_step",
"Call the m-step procedure (for the U subspace).",
"",
true
Expand All @@ -380,7 +380,7 @@ static auto m_step = bob::extension::FunctionDoc(
static PyObject* PyBobLearnEMIVectorTrainer_m_step(PyBobLearnEMIVectorTrainerObject* self, PyObject* args, PyObject* kwargs) {
BOB_TRY

// Parses input arguments in a single shot
// Parses input arguments in a single shot
char** kwlist = m_step.kwlist(0);

PyBobLearnEMIVectorMachineObject* ivector_machine = 0;
Expand Down Expand Up @@ -456,4 +456,3 @@ bool init_BobLearnEMIVectorTrainer(PyObject* module)
Py_INCREF(&PyBobLearnEMIVectorTrainer_Type);
return PyModule_AddObject(module, "IVectorTrainer", (PyObject*)&PyBobLearnEMIVectorTrainer_Type) >= 0;
}

Loading

0 comments on commit 7dbafb3

Please sign in to comment.