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)
| 462 | |
| 463 | |
| 464 | def add_dummy_padding(x, depth, boundary): |
| 465 | """ |
| 466 | Pads an array which has 'none' as the boundary type. |
| 467 | Used to simplify trimming arrays which use 'none'. |
| 468 | |
| 469 | >>> import dask.array as da |
| 470 | >>> x = da.arange(6, chunks=3) |
| 471 | >>> add_dummy_padding(x, {0: 1}, {0: 'none'}).compute() # doctest: +NORMALIZE_WHITESPACE |
| 472 | array([..., 0, 1, 2, 3, 4, 5, ...]) |
| 473 | """ |
| 474 | for k, v in boundary.items(): |
| 475 | d = depth.get(k, 0) |
| 476 | if v == "none" and d > 0: |
| 477 | empty_shape = list(x.shape) |
| 478 | empty_shape[k] = d |
| 479 | |
| 480 | empty_chunks = list(x.chunks) |
| 481 | empty_chunks[k] = (d,) |
| 482 | |
| 483 | empty = empty_like( |
| 484 | getattr(x, "_meta", x), |
| 485 | shape=empty_shape, |
| 486 | chunks=empty_chunks, |
| 487 | dtype=x.dtype, |
| 488 | ) |
| 489 | |
| 490 | out_chunks = list(x.chunks) |
| 491 | ax_chunks = list(out_chunks[k]) |
| 492 | ax_chunks[0] += d |
| 493 | ax_chunks[-1] += d |
| 494 | out_chunks[k] = tuple(ax_chunks) |
| 495 | |
| 496 | x = concatenate([empty, x, empty], axis=k) |
| 497 | x = x.rechunk(out_chunks) |
| 498 | return x |
| 499 | |
| 500 | |
| 501 | def map_overlap( |
nothing calls this directly
no test coverage detected
searching dependent graphs…