2 Mar 2010 05:47
Re: cdef struct for nested ndarray
Felix Schlesinger <schlesin <at> cshl.edu>
2010-03-02 04:47:43 GMT
2010-03-02 04:47:43 GMT
On Mar 1, 5:15 pm, Robert Bradshaw <rober... <at> math.washington.edu>
wrote:
> On Mar 1, 2010, at 12:43 PM, Felix Schlesinger wrote:
> > I am working with large numpy ndarrays in cython. These are 'record
> > arrays' like
> > np.array([], dtype= [('foo', 'i1'),('bar','S1'),('foobars',('i2',5)),
> > ('barfoos',('i2',5)) ])
>
> > What is the right way to declare this type as a struct in cython for
> > static typing and speed-up?
>
> > cdef packed struct arr:
> > np.int8_t foo
> > np.character_t bar
> > np.ndarray[int16_t] foobars
> > np.ndarray[int16_t] barfoos
> This also won't work because you're trying to use a struct--there's
> not really a good way to do refcounting of struct members so not even
> objects are allowed. Use a cdef class instead.
But the cdef class could not be used as an array type, right?
When I try I get
cdef class foobar:
cdef np.ndarray i
cdef np.ndarray j
def foo(np.ndarray[foobar]):
(Continue reading)
RSS Feed