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 .. :-(

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to