(x, func, axis, dtype, out, include_initial)
| 2674 | |
| 2675 | |
| 2676 | def _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 | |
| 2705 | def _cumulative_prod_dispatcher(x, /, *, axis=None, dtype=None, out=None, |
no test coverage detected
searching dependent graphs…