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
--
Cython direct interface to Python's array.array type (builtin module).
* 1D contiguous data view
* 2D views - contigious or [x,y] transposed/strided
* tools for fast array creation, maximum C-speed and handiness
* suitable as allround light weight auto-array within Cython
code too
See also: array_example.pyx and doc strings
--
Tests needed. just used it in 2.6 so far.
Robert
PS: For 2.3 a need arose for conditional compilation within the pxd.
http://docs.cython.org/docs/language_basics.html#conditional-compilation
doesn't seem to allow comparison against the python version so far? )
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev