On Tue, May 18, 2010 at 11:33 PM, Dag Sverre Seljebotn <
[email protected]> wrote:

> You basically have to stoop down to using C pointers:
>
>
> cpdef evaluate(FTYPE_t *x, FTYPE_t *p, FTYPE_t* out, Py_ssize_t len):
>    # Access x[i], p[i]
>
>
> Then call like this:
>
> func.evaluate(<FTYPE_t*>x.data, <FTYPE_t*>p.data, ...)
>
> Note that this relies on mode='c' bit for correctness!
>
>
>
Looks great!  Is it correct that you meant "cdef" rather than "cpdef"?  My
cython complains about not being able to convert "FTYPE_t *" to a "Python
object" otherwise.   So I had to do:

cdef _evaluate(self, FTYPE_t *x, FTYPE_t *p, FTYPE_t *out, Py_ssize_t len):
   # ...
def evaluate(self, np.ndarray[FTYPE_t, ndim=1, mode="c"] x,
            np.ndarray[FTYPE_t, ndim=1, mode="c"] p,
            np.ndarray[FTYPE_t, ndim=1, mode="c"] out
           Py_ssize_t len):
    self._evaluate(<FTYPE_t*>x.data, <FTYPE_t*>y.datat, <FTYPE_t*> out.data,
len(x))
    return out

Which seems to work, but how can I get this to work for a Python subclass of
this extension?  The subclass would redefine evaluate() but my innerloop
would only be calling _evaluate().  I guess this was the purpose of cpdef.
Is there a way around this?
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to