[Cython] Automatic conversion with fixed-size C arrays

2014-07-16 Thread Kurt Smith
Hi devs,

Being able to convert between simple C structs and Python dictionaries is
great, but it doesn't work if there is a fixed-size array field in the
struct.  It seems like the following struct should be convertible safely:

cdef struct state_t:
int i, j, k
float x[3]
float v[3]

Along with that, I'd expect that converting between fixed-sized C arrays
and Python iterables should work as well:

def auto_convert(list ll):
cdef int arr[10] = ll
# ...
return arr

If this is deemed something worth doing and if someone is willing to give
pointers when I get stuck, I'm offering to put in the development time to
implement this.

Thoughts?

Kurt
___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Automatic conversion with fixed-size C arrays

2014-07-16 Thread Robert Bradshaw
On Wed, Jul 16, 2014 at 10:01 AM, Kurt Smith  wrote:
> Hi devs,
>
> Being able to convert between simple C structs and Python dictionaries is
> great, but it doesn't work if there is a fixed-size array field in the
> struct.  It seems like the following struct should be convertible safely:
>
> cdef struct state_t:
> int i, j, k
> float x[3]
> float v[3]
>
> Along with that, I'd expect that converting between fixed-sized C arrays and
> Python iterables should work as well:
>
> def auto_convert(list ll):
> cdef int arr[10] = ll
> # ...
> return arr
>
> If this is deemed something worth doing and if someone is willing to give
> pointers when I get stuck, I'm offering to put in the development time to
> implement this.
>
> Thoughts?

Yes, this'd be nice to have. One difficulty with arrays is that they
can't be returned by value, and so the ordinary from_py_function
mechanism (which gets called recursively) would need to be adapted.
(Allowing to_py_function to be optinally be called by reference
instead of by value could be nice as well from a performance
standpoint.)

- Robert
___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel