<font face="Courier, Monospaced" style="color: rgb(34, 34, 34); background-color: rgb(255, 255, 255); font-family: fixed-width, monospace; font-size: 12px; ">I am trying to pass a multi-dimensional ndarray to C as a multi- <br>
dimensional C array for the purposes of passing it to mathematica. <br>They already have a wrapper for a 1-D Python list. where the list is <br>copied to "list". Shown below: <br><p>static PyObject * mathlink_PutIntegerList(mathlink_Link *self, <br>
PyObject *args) <br>{ <br> PyObject* seq; <br> PyObject* obj; <br> long i, len, result; <br> int* list; <br></p><p> len = PyObject_Length(seq); <br></p>
<p> list = PyMem_New(int, len); <br> for(i = 0; i < len; i++) <br> { <br> obj = PySequence_GetItem(seq, i); <br> list[i] = PyInt_AsLong(obj); <br> } <br></p><p>
CheckForThreadsAndRunLink(self,result = MLPutIntegerList(self->lp, <br>list, len)); <br></p><p> PyMem_Free(list); <br> CHECKNOTEQUAL(result,MLSUCCESS,self); <br></p><p> Py_INCREF(Py_None); <br>
return Py_None; <br></p><p></p><div>} <br><br></div>I would like to create a similar wrapper which accepts an ndarray and <br>provides the array laid out in memory like a C array declared <br>explicitly as "int a[m][n]...". I also need to pass the length of the <br>
array at each level i as dim[i] and the depth. Since this is pretty much the only <br>function I plan to wrap, I'd like to avoid using boost, swig, etc. <br></font><p style="color: rgb(34, 34, 34); font-family: arial, sans-serif; background-color: rgb(255, 255, 255); font-size: 12px; ">
<font face="Courier, Monospaced" style="font-family: fixed-width, monospace; ">Any help would be appreciated, looks like I should use </font><span style="font-family: fixed-width, monospace; ">PyArray_AsCArray but I'm having trouble finding examples that work for me</span><span style="font-family: fixed-width, monospace; ">.</span><span style="font-family: fixed-width, monospace; "> </span></p>