[Numpy-discussion] storage for records

Stefan van der Walt stefan at sun.ac.za
Sun Feb 19 13:37:01 CST 2006


On Sat, Feb 18, 2006 at 06:20:50PM -0700, Travis Oliphant wrote:
> Stefan van der Walt wrote:
> 
> >I am probably trying to do something silly, but still:
> >
> >In [1]: import numpy as N
> >
> >In [2]: N.__version__
> >Out[2]: '0.9.6.2127'
> >
> >In [3]: P = N.array(N.zeros((2,2)), N.dtype((('f4',3), {'names': 
> >['x','y','z'], 'formats': ['f4','f4','f4']})))
> >*** glibc detected *** malloc(): memory corruption: 0x0830bb48 ***
> >Aborted
> >
> >Regards
> >Stéfan
> > 
> >
> This code found a bug that's been there for a while in the 
> PyArray_CastTo code (only seen on multiple copies) which is being done 
> here as the 2x2 array of zeros is being cast to a 2x2x3 array of 
> floating-point zeros.
> 
> The bug should be fixed in SVN, now.

Thank you very much for fixing this! (It works now).

> Despite the use of fields, the base-type is ('f4',3) which is equivalent 
> to (tack on a 3 to the shape of the array of 'f4').  So, on array 
> creation the fields will be lost and you will get a 2x2x3 array of 
> float32.   Types like ('f4', 3) are really only meant to be used in 
> records.  If they are used "by themselves" they simply create an array 
> of larger dimension.  

<snip insightful explanation>

Exactly what I needed for my application!  I'll write this up and put
it on the wiki.

Cheers
Stéfan




More information about the Numpy-discussion mailing list