Skip to content

Instantly share code, notes, and snippets.

@bjodah
Created June 16, 2014 12:18
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 bjodah/3cc42d9c5f70a321af29 to your computer and use it in GitHub Desktop.
Save bjodah/3cc42d9c5f70a321af29 to your computer and use it in GitHub Desktop.
Non-type template arguments C++/Cython
# -*- 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;
namespace myfunc {
template<typename T, int n>
void func(const T * const in, T * const out){
*out = n*(*in);
}
}
cdef extern from "func.h" namespace "myfunc":
cdef void func[T, int n](const T * const, T * const)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from _func import func
if __name__ == '__main__':
print(func(3))
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