vendredi 13 mars 2015

How to take advantage of C++ templates in Cython


I have a C++ library that is templatized -- for example a function can be passed as parameter a pointer of floats or integers. I am calling this using a Cython code where the pointers have been declared using memory view:


numpy.ndarray[float, ndim=3, mode="c"] A


numpy.ndarray[int, ndim=3, mode="c"] B


I am currently writing two functions in my .pyx file to take care of the two types. I looked up single dispatch generic functions and Fused Types but I could not get them to work on numpy.ndarray. Specifically I got invalid syntax error. Is there a way to do "templates" in cython? Thanks! Also as an extension (?) if the ndarray was 2dim instead of 3 dim could the same function take care of it?




Aucun commentaire:

Enregistrer un commentaire