Cython: '+' 的操作数类型无效(btVector3;btVector3)

标签 cython

子弹.pxd:

cdef extern from "bullet/LinearMath/btVector3.h":
    cdef cppclass btVector3:
        btVector3(float, float, float) except +
        btVector3 operator+(const btVector3&, const btVector3&)

btmath.pyx:

cimport bullet as bt

cdef class Vector:

    cdef bt.btVector3* _this

    def __cinit__(self, float x=0, float y=0, float z=0):

        self._this = new bt.btVector3(x, y, z)


    def __add__(Vector self, Vector other):

        vec = Vector()
        del vec._this
        vec._this[0] = self._this[0] + other._this[0]

        return vec

btVector3.h中operator+的原型(prototype):

SIMD_FORCE_INLINE btVector3 
operator+(const btVector3& v1, const btVector3& v2);

如标题所述,我得到“'+'无效的操作数类型(btVector3;btVector3)”。我猜这可能与 Cython 如何处理引用传递有关?

任何帮助将不胜感激。

最佳答案

事实证明,在这种情况下,Cython 将“this”参数视为隐式参数,因此bullet.pxd 应如下所示:

cdef extern from "bullet/LinearMath/btVector3.h":
    cdef cppclass btVector3:
        btVector3(float, float, float) except +
        btVector3 operator+(btVector3)

非常感谢 Robert Bradshaw 帮助我解决了这个问题:https://groups.google.com/forum/#!topic/cython-users/8LtEE_Nvf0o

关于Cython: '+' 的操作数类型无效(btVector3;btVector3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16383792/

相关文章:

python - 为 Python 2.7.12 安装 numpy、cython、cpython

python - Cython 扩展类型属性误解

python - Cython在所有Python脚本上引发相同的运行时错误

python - 返回多个值的 cdef 函数的 Cython 异常传播

numpy - 将 Numpy 数组复制到内存 View

python - 使用从 Cython 中的方法创建的 PyCapsule 结果错误

python - 如何在 CI 上测试 Python 轮子

Cython 中的 C++ 结构继承

python - 在 Cython 中将复杂的 numpy 数组传递给 C++

python - 将 C/C++ 库与 Python 连接