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

Function add_dummy_padding

dask/array/_array_expr/_overlap.py:479–513  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

empty_likeFunction · 0.90
concatenateFunction · 0.90
itemsMethod · 0.45
getMethod · 0.45
rechunkMethod · 0.45

Tested by

no test coverage detected