Skip to content

Instantly share code, notes, and snippets.

@lebedov
Created July 29, 2014 23:20
Show Gist options
  • Save lebedov/e51c2db540469065a98e to your computer and use it in GitHub Desktop.
Save lebedov/e51c2db540469065a98e to your computer and use it in GitHub Desktop.
How to use function pointers with fused types in Cython
# Demo of how to use function pointers with fused types in Cython:
cimport cython
ctypedef fused fused_type:
cython.double
cython.longlong
cdef double func0(double x, double y):
return x+y
cdef long long func1(long long x, long long y):
return x+y
ctypedef fused_type (*FUNC)(fused_type x, fused_type y)
def foo(fused_type x, fused_type y):
cdef FUNC f
if fused_type == cython.double:
print 'double'
f = func0
else:
print 'long'
f = func1
return f(x, y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment