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