我正试图通过Cython学习如何在C和Python之间使用回调,并且一直在研究this demo。我想要一个Python函数应用于一个std::vector/数字阵列并将结果存储到另一个。我可以编译和运行而不出错,但最终向量y是
没有被改变。在
C++头文件// callback.hpp
#include
typedef double (*Callback)( void *apply, double &x );
void function( Callback callback, void *apply, vector &x,
vector &y );
C++源
^{pr2}$
赛顿报头# cy_callback.pxd
import cython
from libcpp.vector cimport vector
cdef extern from "callback.hpp":
ctypedef double (*Callback)( void *apply, double &x )
void function( Callback callback, void* apply, vector[double] &x,
vector[double] &y )
Cython源# cy_callback.pyx
from cy_callback cimport function
from libcpp.vector cimport vector
def pyfun(f,x,y):
function( cb, f, x, y )
cdef double cb(void* f, double &x