diff options
author | Aaron Meurer <asmeurer@gmail.com> | 2021-03-18 15:26:50 -0600 |
---|---|---|
committer | Aaron Meurer <asmeurer@gmail.com> | 2021-03-18 15:26:50 -0600 |
commit | 479c8a24121465bbb9e0e193dc2da39cd08bdfe4 (patch) | |
tree | ad3418d45481316d51aa5852bb88e45d2963631a /numpy/_array_api/_elementwise_functions.py | |
parent | 8968bc31944eb2af214b591d38eca3b0cea56f4b (diff) | |
download | numpy-479c8a24121465bbb9e0e193dc2da39cd08bdfe4.tar.gz |
bitwise_left_shift and bitwise_right_shift are only defined for x2 >= 0
Diffstat (limited to 'numpy/_array_api/_elementwise_functions.py')
-rw-r--r-- | numpy/_array_api/_elementwise_functions.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/numpy/_array_api/_elementwise_functions.py b/numpy/_array_api/_elementwise_functions.py index a8af04c62..aa48f440c 100644 --- a/numpy/_array_api/_elementwise_functions.py +++ b/numpy/_array_api/_elementwise_functions.py @@ -126,6 +126,9 @@ def bitwise_left_shift(x1: array, x2: array, /) -> array: # Note: the function name is different here if x1.dtype not in _integer_dtypes or x2.dtype not in _integer_dtypes: raise TypeError('Only integer dtypes are allowed in bitwise_left_shift') + # Note: bitwise_left_shift is only defined for x2 nonnegative. + if np.any(x2._array < 0): + raise ValueError('bitwise_left_shift(x1, x2) is only defined for x2 >= 0') # Note: The spec requires the return dtype of bitwise_left_shift to be the # same as the first argument. np.left_shift() returns a type that is the # type promotion of the two input types. @@ -161,6 +164,9 @@ def bitwise_right_shift(x1: array, x2: array, /) -> array: # Note: the function name is different here if x1.dtype not in _integer_dtypes or x2.dtype not in _integer_dtypes: raise TypeError('Only integer dtypes are allowed in bitwise_right_shift') + # Note: bitwise_right_shift is only defined for x2 nonnegative. + if np.any(x2._array < 0): + raise ValueError('bitwise_right_shift(x1, x2) is only defined for x2 >= 0') # Note: The spec requires the return dtype of bitwise_left_shift to be the # same as the first argument. np.left_shift() returns a type that is the # type promotion of the two input types. |