|
PLearn 0.1
|
PLearn Mat: use numarray. More...
#include <PythonObjectWrapper.h>
Static Public Member Functions | |
| static PyObject * | newPyObject (const Mat &) |
PLearn Mat: use numarray.
Definition at line 624 of file PythonObjectWrapper.h.
| PyObject * PLearn::ConvertToPyObject< Mat >::newPyObject | ( | const Mat & | data | ) | [static] |
Definition at line 834 of file PythonObjectWrapper.cc.
References PLearn::TMat< T >::copy(), PLearn::TMat< T >::data(), PLearn::TMat< T >::isEmpty(), PLearn::TMat< T >::isNull(), PLearn::TMat< T >::length(), PLearn::TMat< T >::mod(), tReal, and PLearn::TMat< T >::width().
{
PyArrayObject* pyarr = 0;
if (data.isNull() || data.isEmpty())
pyarr = NA_NewArray(NULL, tReal, 2, data.length(), data.width());
else if (data.mod() == data.width())
pyarr = NA_NewArray(data.data(), tReal, 2, data.length(),
data.width());
else {
// static PyObject* NA_NewAll( int ndim, maybelong *shape, NumarrayType
// type, void *buffer, maybelong byteoffset, maybelong bytestride, int
// byteorder, int aligned, int writable)
//
// numarray from C data buffer. The new array has type type, ndim
// dimensions, and the length of each dimensions must be given in
// shape[ndim]. byteoffset, bytestride specify the data-positions in
// the C array to use. byteorder and aligned specify the corresponding
// parameters. byteorder takes one of the values NUM_BIG_ENDIAN or
// NUM_LITTLE_ENDIAN. writable defines whether the buffer object
// associated with the resuling array is readonly or writable. Data is
// copied from buffer into the memory object of the new array.
// maybelong shape[2];
// shape[0] = data.length();
// shape[1] = data.width();
// pyarr = NA_NewAll(2, shape, tReal, data.data(), 0,
// data.mod()*sizeof(real), NA_ByteOrder(), 1, 1);
// NOTE (NC) -- I could not get the above function to work; for now,
// simply copy the matrix to new storage before converting to Python.
Mat new_data = data.copy();
pyarr = NA_NewArray(new_data.data(), tReal, 2,
new_data.length(), new_data.width());
}
return (PyObject*)pyarr;
}

1.7.4