我试图将以下用 C++ 编写的声明包装在 cython 中:
template<typename T, double (*distance)(const DataPoint&, const DataPoint&)>
class VpTree
{...}
我还在 C++ 中得到了以下定义:
inline double euclidean_distance(const DataPoint &t1, const DataPoint &t2) {...}
我正在尝试将其包装在 cython 中。这是我根据文档得出的结论:
cdef extern from "vptree.h":
# declaration of DataPoint omitted here
cdef inline double euclidean_distance(DataPoint&, DataPoint&)
cdef cppclass VpTree[T, F]: # F is almost certainly wrong
...
并围绕此构建一个包装器:
cdef class VPTree:
cdef VpTree[DataPoint, euclidean_distance] tree
def __cinit__(self):
self.tree = VpTree[DataPoint, euclidean_distance]()
不幸的是,这会导致以下错误:
------------------------------------------------------------
cdef class VPTree:
cdef VpTree[DataPoint, euclidean_distance] tree
^
------------------------------------------------------------
unknown type in template argument
------------------------------------------------------------
cdef class VPTree:
cdef VpTree[DataPoint, euclidean_distance] tree
def __cinit__(self):
self.tree = VpTree[DataPoint, euclidean_distance]()
^
------------------------------------------------------------
unknown type in template argument
我怀疑问题出在F
定义的一部分,我尝试了各种方法来代替它,例如double(*)(DataPoint&, DataPoint&)
但这显然会导致语法错误。