summaryrefslogtreecommitdiff
path: root/numpy/array_api/_statistical_functions.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/array_api/_statistical_functions.py')
-rw-r--r--numpy/array_api/_statistical_functions.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/numpy/array_api/_statistical_functions.py b/numpy/array_api/_statistical_functions.py
index c5abf9468..7bee3f4db 100644
--- a/numpy/array_api/_statistical_functions.py
+++ b/numpy/array_api/_statistical_functions.py
@@ -93,11 +93,12 @@ def sum(
) -> Array:
if x.dtype not in _numeric_dtypes:
raise TypeError("Only numeric dtypes are allowed in sum")
- # Note: sum() and prod() always upcast float32 to float64 for dtype=None
- # We need to do so here before summing to avoid overflow
+ # Note: sum() and prod() always upcast integers to (u)int64 and float32 to
+ # float64 for dtype=None. `np.sum` does that too for integers, but not for
+ # float32, so we need to special-case it here
if dtype is None and x.dtype == float32:
- x = asarray(x, dtype=float64)
- return Array._new(np.sum(x._array, axis=axis, keepdims=keepdims))
+ dtype = float64
+ return Array._new(np.sum(x._array, axis=axis, dtype=dtype, keepdims=keepdims))
def var(