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

Function ensure_minimum_chunksize

dask/array/_array_expr/_overlap.py:334–382  ·  view source on GitHub ↗

Determine new chunks to ensure that every chunk >= size Parameters ---------- size: int The maximum size of any chunk. chunks: tuple Chunks along one axis, e.g. ``(3, 3, 2)`` Examples -------- >>> ensure_minimum_chunksize(10, (20, 20, 1)) (20, 11, 10

(size, chunks)

Source from the content-addressed store, hash-verified

332
333
334def ensure_minimum_chunksize(size, chunks):
335 """Determine new chunks to ensure that every chunk >= size
336
337 Parameters
338 ----------
339 size: int
340 The maximum size of any chunk.
341 chunks: tuple
342 Chunks along one axis, e.g. ``(3, 3, 2)``
343
344 Examples
345 --------
346 >>> ensure_minimum_chunksize(10, (20, 20, 1))
347 (20, 11, 10)
348 >>> ensure_minimum_chunksize(3, (1, 1, 3))
349 (5,)
350
351 See Also
352 --------
353 overlap
354 """
355 if size <= min(chunks):
356 return chunks
357
358 # add too-small chunks to chunks before them
359 output = []
360 new = 0
361 for c in chunks:
362 if c < size:
363 if new > size + (size - c):
364 output.append(new - (size - c))
365 new = size
366 else:
367 new += c
368 if new >= size:
369 output.append(new)
370 new = 0
371 if c >= size:
372 new += c
373 if new >= size:
374 output.append(new)
375 elif len(output) >= 1:
376 output[-1] += new
377 else:
378 raise ValueError(
379 f"The overlapping depth {size} is larger than your array {sum(chunks)}."
380 )
381
382 return tuple(output)
383
384
385def _get_overlap_rechunked_chunks(x, depth2):

Calls 2

minFunction · 0.85
sumFunction · 0.50