Magnus Lie Hetland | 3 Jan 17:40

Re: [Cython] Array parameter...

On Jan 3, 2009, at 16:57 , Dag Sverre Seljebotn wrote:

> Another thing you could do is create your own mini-array Cython  
> class. E.g.: A class "DoubleArray" has C fields "ptr" and "len", and  
> a subclass "PyDoubleArray" allows initializing those using a Python  
> list (and managing the memory needed to hold the converted result  
> etc.). That's about 20 lines, nothing fancy...
>
> So from the unit tests you'd pass inn "PyDoubleArray" and from  
> Cython code raw "DoubleArray".

Cool idea. I thought about using some form of struct, but I didn't  
think quite hard enough, I guess (i.e., the subclassing bit :)

> Your methods could then be "cpdef" and use the same interface.

Indeed. If it turns out that this double array is the main cause of  
"wrapping", that would save me quite a bit of cookie-cutter conversion  
code (as it might apply to several methods).

> Doesn't quite work out if you want to create C-callable code though.

Right. Not an issue for now; I guess I'll just deal with that if it  
crops up.

Thanks,

- M

--

-- 
(Continue reading)

Picon
Picon

Re: [Cython] Array parameter...

Another thing you could do is create your own mini-array Cython class. E.g.: A class "DoubleArray" has C
fields "ptr" and "len", and a subclass "PyDoubleArray" allows initializing those using a Python list
(and managing the memory needed to hold the converted result etc.). That's about 20 lines, nothing fancy...

So from the unit tests you'd pass inn "PyDoubleArray" and from Cython code raw "DoubleArray".

Your methods could then be "cpdef" and use the same interface.

Doesn't quite work out if you want to create C-callable code though.

Dag Sverre Seljebotn
-----Original Message-----
From: Magnus Lie Hetland <magnus@...>
Date: Friday, Jan 2, 2009 10:31 pm
Subject: Re: [Cython] Array parameter...
To: cython-dev@...: cython-dev@...

On Jan 2, 2009, at 22:11 , Robert Bradshaw wrote:
>
>> 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.
>
>Yeah, that's what I had planned. Sounds like a good solution, I guess.  
>(Now I just need a naming convention to separate the two ;-)
>
>> You could also look at using NumPy arrays with the buffer
> interface, depending on what you're doing.
>
>Indeed. I played with that a bit; it might be the best bet, perhaps  
(Continue reading)


Gmane