MCPcopy
hub / github.com/dask/dask / cumreduction

Function cumreduction

dask/array/reductions.py:1157–1278  ·  view source on GitHub ↗

Generic function for cumulative reduction Parameters ---------- func: callable Cumulative function like np.cumsum or np.cumprod binop: callable Associated binary operator like ``np.cumsum->add`` or ``np.cumprod->mul`` ident: Number Associated identity lik

(
    func,
    binop,
    ident,
    x,
    axis=None,
    dtype=None,
    out=None,
    method="sequential",
    preop=None,
)

Source from the content-addressed store, hash-verified

1155
1156
1157def cumreduction(
1158 func,
1159 binop,
1160 ident,
1161 x,
1162 axis=None,
1163 dtype=None,
1164 out=None,
1165 method="sequential",
1166 preop=None,
1167):
1168 """Generic function for cumulative reduction
1169
1170 Parameters
1171 ----------
1172 func: callable
1173 Cumulative function like np.cumsum or np.cumprod
1174 binop: callable
1175 Associated binary operator like ``np.cumsum->add`` or ``np.cumprod->mul``
1176 ident: Number
1177 Associated identity like ``np.cumsum->0`` or ``np.cumprod->1``
1178 x: dask Array
1179 axis: int
1180 dtype: dtype
1181 method : {'sequential', 'blelloch'}, optional
1182 Choose which method to use to perform the cumsum. Default is 'sequential'.
1183
1184 * 'sequential' performs the scan of each prior block before the current block.
1185 * 'blelloch' is a work-efficient parallel scan. It exposes parallelism by first
1186 calling ``preop`` on each block and combines the values via a binary tree.
1187 This method may be faster or more memory efficient depending on workload,
1188 scheduler, and hardware. More benchmarking is necessary.
1189 preop: callable, optional
1190 Function used by 'blelloch' method,
1191 like ``np.cumsum->np.sum`` or ``np.cumprod->np.prod``
1192
1193 Returns
1194 -------
1195 dask array
1196
1197 See also
1198 --------
1199 cumsum
1200 cumprod
1201 """
1202 if method == "blelloch":
1203 if preop is None:
1204 raise TypeError(
1205 'cumreduction with "blelloch" method required `preop=` argument'
1206 )
1207 return prefixscan_blelloch(func, preop, binop, x, axis, dtype, out=out)
1208 elif method != "sequential":
1209 raise ValueError(
1210 f'Invalid method for cumreduction. Expected "sequential" or "blelloch". Got: {method!r}'
1211 )
1212
1213 if axis is None:
1214 if x.ndim > 1:

Callers 6

pushFunction · 0.90
nancumsumFunction · 0.85
nancumprodFunction · 0.85
cumsumFunction · 0.85
cumprodFunction · 0.85

Calls 11

validate_axisFunction · 0.90
ArrayClass · 0.90
handle_outFunction · 0.90
prefixscan_blellochFunction · 0.85
flattenMethod · 0.80
from_collectionsMethod · 0.80
funcFunction · 0.70
tokenizeFunction · 0.50
rechunkMethod · 0.45
onesMethod · 0.45
map_blocksMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…