我知道已经回答了this个问题,但似乎无法解决。
我目前正在尝试使用对[double,pair [int,int]]的PriorityQueue,并使用对的double(pair.first)对其进行排序。如果这有帮助,则方法就是这样:pathfind(pair [int,int] start,pair [int,int]目标,np.ndarray网格),第一个参数和第二个参数是在常规python方法中从元组传递的,并且网格只是2D阵列。那么...在Cython中创建对[double,pair [int,int]]的PriorityQueue并使其进行比较的最佳方法是什么?
它输出的错误是这样的:错误C2955:'cpp_pq':使用别名模板需要模板参数列表
cpp_priority_queue.hpp代码是这个:
#include <functional> #include <queue> template <class T> //Had to use this since pair wasn't getting imported correctly with <utilities> using cpp_pq = std::priority_queue<T,std::vector<T>,std::function<bool(T,T)>>;
。pyx代码的一部分是这个:
cdef extern from "cpp_priority_queue.hpp":
cdef cppclass cpp_pq:
cpp_pq(...) except +
void push(pair[double,pair[int,int]])
pair[double,pair[int,int]] top()
void pop()
bool empty()
cdef bool compare_element(pair[double,pair[int,int]] a, pair[double,pair[int,int]] b):
return a.first < b.first
cpdef int pathfind(pair[int,int] start, pair[int,int] goal, np.ndarray grid): # it supposed to output a
# list of tupples, but its
# an int for now until this
# works
cdef cpp_pq queue = cpp_pq(compare_element)
cdef pair[double,pair[int,int]] p = (05.7,start) # some random stuff here for testing....
queue.push(p)
##nothing here till this works...
return 0
我知道已经回答了这个问题,但是我似乎无法解决。我目前正在尝试使用pair [double,pair [int,int]]对的PriorityQueue并使用对的对(pair.first)...
我终于解决了这个问题,我重新启动了该项目,而不是复制.hpp文件,而是重写了它,它的工作原理很吸引人。出于某种原因,该实用程序库最初显示错误(带红色下划线的字),因此我一直在重写代码,直到自己设法将其破坏并添加了不必要的模板。直到我放弃并重新启动一切正常。