Skip to content

Instantly share code, notes, and snippets.

@bjodah bjodah/_func.pyx
Created Jun 16, 2014

Embed
What would you like to do?
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
You can’t perform that action at this time.