Brent Pedersen wrote: > On Thu, May 14, 2009 at 9:05 AM, Robert<[email protected]> wrote: >> Dag Sverre Seljebotn wrote: >>> Robert wrote: >>>> How to deal with Python's array.array directly - as with numpy.pxd >>>> is there a array.pxd ? >>> Which Python version? >> mainly 2.6; and 2.3 >> >>> Under Python 3 this should probably happen automatically, try: >>> >>> cdef object[int, ndim=1, mode="c"] arr = yourarray >>> >>> Not sure about Python 2.6+ >> 2.6.2 didn't: >> File "calc_c.pyx", line 32, in calc_c.test1 (calc_c.c:808) >> cdef object[float, ndim=1, mode="c"] b = pyarray >> TypeError: 'array.array' does not have the buffer interface >> >> in Python "buffer(myarray)" also behaves strange >> >>> For Python 2.5- an array.pxd must be written. It is not difficult, one >>> simply follows the pattern in numpy.pxd (by implementing __getbuffer__ >>> and filling in the Py_buffer struct). >>> >>> If somebody ends up doing this, please submit it for inclusion in >>> Python. >> I've put a array.pxd here: >> http://trac.cython.org/cython_trac/ticket/314 > > hi, what's the status on this? it seemed very useful. > if it needs tests, i could try to write some given some info on where > to start, what to > cover or maybe some cython-numpy tests to from which to crib? > thanks, > -brent
Great! The main issue with the patch as I see it is that it tries to hack on multi-dimensionality. That is very easily done simply by writing a subclass of array instead, and so doesn't belong in the pxd like this. If you could just remove the multi-dimensional stuff from it I'd be happy to accept it. Accompanying tests are strongly preferred though. There's a section on writing tests here: http://wiki.cython.org/HackerGuide I don't expect the numpy tests to be too useful (though they are in tests/run), just make sure the basics work with a couple of different datatypes. I'll be happy to suggest improvements if you make a first iteration anyway. -- Dag Sverre _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
