[Numpy-discussion] More on array protocol

Todd Miller jmiller at stsci.edu
Thu Nov 3 13:26:35 EST 2005


Francesc Altet wrote:

>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:
>  
>
I can reproduce garbage here using 1.4.1 but not with CVS.  

>>>>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.
>  
>
I pretty sure this problem has been solved...  let me know if you're 
still experiencing problems here.

Todd





More information about the NumPy-Discussion mailing list