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

Function add_dummy_padding

dask/array/overlap.py:465–499  ·  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

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