MCPcopy Index your code
hub / github.com/numpy/numpy / _count_reduce_items

Function _count_reduce_items

numpy/_core/_methods.py:73–94  ·  view source on GitHub ↗
(arr, axis, keepdims=False, where=True)

Source from the content-addressed store, hash-verified

71 return umr_all(a, axis, dtype, out, keepdims, where=where)
72
73def _count_reduce_items(arr, axis, keepdims=False, where=True):
74 # fast-path for the default case
75 if where is True:
76 # no boolean mask given, calculate items according to axis
77 if axis is None:
78 axis = tuple(range(arr.ndim))
79 elif not isinstance(axis, tuple):
80 axis = (axis,)
81 items = 1
82 for ax in axis:
83 items *= arr.shape[mu.normalize_axis_index(ax, arr.ndim)]
84 items = nt.intp(items)
85 else:
86 # TODO: Optimize case when `where` is broadcast along a non-reduction
87 # axis and full sum is more excessive than needed.
88
89 # guarded to protect circular imports
90 from numpy.lib._stride_tricks_impl import broadcast_to
91 # count True values in (potentially broadcasted) boolean mask
92 items = umr_sum(broadcast_to(where, arr.shape), axis, nt.intp, None,
93 keepdims)
94 return items
95
96def _clip(a, min=None, max=None, out=None, **kwargs):
97 if a.dtype.kind in "iu":

Callers 2

_meanFunction · 0.85
_varFunction · 0.85

Calls 1

broadcast_toFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…