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

Function trim_internal

dask/array/_array_expr/_overlap.py:111–154  ·  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 else:
137 if isinstance(overlap, tuple):
138 d = d - overlap[0] if j != 0 else d
139 d = d - overlap[1] if j != len(bd) - 1 else d
140 else:
141 d = d - overlap if j != 0 else d
142 d = d - overlap if j != len(bd) - 1 else d
143
144 ilist.append(d)
145 olist.append(tuple(ilist))
146 chunks = tuple(olist)
147
148 return map_blocks(
149 partial(_trim, axes=axes, boundary=boundary),
150 x,
151 chunks=chunks,
152 dtype=x.dtype,
153 meta=x._meta,
154 )
155
156
157def _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