Re: [Numpy-discussion] How to export a CObject from NumPy to my own module?

Well, I believe I should problably use the PyArray_API instead (http://www.velocityreviews.com/forums/t358140-re-dynamically-loaded-librarie...), since it seems it's implemented in NumPy for this exact reason(?). Can anyone point me in the direction of a good step-step guide og using this api to export function pointers from NumPy to your own modules?
NumPyStudent wrote:
Hi
I haven't worked very much with NumPy and Python and hope some assistance :-)
I need access to a functionpointer in my own Python module. This functionpointer is available in a modified NumPy module. I would like to pass the functionpointer to my module when I import it in the Python runtime. Before importing my module I've already imported the NumPy module, and this is fine by me - I don't necessarily need my own module to handle the import of NumPy...
My question concerns how I should modify NumPy source code to be able to use the method of passing CObjects as described here: http://docs.python.org/release/2.5.2/ext/using-cobjects.html
Can anyone tell me where I should add the C-Object in NumPy? I tried to add it to the "multiarray" module (in the file multiarraymodule.c), but it dosen't look like this module is available for import (as in PyImport_ImportModule("multiarray"); in my own module - the return value of this is null). However, if I try PyImport_ImportModule("numpy"); it seems like I get a module imported, but this module does not have the CObject added. This is not surprising, since I added it to the "multiarray" module.
I believe I can solve my problem by adding the CObject to the "numpy" module instead, but in what file or files should I make modifications to do this?
Alternatively, how can I make the "multiarray" module available for import by my own module?
BR. NumPyStudent

On Wed, Nov 24, 2010 at 11:35, NumPyStudent jens.marquard.ipsen@gmail.com wrote:
Well, I believe I should problably use the PyArray_API instead (http://www.velocityreviews.com/forums/t358140-re-dynamically-loaded-librarie...), since it seems it's implemented in NumPy for this exact reason(?). Can anyone point me in the direction of a good step-step guide og using this api to export function pointers from NumPy to your own modules?
http://docs.scipy.org/doc/numpy/user/c-info.how-to-extend.html?highlight=imp...

Thanks for your answers!

On 11/24/10 9:35 AM, NumPyStudent wrote:
Well, I believe I should problably use the PyArray_API instead (http://www.velocityreviews.com/forums/t358140-re-dynamically-loaded-librarie...), since it seems it's implemented in NumPy for this exact reason(?). Can anyone point me in the direction of a good step-step guide og using this api to export function pointers from NumPy to your own modules?
It's not clear to me what you really are trying accomplish here. A little more detail about your problem may help.
If what you are trying to do is write a C-extension that can take numpy arrays as input, and/or provide them as output, while working natively with the data inside them in C, then yes, working with the numpy C api is the way to go.
However, I suggest you take a look at Cython:
It provides a much easier way to write python extensions, and has build-in understanding of numpy arrays. It can call arbitrary C code so there are no limits to its functionality, but it will save you much pain in reference coutning, converting to/from python objects, etc.
-Chris

Thanks for your answers!
participants (3)
-
Christopher Barker
-
NumPyStudent
-
Robert Kern