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)
| 95 | |
| 96 | |
| 97 | def 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 | elif isinstance(overlap, tuple): |
| 123 | d = d - overlap[0] if j != 0 else d |
| 124 | d = d - overlap[1] if j != len(bd) - 1 else d |
| 125 | else: |
| 126 | d = d - overlap if j != 0 else d |
| 127 | d = d - overlap if j != len(bd) - 1 else d |
| 128 | |
| 129 | ilist.append(d) |
| 130 | olist.append(tuple(ilist)) |
| 131 | chunks = tuple(olist) |
| 132 | |
| 133 | return map_blocks( |
| 134 | partial(_trim, axes=axes, boundary=boundary), |
| 135 | x, |
| 136 | chunks=chunks, |
| 137 | dtype=x.dtype, |
| 138 | meta=x._meta, |
| 139 | ) |
| 140 | |
| 141 | |
| 142 | def _trim(x, axes, boundary, _overlap_trim_info): |
no test coverage detected
searching dependent graphs…