[Pyrex] Math functions like exp, sin, cos, atan, etc.

Greg Ewing greg.ewing at canterbury.ac.nz
Sat May 19 01:03:10 UTC 2007


stephen at theboulets.net wrote:
> Can someone tell me what the best way to use the functions in the math
> module in pyrex are? Say I'm going to use the "exp" function a million
> times in a loop, is "from math import exp" the best choice?

The fastest way is to use C floats and call the C math
library routines, as long as you can arrange things so
that you're not converting back and forth between C
and Python floats all the time.

The next fastest is

   cdef object exp
   from math import exp

since that will bind a C global to the Python exp function
and avoid a dictionary lookup when calling it.

--
Greg



More information about the Pyrex mailing list