Last active
August 29, 2015 13:57
-
-
Save mattjj/9692956 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "bar.h" | |
void blah(int sz, double *x) { | |
for (int i=0; i<sz; i++) { | |
x[i] = (double) 2*i; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void blah(int sz, double *x); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# distutils: extra_compile_args = -O3 -w | |
# distutils: sources = bar.c | |
# cython: boundscheck = False | |
# cython: initializedcheck=False | |
# cython: nonecheck = False | |
# cython: wraparound = False | |
import numpy as np | |
cimport numpy as np | |
### interfacing external c code | |
# add any c files to the distutils sources directive at the top | |
cdef extern from "bar.h": | |
void blah(int sz, double *x) | |
def blargh(double[:] x): | |
blah(x.shape[0], &x[0]) | |
### writing cython | |
def foo(double[:,::1] x): | |
cdef int i, j | |
cdef double[:,::1] y = np.arange(100.).reshape((10,10)) | |
z = [a**2 for a in range(10)] | |
for i in range(x.shape[0]): | |
for j in range(x.shape[1]): | |
x[i,j] = i*j | |
return np.asarray(x), np.asarray(y), z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from distutils.core import setup | |
from Cython.Build import cythonize | |
import numpy | |
setup( | |
ext_modules=cythonize('**/*.pyx'), | |
include_dirs=[numpy.get_include(),], | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment