mrpro.utils.sliding_window

mrpro.utils.sliding_window(x: Tensor, window_shape: int | Sequence[int], dim: int | Sequence[int] | None = None, stride: int | Sequence[int] | None = 1, dilation: int | Sequence[int] = 1) Tensor[source]

Create a sliding window view into a tensor.

Returns a view into tensor x where new dim representing the number of windows are added at the front, and the original dim involved in the sliding operation are replaced by window dimensions.

Example

Input shape (D1, D2, D3, D4, D5), dim=(1, 3), window_shape=(k2, k4) Output shape: (n_windows_2, n_windows_4, D1, k2, D3, k4, D5)

Parameters:
  • x (Tensor) – Input tensor to create sliding windows from

  • window_shape (int | Sequence[int]) – Size of window over each dimension

  • dim (int | Sequence[int] | None, default: None) – Dimension(s) to apply to. If None, applies to all dimensions.

  • stride (int | Sequence[int] | None, default: 1) – Stride of the sliding window. If None, equals window_shape.

  • dilation (int | Sequence[int], default: 1) – Spacing between window elements for each dimension.

Returns:

A view of the tensor with window dimensions at the front and original sliding dim replaced by kernel dimensions.