Skip to content

Commit 8fbd8ef

Browse files
committed
core: improve readibility
1 parent c4d2239 commit 8fbd8ef

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

include/eigenpy/details.hpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,32 +237,39 @@ namespace eigenpy
237237
}
238238
};
239239
#endif
240+
240241
/* --- TO PYTHON -------------------------------------------------------------- */
242+
241243
template<typename MatType>
242244
struct EigenToPy
243245
{
244-
static PyObject* convert(MatType const& mat)
246+
static PyObject* convert(MatType const & mat)
245247
{
246248
typedef typename MatType::Scalar T;
249+
typedef typename MatType::Scalar Scalar;
247250
assert( (mat.rows()<INT_MAX) && (mat.cols()<INT_MAX)
248251
&& "Matrix range larger than int ... should never happen." );
249252
const int R = (int)mat.rows(), C = (int)mat.cols();
250253

251254
PyArrayObject* pyArray;
252-
if(C == 1 && NumpyType::getType() == ARRAY_TYPE)
255+
// Allocate Python memory
256+
if(C == 1 && NumpyType::getType() == ARRAY_TYPE) // Handle array with a single dimension
253257
{
254258
npy_intp shape[1] = { R };
255259
pyArray = (PyArrayObject*) PyArray_SimpleNew(1, shape,
256-
NumpyEquivalentType<T>::type_code);
260+
NumpyEquivalentType<Scalar>::type_code);
257261
}
258262
else
259263
{
260264
npy_intp shape[2] = { R,C };
261265
pyArray = (PyArrayObject*) PyArray_SimpleNew(2, shape,
262-
NumpyEquivalentType<T>::type_code);
266+
NumpyEquivalentType<Scalar>::type_code);
263267
}
264268

269+
// Allocate memory
265270
EigenObjectAllocator<MatType>::convert(mat,pyArray);
271+
272+
// Create an instance (either np.array or np.matrix)
266273
return NumpyType::getInstance().make(pyArray).ptr();
267274
}
268275
};
@@ -395,7 +402,7 @@ namespace eigenpy
395402
return pyObj;
396403
}
397404

398-
// Convert obj_ptr into an Eigen::Vector
405+
/// \brief Allocate memory and copy pyObj in the new storage
399406
static void construct(PyObject* pyObj,
400407
bp::converter::rvalue_from_python_stage1_data* memory)
401408
{

0 commit comments

Comments
 (0)