Skip to content

Commit 42dc653

Browse files
authored
PERF: Use python integer on _count_reduce_items (numpy#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.
1 parent ef3c1b8 commit 42dc653

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

numpy/core/_methods.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ def _count_reduce_items(arr, axis, keepdims=False, where=True):
7171
axis = tuple(range(arr.ndim))
7272
elif not isinstance(axis, tuple):
7373
axis = (axis,)
74-
items = nt.intp(1)
74+
items = 1
7575
for ax in axis:
7676
items *= arr.shape[mu.normalize_axis_index(ax, arr.ndim)]
77+
items = nt.intp(items)
7778
else:
7879
# TODO: Optimize case when `where` is broadcast along a non-reduction
7980
# axis and full sum is more excessive than needed.

0 commit comments

Comments
 (0)