From 479c8a24121465bbb9e0e193dc2da39cd08bdfe4 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 18 Mar 2021 15:26:50 -0600 Subject: bitwise_left_shift and bitwise_right_shift are only defined for x2 >= 0 --- numpy/_array_api/_elementwise_functions.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'numpy/_array_api/_elementwise_functions.py') 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. -- cgit v1.2.1