On Tue, Nov 25, 2008 at 12:06:06PM -0800, Robert Bradshaw wrote: > One way to do it would be to flatten/compact the ndarray early on (so > one know the entries are contiguous) and then pass the raw float* and > its length (keeping the original array around so you don't have to > worry about memory issues. > Yeah I do this with my own code at times, but I am generally dealing with a matlab audience, and this seems like dark magic. I don't need maximum speed, just as fast as is still understandable to basic programmers.
> Note that __call__, though not as slow as a normal python function > call, still has Python semantics (i.e. all of its arguments and its > return value have to pass through Python objects) so just using a > cdef method could speed things up considerably. (I wonder how hard it > would be to support cpdef __call__?) The call to empty is probably > dominating things too--since the 3 seems hard coded in anyways, I > would accept (and return) a > How hard do you think it would be to write something that sets up an empty (or zeroed) ndarray do avoid the python call? Upon further thinking I imagine this is the major issue from f2py. If it is doable for mortals I would try my hand at it. I imagine it is just getting the .data and some metadata of the struct setup correctly, but I don't fully understand the magic of the ndarray in cython. If this is possible would it make sense to add it to the numpy.pyx file? > cdef struct data: > float x > float y > float z > > instead of a 3-element ndarray. > I don't have control of the calling program routine, so this won't work . . . Again, thanks for all the responses, I continue to think Cython is pythons greatest `killer` feature for science. Gabriel _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
