【发布时间】:2015-04-22 16:04:47
【问题描述】:
我正在尝试将用 c++ 编写的并行排序包装为模板,以将其与任何数字类型的 numpy 数组一起使用。我正在尝试使用 Cython 来做到这一点。
我的问题是我不知道如何将指向 numpy 数组数据(类型正确)的指针传递给 c++ 模板。我相信我应该为此使用融合 dtypes,但我不太明白如何。
.pyx 文件中的代码如下
# importing c++ template
cdef extern from "test.cpp":
void inPlaceParallelSort[T](T* arrayPointer,int arrayLength)
def sortNumpyArray(np.ndarray a):
# This obviously will not work, but I don't know how to make it work.
inPlaceParallelSort(a.data, len(a))
过去,我在所有可能的 dtype 上使用丑陋的 for 循环完成了类似的任务,但我相信应该有更好的方法来做到这一点。
【问题讨论】:
标签: python c++ arrays numpy cython