我正在尝试通过实现从 C++ 到 Python 的线性插值器来学习 cython。我正在尝试将 PXD 头文件用于最终的 Intepolator 对象,以便可以在其他方法/类中重用它,因此我希望 PXD 头文件可用。
我有一个 cpp_线性_插值.cpp 和 cpp_线性_插值.h 工作正常,插值器使用两个双精度向量(x 和 y)作为输入进行实例化。
有我的文件
cy_线性_插值.pxd
# distutils: language = c++
import cython
import numpy as np
cimport numpy as np
from libcpp.vector cimport vector
cdef extern from "cpp_linear_interpolation.h":
cdef cppclass cppLinearInterpolation:
cppLinearInterpolation(vector[double], vector[double]) except +
vector[double] interp(vector[double]) except +
vector[double] m_x
vector[double] m_y
int m_len
double m_x_min
double m_x_max
Run Code Online (Sandbox Code Playgroud)
py_线性插值.pxd
from cy_linear_interpolation cimport cppLinearInterpolation
cdef class LinearInterpolation:
cdef cppLinearInterpolation * thisptr
Run Code Online (Sandbox Code Playgroud)
py_线性插值.pyx
import cython …
Run Code Online (Sandbox Code Playgroud)