NumPy operations generally follow the rule that the output dtype/shape is a deterministic function of the inputs dtype/shape.
However, binary arithmetic with 0d arrays appears to be an exception to these rules. Consider:
np.array(12).dtype # int64
np.array(4625196817309499392).dtype # int64
(np.array([[123]], dtype=np.float32) + np.array(12)).dtype # float32
(np.array([[123]], dtype=np.float32) + np.array(4625196817309499392)).dtype # float64
Basically, whether the result is float32 depends on the size of the scalar argument.
I can see why this would be desirable for operations with Python scalars (e.g., array + 1), but when the 0d/scalar argument is already typed this is highly surprising.
EDIT seberg: This is basically what NEP 50 is about.
NumPy operations generally follow the rule that the output dtype/shape is a deterministic function of the inputs dtype/shape.
However, binary arithmetic with 0d arrays appears to be an exception to these rules. Consider:
Basically, whether the result is float32 depends on the size of the scalar argument.
I can see why this would be desirable for operations with Python scalars (e.g.,
array + 1), but when the 0d/scalar argument is already typed this is highly surprising.EDIT seberg: This is basically what NEP 50 is about.