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

Function ensure_minimum_chunksize

dask/array/overlap.py:320–368  ·  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

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

Callers 2

sliding_window_viewFunction · 0.70

Calls 2

minFunction · 0.85
sumFunction · 0.70

Tested by

no test coverage detected