[Cython] Automatic conversion with fixed-size C arrays
Robert Bradshaw
robertwb at gmail.com
Wed Jul 16 20:02:13 CEST 2014
On Wed, Jul 16, 2014 at 10:01 AM, Kurt Smith <kwmsmith at gmail.com> 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
More information about the cython-devel
mailing list