MCPcopy Index your code
hub / github.com/dask/dask / trim_internal

Function trim_internal

dask/array/_array_expr/_overlap.py:111–153  ·  view source on GitHub ↗

Trim sides from each block This couples well with the overlap operation, which may leave excess data on each block See also -------- dask.array.chunk.trim dask.array.map_blocks

(x, axes, boundary=None)

Source from the content-addressed store, hash-verified

109
110
111def trim_internal(x, axes, boundary=None):
112 """Trim sides from each block
113
114 This couples well with the overlap operation, which may leave excess data on
115 each block
116
117 See also
118 --------
119 dask.array.chunk.trim
120 dask.array.map_blocks
121 """
122 boundary = coerce_boundary(x.ndim, boundary)
123
124 olist = []
125 for i, bd in enumerate(x.chunks):
126 bdy = boundary.get(i, "none")
127 overlap = axes.get(i, 0)
128 ilist = []
129 for j, d in enumerate(bd):
130 if bdy != "none":
131 if isinstance(overlap, tuple):
132 d = d - sum(overlap)
133 else:
134 d = d - overlap * 2
135
136 elif isinstance(overlap, tuple):
137 d = d - overlap[0] if j != 0 else d
138 d = d - overlap[1] if j != len(bd) - 1 else d
139 else:
140 d = d - overlap if j != 0 else d
141 d = d - overlap if j != len(bd) - 1 else d
142
143 ilist.append(d)
144 olist.append(tuple(ilist))
145 chunks = tuple(olist)
146
147 return map_blocks(
148 partial(_trim, axes=axes, boundary=boundary),
149 x,
150 chunks=chunks,
151 dtype=x.dtype,
152 meta=x._meta,
153 )
154
155
156def _trim(x, axes, boundary, _overlap_trim_info):

Callers 5

test_trim_internalFunction · 0.90
test_nearest_overlapFunction · 0.90
trim_overlapFunction · 0.70
map_overlapFunction · 0.70

Calls 4

map_blocksFunction · 0.90
coerce_boundaryFunction · 0.70
sumFunction · 0.50
getMethod · 0.45

Tested by 3

test_trim_internalFunction · 0.72
test_nearest_overlapFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…