Closed awni closed 3 months ago
Thanks for the fix @yosh-matsuda !
@yosh-matsuda and @wjakob there still seems to be an issue here. In the example above if I send in a NumPy array it matches to complex:
import numpy as np
test.print_type(np.array(1.0))
Do you mind to reopen this or shall I file a separate bug report?
@awni I think this is expected behavior.
Roughly speaking, the casting in your case seems to be attempted by the following:
nb::float_
checks type(numpy.array(1.0)) is float
. => False
std::complex<float>
checks,
type(numpy.array(1.0)) is complex
. => False
type(complex(float(numpy.array(1.0)))) is complex
. => True
How about using float
instead of nb::float_
?
using MyType = std::variant<
float,
std::complex<float>>;
I see, thanks. What I actually want is a third option in the variant to match which is for nb::ndarray<>
. I supposed if I check for that first, it will catch this case. Let me try.
PS what works for me is to put the ndarray before the std::complex<float>
in the variant. Thanks for your help!
Problem description
If
std::complex<float>
is included in a variant then it causes the variant to improperly detect non complex types as complex (see example below).Reproducible example code
And in Python: