MCPcopy
hub / github.com/dask/dask / contract_tuple

Function contract_tuple

dask/array/reshape.py:260–280  ·  view source on GitHub ↗

Return simple chunks tuple such that factor divides all elements Examples -------- >>> contract_tuple((2, 2, 8, 4), 4) (4, 8, 4)

(chunks, factor)

Source from the content-addressed store, hash-verified

258
259
260def contract_tuple(chunks, factor):
261 """Return simple chunks tuple such that factor divides all elements
262
263 Examples
264 --------
265
266 >>> contract_tuple((2, 2, 8, 4), 4)
267 (4, 8, 4)
268 """
269 assert sum(chunks) % factor == 0
270
271 out = []
272 residual = 0
273 for chunk in chunks:
274 chunk += residual
275 div = chunk // factor
276 residual = chunk % factor
277 good = factor * div
278 if good:
279 out.append(good)
280 return tuple(out)
281
282
283def reshape(x, shape, merge_chunks=True, limit=None):

Callers 2

test_contract_tupleFunction · 0.90
reshape_rechunkFunction · 0.85

Calls 1

sumFunction · 0.70

Tested by 1

test_contract_tupleFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…