summaryrefslogtreecommitdiff
path: root/numpy/core/_methods.py
diff options
context:
space:
mode:
authorPieter Eendebak <pieter.eendebak@gmail.com>2022-05-11 11:51:37 +0200
committerGitHub <noreply@github.com>2022-05-11 11:51:37 +0200
commit42dc6537497d563612eab053d9dbf497d210a5a7 (patch)
tree0190bdd6269fec30665bb942963b88ce2d6641e9 /numpy/core/_methods.py
parentef3c1b8215d7510c5e8e13f27e075f35174c2efa (diff)
downloadnumpy-42dc6537497d563612eab053d9dbf497d210a5a7.tar.gz
PERF: Use python integer on _count_reduce_items (#21465)
Small micro-optimization, since using Python integers is generally a bit faster in the loop. The effect is small, so this could undone if anyone figures it is cleaner the other way.
Diffstat (limited to 'numpy/core/_methods.py')
-rw-r--r--numpy/core/_methods.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/numpy/core/_methods.py b/numpy/core/_methods.py
index a239e2c87..eda00147d 100644
--- a/numpy/core/_methods.py
+++ b/numpy/core/_methods.py
@@ -71,9 +71,10 @@ def _count_reduce_items(arr, axis, keepdims=False, where=True):
axis = tuple(range(arr.ndim))
elif not isinstance(axis, tuple):
axis = (axis,)
- items = nt.intp(1)
+ items = 1
for ax in axis:
items *= arr.shape[mu.normalize_axis_index(ax, arr.ndim)]
+ items = nt.intp(items)
else:
# TODO: Optimize case when `where` is broadcast along a non-reduction
# axis and full sum is more excessive than needed.