[Numpy-discussion] More on array protocol

Francesc Altet faltet at carabos.com
Wed Nov 2 00:37:41 CST 2005


Hi,

I'm having problems in using the array protocol in numarray-->Numeric in
some situations. I'm using the PyBuffer_FromReadWriteMemory C call in
order to create buffers that will be later used to create numarray
objects (both NumArray and CharArray) in Python space. The problem is
that the array protocol implementation is doing badly this conversion.

I was able to create a small example in pure python that reproduces the
problem:

>>> import numarray
>>> from numarray import memory
>>> import Numeric
>>> na=numarray.array([1,2])
>>> Numeric.array(na)
array([1, 2])

but ...

>>> wbuf = memory.writeable_buffer(na)
>>> nawb = numarray.array(wbuf,type="Int32",shape=(2,))
>>> nawb
array([1, 2])
>>> Numeric.array(nawb)
array([        2, 135510112])

I'm afraid that the problem should be related with the kind of buffer
that is attached to the numarray object:

>>> na._data
<memory at 0x082577f8 with size:0x00000008 held by object 0x401f10a0
aliasing object 0x00000000>
>>> nawb._data
<read-write buffer for 0x401f10a0, size -1, offset 0 at 0x40572020>

Travis, Todd, are you going to support read-write buffers or should I
try to move to using the memory module in order to cope with this? For a
series of reasons I'd like to keep using regular read-write buffers, but
anyway... I think I'll be able to do the change if absolutely necessary.

Thanks,

-- 
>0,0<   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data
 "-"






More information about the Numpy-discussion mailing list