Dag Sverre Seljebotn wrote: > Jason Grout wrote: >> In http://docs.cython.org/docs/numpy_tutorial.html, it says this about >> the future plans for the cython/numpy interface: "Support for efficient >> access to structs/records stored in arrays; currently only primitive >> types are allowed." >> >> I have an array of C structs that I'd like to access using the cython >> numpy indexing syntax (basically, treat each item as a binary blob with >> size sizeof(my_struct)). Does the above statement mean that I can't use >> the nice Cython numpy syntax? It appears that way to me, but I thought >> I'd just double-check in case I was misunderstanding something. > > Better support was added in 0.11.2 -- if it is OK to say it is present > when it is not documented anywhere .. :-(
Actually, there are some docs I forgot about: Slide 27 (pdf page 56) of this: http://sage.math.washington.edu/home/dagss/cython-notur09/notur2009.pdf (with the example at http://sage.math.washington.edu/home/dagss/cython-notur09 -- somebody complained that it was buggy but I didn't follow it up). > > Remember though that NumPy packs records by default -- so either pass > "align=True" when constructing the record dtype, or use packed (and in > some circumstances inefficient!) structs: > > cdef packed struct MyStruct: > int a > double b > ... > > This might not apply to Sage though unless Sage recently upgraded > Cython. But I think the Sage Cython has been recent enough for some time > that you can do > > cdef np.ndarray[MyStruct, cast=True] arr = somenparray > > to disregard all checks except the size of each element. > > (BTW, the odds of me discovering this had been higher had this been on > the Cython list. I'm not sure how closely Robert Bradshaw follows this > part of Cython. A cython-users is hopefully coming up so that cython-dev > subscription isn't necesarry...) > -- Dag Sverre --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---