On Jan 2, 2009, at 1:02 PM, Magnus Lie Hetland wrote:

> Hi!
>
> I'm writing a method of an extension class that will take an array as
> an argument (or, rather, a pointer and a size, for example). Now, I
> don't, strictly speaking, need to access this method from Python
> (i.e., it can be internal to the Cython code), but I'm writing my unit
> tests in Python, so it'd be nice... On the other hand, I'm thinking I
> wouldn't want to use list or the like as the type (in a cpdef) just to
> accomplish this, as that would, most likely, slow things down in
> actual Cython-to-Cython (or C-to-C) calls.

Using a list to wrap a list of doubles will *vastly* slow things  
down, probably by a factor of 100 or more.

> Is there a standard way of doing this sort of thing? My thinking is
> that I can write a simple wrapper for the Python use, which does the
> proper conversion, but I don't know if that's ideal... (It doesn't
> *have* to be an array. I just need to pass in a variable number of
> doubles in an efficient manner.)

The standard way to do things now is to write a cdef function that  
takes a double* and length argument, then write a python wrapper for  
testing. You could also look at using NumPy arrays with the buffer  
interface, depending on what you're doing.

- Robert


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

Reply via email to