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

Function _cumulative_func

numpy/_core/fromnumeric.py:2676–2702  ·  view source on GitHub ↗
(x, func, axis, dtype, out, include_initial)

Source from the content-addressed store, hash-verified

2674
2675
2676def _cumulative_func(x, func, axis, dtype, out, include_initial):
2677 x = np.atleast_1d(x)
2678 x_ndim = x.ndim
2679 if axis is None:
2680 if x_ndim >= 2:
2681 raise ValueError("For arrays which have more than one dimension "
2682 "``axis`` argument is required.")
2683 axis = 0
2684
2685 if out is not None and include_initial:
2686 item = [slice(None)] * x_ndim
2687 item[axis] = slice(1, None)
2688 func.accumulate(x, axis=axis, dtype=dtype, out=out[tuple(item)])
2689 item[axis] = 0
2690 out[tuple(item)] = func.identity
2691 return out
2692
2693 res = func.accumulate(x, axis=axis, dtype=dtype, out=out)
2694 if include_initial:
2695 initial_shape = list(x.shape)
2696 initial_shape[axis] = 1
2697 res = np.concat(
2698 [np.full_like(res, func.identity, shape=initial_shape), res],
2699 axis=axis,
2700 )
2701
2702 return res
2703
2704
2705def _cumulative_prod_dispatcher(x, /, *, axis=None, dtype=None, out=None,

Callers 2

cumulative_prodFunction · 0.85
cumulative_sumFunction · 0.85

Calls 2

sliceFunction · 0.85
accumulateMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…