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