Skip to content

Instantly share code, notes, and snippets.

@piskvorky
Created September 24, 2013 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piskvorky/6692036 to your computer and use it in GitHub Desktop.
Save piskvorky/6692036 to your computer and use it in GitHub Desktop.
from cpython cimport PyCObject_AsVoidPtr
from scipy.linalg.blas import fblas
from libc.math cimport fabs
ctypedef float (*sdot_ptr) (const int *N, const float *X, const int *incX, const float *Y, const int *incY) nogil
cdef sdot_ptr sdot=<sdot_ptr>PyCObject_AsVoidPtr(fblas.sdot._cpointer)
ctypedef double (*dsdot_ptr) (const int *N, const float *X, const int *incX, const float *Y, const int *incY) nogil
cdef dsdot_ptr dsdot=<dsdot_ptr>PyCObject_AsVoidPtr(fblas.sdot._cpointer)
cdef int ONE = 1
cdef double test_dsdot(int what) nogil:
cdef float *x = [10.0]
cdef float *y = [0.01]
cdef float expected = 0.1
cdef int size = 1
cdef double d_res
cdef float *p_res
d_res = dsdot(&size, x, &ONE, y, &ONE)
p_res = <float *>&d_res
if (what == 0):
return d_res
if (what == 1):
return p_res[0]
if (what == 2):
return p_res[1]
return sdot(&size, x, &ONE, y, &ONE)
print 'double', test_dsdot(0)
print 'float[0]', test_dsdot(1)
print 'float[1]', test_dsdot(2)
print 'float', test_dsdot(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment