[Cython] Automatic conversion with fixed-size C arrays

Kurt Smith kwmsmith at gmail.com
Tue Jul 29 06:29:35 CEST 2014


On Mon, Jul 28, 2014 at 11:02 AM, Robert Bradshaw <robertwb at gmail.com>
wrote:

> On Sun, Jul 27, 2014 at 9:34 PM, Kurt Smith <kwmsmith at gmail.com> wrote:
>
> > I have sorted out all the code
> > generation pieces and nearly have a minimal example working, and will
> have
> > something for you to review soon.  From what I can tell, Cython has some
> > baked-in assumptions when it comes to assignment statements.  Telling
> Cython
> > that in this case, no, don't assign to something at the C level, instead
> > generate a function call and pass in the lvalue by reference takes some
> > doing.
>
> Yeah, I'm not too surprised about that.
>
>
I have an initial version working for assigning a Python object to a
fixed-size array.  It's special cased to C ints and pretty messy in parts,
but it gets the job done.  I have some ideas on how to generalize the
type.  Like I said, I'll need your input on the right way to do some things.

Will clean it up and put up a PR as soon as I can.

Once this is in place, assigning a dict-like object to a struct can build
on it.

There are a number of other little things that would be nice, like allowing
slice assignment:

    c_arr[5:13] = obj

and initializing a dynamic C array with a Python object, provided the
extent is specified:

    cdef int *arr = <int*>malloc(N * sizeof(int))
    arr[:N] = obj
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20140728/8080b98f/attachment.html>


More information about the cython-devel mailing list