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)
| 109 | |
| 110 | |
| 111 | def 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 | |
| 156 | def _trim(x, axes, boundary, _overlap_trim_info): |
searching dependent graphs…