[Cython] buffer types as members of extension types?
Norbert Nemec
Norbert.Nemec.list at gmx.de
Tue Apr 28 18:31:37 CEST 2009
Dag Sverre Seljebotn wrote:
>
>> Is there a workaround that allows me to store and efficiently access buffer data in an extension type?
>>
>
> Is this what you are referring to which is too slow?:
>
> 1) Store it as plain numpy.ndarray
> 2) Copy it to numpy.ndarray[numpy.float_t] inside the local function
> before processing
>
The core routine is called very often, each time, the data is accessed
just once. Doing the conversion once for every call would therefore not
gain me anything... :-(
> If that is too slow as well, I'm afraid the only solution right now is
> to store it as numpy.ndarray and access the data field (i.e.
> self.data.data), casted to numpy.float_t*. You must then make sure you
> work with a contiguous array:
>
> if not data.flags['C_CONTIGUOUS']:
> data = data.copy()
> self.data = data
>
Ok, that's ugly, but it should work. The array is created within the
class, so I have full control. I could then just store an additional
class member of pointer type and use that to access the data.
Thanks for the help!
More information about the Cython-dev
mailing list