From d40d2bcfbe01678479fe741ab8b0ff5e431e0329 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 13 Apr 2021 18:11:09 -0600 Subject: Fix ceil() and floor() in the array API to always return the same dtype --- 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 aa48f440c..3ca71b53e 100644 --- a/numpy/_array_api/_elementwise_functions.py +++ b/numpy/_array_api/_elementwise_functions.py @@ -190,6 +190,9 @@ def ceil(x: array, /) -> array: """ if x.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in ceil') + if x.dtype in _integer_dtypes: + # Note: The return dtype of ceil is the same as the input + return x return ndarray._new(np.ceil(x._array)) def cos(x: array, /) -> array: @@ -258,6 +261,9 @@ def floor(x: array, /) -> array: """ if x.dtype not in _numeric_dtypes: raise TypeError('Only numeric dtypes are allowed in floor') + if x.dtype in _integer_dtypes: + # Note: The return dtype of floor is the same as the input + return x return ndarray._new(np.floor(x._array)) def floor_divide(x1: array, x2: array, /) -> array: -- cgit v1.2.1