[SciPy-User] Speed up sin/sqrt functions with cython
Gregor Thalhammer
gregor.thalhammer at gmail.com
Thu Jan 13 12:33:19 EST 2011
Am 12.1.2011 um 13:05 schrieb <g.plantageneto at runbox.com> <g.plantageneto at runbox.com>:
>
> Hi,
>
> I am using cython to speed up some computations (btw, thanks a lot to the people who gave me suggestions on a previous thread).
> I don't understand how to apply the fast C-coded sin/sqrt functions to a numpy array.
> I can import from math.h like this:
>
> cdef extern from "math.h"
> double sin(double)
>
> but then I can't use this function on a numpy ndarray, obviously.
>
> Any ideas? It sounds silly to me to write a cycle on ndarray elements.
>
> Thanks
For sin/sqrt computations on large arrays, numexpr + VML might give you better results than a cython implementation, and with less effort. numexpr with VML uses Intels VML library which gives much better performance than a C loop, at least for sin, for sqrt the performance is similar. In addition, numexpr-VML makes use of all your CPU cores.
Gregor
More information about the SciPy-User
mailing list