-
|
I recently hit a surprise in how function overload is selected. I crafted a small repro that can be dropped into the nanobind_example project: In the below example, the second overload is chosen. This is what I'd expect to happen as both inputs are ndarrays. However, if I any other element type than the default np.float64, say, np.float32 or np.uint8, looks like the second argument is implicitly converted to a scalar float, and the first overload is chosen instead: It works again if I re-order the overloads in the C++ binding code to put the Numpy also issues a deprecation warning about, as can be seen above. Is this a bug? Or can I turn off 1-dim arrays from being automatically converted to scalars? Or is the right fix to reorder the overloads in the binding implementation? I don't know the overload resolution algorithm well enough to know what workaround to apply. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
|
I think this is expected. |
Beta Was this translation helpful? Give feedback.
-
|
See also: implicit conversions and overload resolution order |
Beta Was this translation helpful? Give feedback.
-
|
I suggested NumPy to raise TypeError: numpy/numpy#29835 |
Beta Was this translation helpful? Give feedback.
Nanobind is not doing the conversion; NumPy is.
I agree it should not. The NumPy developers must agree as well since they deprecated it.
Maybe they've started throwing
TypeErrorin a newer release?If not, you can suggest that it might now be better to start doing so.
If NumPy did not do the conversion, nanobind would move on to the next overload.