MCPcopy
hub / github.com/dask/dask / expand_tuple

Function expand_tuple

dask/array/reshape.py:229–257  ·  view source on GitHub ↗

>>> expand_tuple((2, 4), 2) (1, 1, 2, 2) >>> expand_tuple((2, 4), 3) (1, 1, 1, 1, 2) >>> expand_tuple((3, 4), 2) (1, 2, 2, 2) >>> expand_tuple((7, 4), 3) (2, 2, 3, 1, 1, 2)

(chunks, factor)

Source from the content-addressed store, hash-verified

227
228
229def expand_tuple(chunks, factor):
230 """
231
232 >>> expand_tuple((2, 4), 2)
233 (1, 1, 2, 2)
234
235 >>> expand_tuple((2, 4), 3)
236 (1, 1, 1, 1, 2)
237
238 >>> expand_tuple((3, 4), 2)
239 (1, 2, 2, 2)
240
241 >>> expand_tuple((7, 4), 3)
242 (2, 2, 3, 1, 1, 2)
243 """
244 if factor == 1:
245 return chunks
246
247 out = []
248 for c in chunks:
249 x = c
250 part = max(x / factor, 1)
251 while x >= 2 * part:
252 out.append(int(part))
253 x -= int(part)
254 if x:
255 out.append(x)
256 assert sum(chunks) == sum(out)
257 return tuple(out)
258
259
260def contract_tuple(chunks, factor):

Callers 2

test_expand_tupleFunction · 0.90
reshape_rechunkFunction · 0.85

Calls 2

maxFunction · 0.85
sumFunction · 0.70

Tested by 1

test_expand_tupleFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…