Cython:将complex [double]添加为double时出错 [英] Cython: error adding complex[double] to double
问题描述
根据libcpp/complex.pxd
支持将T
添加到complex[T]
:
complex[T] operator+(complex[T]&, T&)
complex[T] operator+(T&, complex[T]&)
但这不起作用:
a.pyx:
# distutils: language = c++
cimport libcpp.complex
def f():
libcpp.complex.complex[double](1,2) + libcpp.complex.complex[double](2,3) # ok
libcpp.complex.complex[double](1,2) + 5. # Cannot assign type 'double' to 'complex[double]'
5. + libcpp.complex.complex[double](1,2) # Invalid operand types for '+' (double; complex[double])
setup.pyx:
setup.pyx:
from distutils.core import setup
from Cython.Build import cythonize
setup(
name = "demo",
ext_modules = cythonize('a.pyx'),
)
不知道如何解决?
移动声明
complex[T] operator+(complex[T]&, T&)
并将其更改为 out of 看起来更合法,但仍然行不通. looks more legimate but still does not work. 我已经开始使用它了.请参阅cython票证 https://github.com/cython/cython/issues/1643 I've got it working. See cython ticket https://github.com/cython/cython/issues/1643 它是以下各项的组合
超出cppclass定义,将其更改为 out of cppclass definition, changing it to 在问题和@DavidW的 as suggested in the question and @DavidW's idea of 这篇关于Cython:将complex [double]添加为double时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!cppclass
and changing it tocomplex[T] operator+[T](complex[T]&, T&)
推荐答案
complex[T] operator+(complex[T]&, T&)
complex[T] operator+[T](complex[T]&, T&)
cimport *
cimport *