[Numpy-discussion] ndarray allocation question
Travis Oliphant
oliphant.travis at ieee.org
Tue Apr 10 02:38:07 EDT 2007
David Doukhan wrote:
> Hi!
> I'm writing you this mail because I would like to do "advanced" use of
> ndarray memory allocation.
>
> So here is a short description of my problem:
>
> I'm interfacing multidimensionnal Numpy array to C using the ctypes
> module. For now, there is no problem.
> The C program that will use the pointer to the data of the array runs
> on a CellBE architecture.
> The consequences are:
> * the adress of the beginning of the data of the array must be a
> multiple a 16 bytes (that could be specified using the attribute
> 'align' of dtype)
> * the memory allocated MUST be a multiple of 16 bytes, and that's my
> current problem, because I didn't find a way to specify it using dtypes...
You can't specify the alignment for a data-type unless you write your
own data-type (the alignment is a property of the data-type and is
determined at compile time for built-in data-types). I don't think you
can set the alignment for a derived data-type at this point.
> So, do the think there is a "clean" way to do what I want. For
> example, asking for an array of 2 lines and 7 columns of float32, so
> that the adress of the biginning of the data would be a multiple of 16
> bytes (that's already possible)
How are you doing that?
> AND beeing sure that the allocated memory for the data would be at
> least 16 * sizeof(float32), instead of 14*sizeof(float32).
You will have to make sure that the array is large-enough yourself by
over requesting the size.
-Travis
More information about the NumPy-Discussion
mailing list