Hi, I am not sure if my question is appropriate for the cython-dev list. I thought, this might be a pretty common problem and I am curious to hear an opinion of the cython developers.
Thanks, Kilian ---------- Forwarded message ---------- From: killian koepsell <[email protected]> Date: Sat, Oct 30, 2010 at 3:14 PM Subject: pointers to numpy ndarray / conversion of numpy array to some type C++ array To: [email protected] Hi, I would like to access a large number of numpy ndarrays (of different size) from cython inside some inner loop. In python I would keep these arrays inside an object attribute, such as a dictionary or a list of arrays. However, as I understand it, I would always incure a significant overhead if I access a python list from within cython (since the list members are not typed). What is the best way to attach a number of ndarrays to a python object in a way that they are fast accessible inside cython without going through the python layer? I was thinking of keeping a list of pointers in a C++ vector, however I did not manage to obtain a pointer to a buffer of type e.g. np.ndarray[y[np.double_t, dim=2]. If I only keep a pointer to the ndarray.data, I loose the shape and stride information. The workaround I came up with is to create an auxiliary struct or cppclass that contains all the required information to access a numpy array (data pointer, shape, strides) and to keep pointers to these auxiliary object in a C++ vector. This works fast but seems somewhat cumbersome. In particular, I lose all the nice cython buffer indexing features and now have to use pointer arithmetics to access the data. I am wondering if there is a better solution. Maybe, it is possible to obtain a pointer to the buffer objects that cython uses internally? Or alternatively, maybe it is possible to create some type of C++ ndarrays without copying of the data and to store pointers to these C++ arrays inside a C++ vector? Blitz, opencv, and boost come to mind, but I haven't used either from inside cython. What would be the best/easiest way to do that? Thanks for any suggestions. Kilian _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
