summaryrefslogtreecommitdiff
path: root/numpy/array_api/_statistical_functions.py
diff options
context:
space:
mode:
authorDeveloper-Ecosystem-Engineering <65677710+Developer-Ecosystem-Engineering@users.noreply.github.com>2021-11-18 14:32:20 -0800
committerDeveloper-Ecosystem-Engineering <65677710+Developer-Ecosystem-Engineering@users.noreply.github.com>2021-11-18 14:32:20 -0800
commit9fe353e048bc317099bb13cae4cb5a4de8c0c656 (patch)
tree4976e4328da9906d99cd2478547ca1e2829e071d /numpy/array_api/_statistical_functions.py
parent66ca468b97873c1c8bfe69bddac6df633780c71c (diff)
parent5e9ce0c0529e3085498ac892941a020a65c7369a (diff)
downloadnumpy-9fe353e048bc317099bb13cae4cb5a4de8c0c656.tar.gz
Merge branch 'as_min_max' of https://github.com/Developer-Ecosystem-Engineering/numpy into as_min_max
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(