【发布时间】:2018-12-02 17:45:26
【问题描述】:
我正在尝试在 cython 中包装以下用 C++ 编写的声明:
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&) 但这显然会导致语法错误。
【问题讨论】: