> Really nice! Excuse my ignorance about ufuncs, but is there a function > pointer call overhead for every element this way, or is it all macro based
Unfortunately, there is a function call for every single element because I used the PyUFunc_*_* family of wrappers. For something like lgamma(), this is perfectly acceptable since you would have to call the function once per element anyway. But for your own functions, it would be nice to eliminate this overhead. One way around this would be for me to re-implement the PyUFunc_*_* as static functions, then have the user declare the element-wise function as inline so that the compiler does the inlining for us. Another way around the overhead would be to build the ufunc wrapping into Cython, perhaps as a decorator or something. This would make the user's job really simple, but I'm not sure if it's worth the effort. There is also the overhead of using the ufunc machinery, but I think it's probably safe to say this overhead is minimal since all the NumPy operators and functions are implemented as ufuncs. > I wouldn't like to ship it as "pxi" (because include is kind of > discouraged these days and it is not good if the Cython standard lib > requires it). I think all the functions can be put in a pxd if you mark > them "inline". (An alternative is to create a numpy_cython_ufuncs module > in Cython/Runtime, but not unless we have to). How can I implement this as a pxd? I used pxi for two reasons: (1) import_ufunc() needs to be called before anything is used, so by including the pxi I can force this to be done automatically, and (2) the ufunc API functions expect arrays that will stay in existence forever. I used globals since this is the easiest route, but you can't define globals in a pxd. I guess I can malloc and just create a memory leak, but this seems sloppy. Another way to implement all this would be to do it as C macros in a header file. The downside to this approach is that the user would have to add another -I to their CFLAGS. Is there any way to include pure C code (well, really CPP macros) into the pxd? Perhaps a better solution would be to offer these macros as a patch to NumPy, rather than Cython? > It would be best if you would play around in Cython/Includes and submit > a patch. I plan to :) ~Mark _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
