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

Function trim_internal

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

95
96
97def trim_internal(x, axes, boundary=None):
98 """Trim sides from each block
99
100 This couples well with the overlap operation, which may leave excess data on
101 each block
102
103 See also
104 --------
105 dask.array.chunk.trim
106 dask.array.map_blocks
107 """
108 boundary = coerce_boundary(x.ndim, boundary)
109
110 olist = []
111 for i, bd in enumerate(x.chunks):
112 bdy = boundary.get(i, "none")
113 overlap = axes.get(i, 0)
114 ilist = []
115 for j, d in enumerate(bd):
116 if bdy != "none":
117 if isinstance(overlap, tuple):
118 d = d - sum(overlap)
119 else:
120 d = d - overlap * 2
121
122 else:
123 if isinstance(overlap, tuple):
124 d = d - overlap[0] if j != 0 else d
125 d = d - overlap[1] if j != len(bd) - 1 else d
126 else:
127 d = d - overlap if j != 0 else d
128 d = d - overlap if j != len(bd) - 1 else d
129
130 ilist.append(d)
131 olist.append(tuple(ilist))
132 chunks = tuple(olist)
133
134 return map_blocks(
135 partial(_trim, axes=axes, boundary=boundary),
136 x,
137 chunks=chunks,
138 dtype=x.dtype,
139 meta=x._meta,
140 )
141
142
143def _trim(x, axes, boundary, _overlap_trim_info):

Callers 2

trim_overlapFunction · 0.70
map_overlapFunction · 0.70

Calls 4

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

Tested by

no test coverage detected