import torch
from typing import Sequence


def crop(data: torch.Tensor, corner: Sequence[int], size: Sequence[int]) -> torch.Tensor:
    """
    Extract crop from last dimensions of data

    Args:
    data: input tensor
    corner: top left corner point
    size: size of patch

    Returns:
        torch.Tensor: cropped data
    """
    _slices = []
    if len(corner) < data.ndim:
        for i in range(data.ndim - len(corner)):
            _slices.append(slice(0, data.shape[i]))

    _slices = _slices + [slice(c, c + s) for c, s in zip(corner, size)]
    return data[_slices]