Reputation: 34014
According to libcpp/complex.pxd
adding T
to complex[T]
is supported:
complex[T] operator+(complex[T]&, T&)
complex[T] operator+(T&, complex[T]&)
But it doesn't work:
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:
from distutils.core import setup
from Cython.Build import cythonize
setup(
name = "demo",
ext_modules = cythonize('a.pyx'),
)
Àny idea how to fix it?
Moving declaration
complex[T] operator+(complex[T]&, T&)
out of cppclass
and changing it to
complex[T] operator+[T](complex[T]&, T&)
looks more legimate but still does not work.
Upvotes: 0
Views: 622
Reputation: 1697
I've got it working. See cython ticket https://github.com/cython/cython/issues/1643
It is a combination of moving
complex[T] operator+(complex[T]&, T&)
out of cppclass definition, changing it to
complex[T] operator+[T](complex[T]&, T&)
as suggested in the question and @DavidW's idea of cimport *
Upvotes: 2