MCPcopy Create free account
hub / github.com/dask/dask / cumreduction

Function cumreduction

dask/array/reductions.py:1154–1258  ·  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

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

Callers 5

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

no test coverage detected