Programmatically create a slice object of the right dimensions for pad_np. We assume pad_np's first two dimensions are not spatial and are not touched by the pad. pad_np[slice] should give the elements of the data that a pool operation will use for the step given in dim_coord.
(
spatial_dimensions: int,
pad_np: np.array,
dim_coord: tuple[int],
kernel: tuple[int],
strides: tuple[int],
dilation: tuple[int],
)
| 69 | |
| 70 | |
| 71 | def get_slice( |
| 72 | spatial_dimensions: int, |
| 73 | pad_np: np.array, |
| 74 | dim_coord: tuple[int], |
| 75 | kernel: tuple[int], |
| 76 | strides: tuple[int], |
| 77 | dilation: tuple[int], |
| 78 | ) -> tuple[slice]: |
| 79 | """ |
| 80 | Programmatically create a slice object of the right dimensions for pad_np. |
| 81 | |
| 82 | We assume pad_np's first two dimensions are not spatial and are not touched by the pad. |
| 83 | |
| 84 | pad_np[slice] should give the elements of the data that a pool operation will use for the |
| 85 | step given in dim_coord. |
| 86 | """ |
| 87 | slices = [slice(None)] * spatial_dimensions |
| 88 | |
| 89 | for nd in range(spatial_dimensions): |
| 90 | slices[nd] = slice( |
| 91 | dim_coord[nd] * strides[nd], |
| 92 | dim_coord[nd] * strides[nd] + (kernel[nd] - 1) * dilation[nd] + 1, |
| 93 | dilation[nd], |
| 94 | ) |
| 95 | |
| 96 | # Add back batch and channel dimensions |
| 97 | slices = [slice(None), slice(None)] + slices |
| 98 | |
| 99 | return tuple(slices) |
| 100 | |
| 101 | |
| 102 | def pad_tensor( |
no test coverage detected
searching dependent graphs…