[Numpy-discussion] Help with wrapper ndarray to c array
mail at enricong.com
Thu Dec 8 20:14:48 EST 2011
I am trying to pass a multi-dimensional ndarray to C as a multi-
dimensional C array for the purposes of passing it to mathematica.
They already have a wrapper for a 1-D Python list. where the list is
copied to "list". Shown below:
static PyObject * mathlink_PutIntegerList(mathlink_Link *self,
long i, len, result;
len = PyObject_Length(seq);
list = PyMem_New(int, len);
for(i = 0; i < len; i++)
obj = PySequence_GetItem(seq, i);
list[i] = PyInt_AsLong(obj);
CheckForThreadsAndRunLink(self,result = MLPutIntegerList(self->lp,
I would like to create a similar wrapper which accepts an ndarray and
provides the array laid out in memory like a C array declared
explicitly as "int a[m][n]...". I also need to pass the length of the
array at each level i as dim[i] and the depth. Since this is pretty much
function I plan to wrap, I'd like to avoid using boost, swig, etc.
Any help would be appreciated, looks like I should use PyArray_AsCArray but
I'm having trouble finding examples that work for me.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion