Closed
Description
Describe the issue:
Implicit type casting for binary operators seems to ignore types of scalar values, see code example below where the left operand is passed a 0D scalar and 1D array respectively.
This behaviour provokes unexpected overflow errors in corner cases of empty shape tuples that can be easily overseen.
Reproduce the code example:
import numpy as np
type_w_scalar = (np.ones((), dtype=np.int32) + np.ones(5, dtype=np.int16)).dtype
type_wo_scalar = (np.ones(1, dtype=np.int32) + np.ones(5, dtype=np.int16)).dtype
promoted_type = np.promote_types(np.int32, np.int16)
# Note that promoted_type == type_wo_scalar != type_w_scalar
# promoted_type == np.int32
# type_wo_scalar == np.int32
# type_w_scalar == np.int16
print(type_w_scalar, type_wo_scalar, promoted_type)
Error message:
No response
NumPy/Python version information:
1.20.3 3.8.8 (default, Feb 24 2021, 21:46:12)
[GCC 7.3.0]