Repository: numpy/numpy
File: numpy/lib/_stride_tricks_impl.py (Python)

Code before:
    # The route via `__interface__` does not preserve structured
    # dtypes. Since dtype should remain unchanged, we set it explicitly.
    array.dtype = base.dtype

    view = _maybe_view_as_subclass(base, array)

    if view.flags.writeable and not writeable:
        view.flags.writeable = False

    if check_bounds:
        while isinstance(base.base, np.ndarray):
            base = base.base

        base_low, base_high = byte_bounds(base)
        view_low, view_high = byte_bounds(view)

        if view_low < base_low:
            raise ValueError(
                f"Given shape and strides would access memory out of bounds. "
                f"View starts {base_low - view_low} before starts"
            )

        if view_high > base_high:
            raise ValueError(
                f"Given shape and strides would access memory out of bounds. "
                f"View ends {view_high - base_high} after ends"
            )

    return view


def _sliding_window_view_dispatcher(x, window_shape, axis=None, *,
                                    subok=None, writeable=None):
    return (x,)


@array_function_dispatch(
    _sliding_window_view_dispatcher, module="numpy.lib.stride_tricks"
)
def sliding_window_view(x, window_shape, axis=None, *,
                        subok=False, writeable=False):
    """
    Create a sliding window view into the array with the given window shape.

    Also known as rolling or moving window, the window slides across all
    dimensions of the array and extracts subsets of the array at all window
    positions.

    .. versionadded:: 1.20.0

    Parameters

Review comment (suggestion):
```suggestion
                f"View ends {view_high - base_high} bytes after highest address"
```

Code after:
    # The route via `__interface__` does not preserve structured
    # dtypes. Since dtype should remain unchanged, we set it explicitly.
    array.dtype = base.dtype

    view = _maybe_view_as_subclass(base, array)

    if view.flags.writeable and not writeable:
        view.flags.writeable = False

    if check_bounds:
        while isinstance(base.base, np.ndarray):
            base = base.base

        base_low, base_high = byte_bounds(base)
        view_low, view_high = byte_bounds(view)

        if view_low < base_low:
            raise ValueError(
                f"Given shape and strides would access memory out of bounds. "
                f"View starts {base_low - view_low} bytes before lowest address"
            )

        if view_high > base_high:
            raise ValueError(
                f"Given shape and strides would access memory out of bounds. "
                f"View ends {view_high - base_high} bytes after highest address"
            )

    return view


def _sliding_window_view_dispatcher(x, window_shape, axis=None, *,
                                    subok=None, writeable=None):
    return (x,)


@array_function_dispatch(
    _sliding_window_view_dispatcher, module="numpy.lib.stride_tricks"
)
def sliding_window_view(x, window_shape, axis=None, *,
                        subok=False, writeable=False):
    """
    Create a sliding window view into the array with the given window shape.

    Also known as rolling or moving window, the window slides across all
    dimensions of the array and extracts subsets of the array at all window
    positions.

    .. versionadded:: 1.20.0

    Parameters