[Numpy-discussion] numpy arrays, data allocation and SIMD alignement
peridot.faceted at gmail.com
Wed Aug 8 11:29:55 EDT 2007
On 08/08/2007, Stefan van der Walt <stefan at sun.ac.za> wrote:
> On Tue, Aug 07, 2007 at 01:33:24AM -0400, Anne Archibald wrote:
> > Well, it can be done in Python: just allocate a too-big ndarray and
> > take a slice that's the right shape and has the right alignment. But
> > this sucks.
> Could you explain to me why is this such a bad idea?
Oh. Well, it's not *terrible*; it gets you an aligned array. But you
have to allocate the original array as a 1D byte array (to allow for
arbitrary realignments) and then align it, reshape it, and reinterpret
it as a new type. Plus you're allocating an extra ndarray structure,
which will live as long as the new array does; this not only wastes
even more memory than the portable alignment solutions, it clogs up
python's garbage collector.
It's not outrageous, if you need aligned arrays *now*, on a released
version of numpy, but numpy itself should do better.
More information about the NumPy-Discussion