-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add type caster for complex numbers #292
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add test coverage to the official test suite? (this should validate the casting in both directions for std::complex<float>
and std:::complex<double>
).
I'll see for coding the tests, it might take me a bit of time. |
You can put tests into the existing STL type casters (it is part of that). I don't think it needs to be that complicated: show that you can pass a complex number to C++ and back, for single and double versions. |
c15c31c
to
41b241b
Compare
I'm checking in on the status of this PR -- will you be able to add test coverage @gillesdegottex ? |
Give me up to next Monday plz, and just close it if I can't do it by then. |
All done. The 9 failing tests do so because of numpy module not being installed on the corresponding docker image. |
I made a number of changes to this PR and merged it as commit dcbed4f. |
Great thx! |
This is an attempt to add support for complex numbers using a
type_caster
(previously discussed as #286 ).With test code:
This works with test commands:
However, it fails when numpy input is 32b float (i.e. np.complex64), ex:
This happens, no matter if I'm using
std::complex<float>
orstd::complex<double>
in test code.My understanding is that a
PyComplex
seems to be built at some point assuming double size (because base python (not numpy) complex type is always double) and I can't find where this is built (I guess before call totype_caster<std::complex<T1>>::from_python(.)
).If anybody has an idea about this issue, it is very much welcome!
Even though forcing to 64b float could be enough, this is clearly not optimal both in terms of efficiency and memory.
Elements to review:
np.complex64
inputs, as mentioned above: Now supported.make_caster<T1>
I think. See TODO tag in filestl/complex.h
: Cleaned.