Created
June 16, 2014 12:18
-
-
Save bjodah/3cc42d9c5f70a321af29 to your computer and use it in GitHub Desktop.
Non-type template arguments C++/Cython
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
# -*- coding: utf-8 -*- | |
# distutils: language = c++ | |
from func cimport func as _func | |
def func(double inp): | |
cdef double out | |
_func[double, 3](&inp, &out); | |
return out; |
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
namespace myfunc { | |
template<typename T, int n> | |
void func(const T * const in, T * const out){ | |
*out = n*(*in); | |
} | |
} |
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
cdef extern from "func.h" namespace "myfunc": | |
cdef void func[T, int n](const T * const, T * const) |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from _func import func | |
if __name__ == '__main__': | |
print(func(3)) |
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 | |
ext_mod = cythonize("_func.pyx") | |
setup( | |
ext_modules = ext_mod | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment