how to get data out of an object array in pyrex?
Hi: I've successfully used the examples at http://www.scipy.org/Wiki/Cookbook/Pyrex_and_NumPy to access the data in a 'normal' numpy array, but have had no success adapting these examples to work with object arrays. I understand that the .data attribute holds pointers to the objects which actually contain the data in an object array, but how to you use those pointers to get the data in C/pyrex? -Jeff -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX : (303)497-6449 NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@noaa.gov 325 Broadway Office : Skaggs Research Cntr 1D-124 Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg
Jeff Whitaker wrote:
Hi: I've successfully used the examples at http://www.scipy.org/Wiki/Cookbook/Pyrex_and_NumPy to access the data in a 'normal' numpy array, but have had no success adapting these examples to work with object arrays. I understand that the .data attribute holds pointers to the objects which actually contain the data in an object array, but how to you use those pointers to get the data in C/pyrex?
You have a pointer to a PyObject *object in the data. Thus, data should be recast to PyObject **. I don't know how to do that in PyRex. But, it's easy in C. In C, you will need to be concerned about reference counts. I don't know how pyrex handles this.
Travis Oliphant wrote:
Jeff Whitaker wrote:
Hi: I've successfully used the examples at http://www.scipy.org/Wiki/Cookbook/Pyrex_and_NumPy to access the data in a 'normal' numpy array, but have had no success adapting these examples to work with object arrays. I understand that the .data attribute holds pointers to the objects which actually contain the data in an object array, but how to you use those pointers to get the data in C/pyrex?
You have a pointer to a PyObject *object in the data. Thus, data should be recast to PyObject **. I don't know how to do that in PyRex. Travis:
Apparently not. If I try to do this pyrex says 115:25: Pointer base type cannot be a Python object
But, it's easy in C. In C, you will need to be concerned about reference counts. OK, I was hoping to avoid hand-coding an extension in C (which I'm woefully unqualified to do).
-Jeff -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX : (303)497-6449 NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@noaa.gov 325 Broadway Office : Skaggs Research Cntr 1D-124 Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg
Hi Jeff, I've significantly updated the page at http://scipy.org/Wiki/Cookbook/Pyrex_and_NumPy Pyrex should be able to do everything you need. I hope you find the revised page more useful. Please let me know (or fix the page) if you have any issues or questions. Cheers! Andrew
Andrew Straw wrote:
Hi Jeff,
I've significantly updated the page at http://scipy.org/Wiki/Cookbook/Pyrex_and_NumPy
Pyrex should be able to do everything you need.
I hope you find the revised page more useful. Please let me know (or fix the page) if you have any issues or questions.
Cheers! Andrew
Andrew: Thanks! That looks like exactly what I need. -Jeff -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX : (303)497-6449 NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@noaa.gov 325 Broadway Office : Skaggs Research Cntr 1D-124 Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg
On Mon, 6 Feb 2006, Jeff Whitaker wrote:
Andrew Straw wrote:
Hi Jeff,
I've significantly updated the page at http://scipy.org/Wiki/Cookbook/Pyrex_and_NumPy
Pyrex should be able to do everything you need.
I hope you find the revised page more useful. Please let me know (or fix the page) if you have any issues or questions.
Cheers! Andrew
Andrew: Thanks! That looks like exactly what I need. -Jeff
Very nice! Would it be better the policy that any runnable .py file is an attachment (see tst.py in http://scipy.org/Wiki/WikiSandBox) to the page, so that it can be easily downloaded? Presently one has to disable line numbers, copy the text, paste into an editor and save with the right file name... Best, Arnd
On Mon, 6 Feb 2006, Andrew Straw wrote:
I've significantly updated the page at http://scipy.org/Wiki/Cookbook/Pyrex_and_NumPy
FYI, numpy.distutils now supports building pyrex extension modules. See numpy/distutils/tests/pyrex_ext/ for a working example. In case of Cookbook/Pyrex_and_NumPy, the corresponding setup.py file is: #!/usr/bin/env python def configuration(parent_package='',top_path=None): from numpy.distutils.misc_util import Configuration config = Configuration('mypackage',parent_package,top_path) config.add_extension('pyrex_and_numpy', sources = ['test.pyx'], depends = ['c_python.pxd','c_numpy.pxd']) return config if __name__ == "__main__": from numpy.distutils.core import setup setup(**configuration(top_path='').todict()) And to build the package inplace, use python setup.py build_src build_ext --inplace Pearu
participants (5)
-
Andrew Straw
-
Arnd Baecker
-
Jeff Whitaker
-
Pearu Peterson
-
Travis Oliphant