Norbert Nemec wrote:
> Hi there,
> 
> currently, the code snippet
> 
> -------------
> import numpy
> cimport numpy
> cdef class myclass:
>     cdef numpy.ndarray[numpy.float_t] data
> -------------
> 
> produces the error
>     "Buffer types only allowed as function local variables"
> 
> Is this a fundamental limitation of Cython or just something that has not yet 
> been implemented?

It has just not been implemented.

> 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

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

-- 
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to