Pads an array which has 'none' as the boundary type. Used to simplify trimming arrays which use 'none'. >>> import dask.array as da >>> x = da.arange(6, chunks=3) >>> add_dummy_padding(x, {0: 1}, {0: 'none'}).compute() # doctest: +NORMALIZE_WHITESPACE array([..., 0, 1, 2,
(x, depth, boundary)
| 476 | |
| 477 | |
| 478 | def add_dummy_padding(x, depth, boundary): |
| 479 | """ |
| 480 | Pads an array which has 'none' as the boundary type. |
| 481 | Used to simplify trimming arrays which use 'none'. |
| 482 | |
| 483 | >>> import dask.array as da |
| 484 | >>> x = da.arange(6, chunks=3) |
| 485 | >>> add_dummy_padding(x, {0: 1}, {0: 'none'}).compute() # doctest: +NORMALIZE_WHITESPACE |
| 486 | array([..., 0, 1, 2, 3, 4, 5, ...]) |
| 487 | """ |
| 488 | for k, v in boundary.items(): |
| 489 | d = depth.get(k, 0) |
| 490 | if v == "none" and d > 0: |
| 491 | empty_shape = list(x.shape) |
| 492 | empty_shape[k] = d |
| 493 | |
| 494 | empty_chunks = list(x.chunks) |
| 495 | empty_chunks[k] = (d,) |
| 496 | |
| 497 | empty = empty_like( |
| 498 | getattr(x, "_meta", x), |
| 499 | shape=empty_shape, |
| 500 | chunks=empty_chunks, |
| 501 | dtype=x.dtype, |
| 502 | ) |
| 503 | |
| 504 | out_chunks = list(x.chunks) |
| 505 | ax_chunks = list(out_chunks[k]) |
| 506 | ax_chunks[0] += d |
| 507 | ax_chunks[-1] += d |
| 508 | out_chunks[k] = tuple(ax_chunks) |
| 509 | |
| 510 | x = concatenate([empty, x, empty], axis=k) |
| 511 | x = x.rechunk(out_chunks) |
| 512 | return x |
| 513 | |
| 514 | |
| 515 | def map_overlap( |
nothing calls this directly
no test coverage detected
searching dependent graphs…