Ian Bell | 3 May 03:09 2012
Picon

[Cython] PXD file for overriding math functions

Ok, I think I am missing something - I am a bit lost in the Cython jargon.  Here is where I stand, let me know where I am going wrong...   I compiled with cython.py -a test.py, but it isn't working.  If I am completely not on the right track, feel free to let me know :)

Ian

##### test.py (Pure python file) #####
from math import sin

def f(r):
    s=sin(r)
    return s
   
r=3.141592654/3.0
print f(r)

#### test.pxd #####
cimport cython
import cython

cimport math_override

<at> cython.locals(s=cython.

double)
cpdef f(double r)

#### math_override.pxd #####
cdef extern from "math.h":
    double sin_d "sin" (double x)
    float sin_f "sin" (float x)
   
cpdef inline double sin(double x):
    return sin_d(x)
   
cpdef inline float sin(float x):
    return sin_f(x)
<div>
<p>Ok, I think I am missing something - I am a bit lost in the Cython 
jargon.&nbsp; Here is where I stand, let me know where I am going wrong...&nbsp;&nbsp; I
 compiled with cython.py -a test.py, but it isn't working.&nbsp; If I am 
completely not on the right track, feel free to let me know :)<br><br>Ian<br><br>##### test.py (Pure python file) #####<br>from math import sin<br><br>def f(r):<br>&nbsp;&nbsp;&nbsp; s=sin(r)<br>&nbsp;&nbsp;&nbsp; return s<br>&nbsp;&nbsp;&nbsp; <br>r=3.141592654/3.0<br>print f(r)<br><br>#### test.pxd #####<br>cimport cython<br>import cython<br><br>cimport math_override<br><br> <at> cython.locals(s=cython.</p>
<div>double)<br>cpdef f(double r)<br><br>#### math_override.pxd #####<br>cdef extern from "math.h":<br>&nbsp;&nbsp;&nbsp; double sin_d "sin" (double x)<br>

&nbsp;&nbsp;&nbsp; float sin_f "sin" (float x)<br>
&nbsp;&nbsp;&nbsp; <br>cpdef inline double sin(double x):<br>&nbsp;&nbsp;&nbsp; return sin_d(x)<br>&nbsp;&nbsp;&nbsp; <br>cpdef inline float sin(float x):<br>&nbsp;&nbsp;&nbsp; return sin_f(x)</div>
</div>

Gmane