[Cython] array.array and PIL directly ?
Brent Pedersen
bpederse at gmail.com
Thu Jun 11 02:00:16 CEST 2009
On Wed, Jun 10, 2009 at 3:23 PM, Brent Pedersen<bpederse at gmail.com> wrote:
> On Wed, Jun 10, 2009 at 12:08 PM, Dag Sverre
> Seljebotn<dagss at student.matnat.uio.no> wrote:
>> Brent Pedersen wrote:
>>> On Thu, May 14, 2009 at 9:05 AM, Robert<kxroberto at googlemail.com> 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.
>>
>
> thanks for the pointers,
> i have a start on this, but what should i do with the arrayarray.h?
> there doesnt seem to be any cases where a header is included with cython itself.
>
> -brent
>
here's a first iteration with tests for some feedback.
i'm still not sure what to do with the .h file. currently
the tests have to be run as:
INCLUDE=/path/to/cython-devel/Cython/Includes/ python runtests.py pyarray
-------------- next part --------------
A non-text attachment was scrubbed...
Name: array.patch
Type: text/x-diff
Size: 14963 bytes
Desc: not available
Url : http://codespeak.net/pipermail/cython-dev/attachments/20090610/31de2748/attachment-0001.bin
More information about the Cython-dev
mailing list