[C++-sig] std::complex vs python complex
Holger Brandsmeier
brandsmeier at gmx.de
Tue Apr 10 12:58:03 CEST 2012
Dear list,
I exported a wrapper for std::complex<double> to python and I am
willing to always use this class in python and I never want to use
pythons own `complex` data type.
However, a funny thing happens when I export the addition operator
(the implemenation is given in the STL ...)
.def(self + self)
Now I get that:
type(scalar_cd(1,2) + scalar_cd(1,2))
<type 'complex'>
But my own type is of the form:
type(scalar_cd(1,2))
<class 'parfem.scalarPy.scalar_cd'>
Why did this happen and how can I avoid this? Later own I get problems
when I want to pass this back to C++.
I remember that pythons own complex type is a bit special and does not
cooperate nicely with boost::python and std::complex<> but how did
python/boost::python end up converting the result of the addition to
`complex`?
I am using:
Python 2.7.2
boost-1.46.1
Best regards,
Holger Brandsmeier
More information about the Cplusplus-sig
mailing list