[Numpy-discussion] numpy arrays, data allocation and SIMD alignement
Charles R Harris
charlesr.harris at gmail.com
Tue Aug 7 16:26:27 EDT 2007
On 8/6/07, Anne Archibald <peridot.faceted at gmail.com> wrote:
> On 06/08/07, David Cournapeau <david at ar.media.kyoto-u.ac.jp> wrote:
> > Well, when I proposed the SIMD extension, I was willing to implement the
> > proposal, and this was for a simple goal: enabling better integration
> > with many numeric libraries which need SIMD alignment.
> > As nice as a custom allocator might be, I will certainly not implement
> > it myself. For SIMD, I think the weight adding complexity / benefit
> > worth it (since there is not much change to the API and implementation),
> > and I know more or less how to do it; for custom allocator, that's an
> > entirely different story. That's really more complex; static pools may
> > be useful in some cases (but that's not obvious, since only the data are
> > allocated with this buffer, everything else being allocated through the
> > python memory allocator, and numpy arrays have pretty simple memory
> > allocation patterns).
> I have to agree. I can hardly volunteer David for anything, and I
> don't have time to implement this myself, but I think a custom
> allocator is a rather special-purpose tool; if one were to implement
> one, I think the way to go would be to implement a subclass of ndarray
> (or just a constructor) that allocated the memory. This could be done
> from python, since you can make an ndarray from scratch using a given
> memory array. Of course, making temporaries be allocated with the
> correct allocator will be very complicated, since it's unclear which
> allocator should be used.
Maybe I'm missing something, but handling the temporaries is automatic. Just
return the appropriate slice from an array created in a subroutine. The
original array gets its reference count decremented when the routine exits
but the slice will still hold one. When the slice is deleted all the
allocated memory will get garbage collected.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion