import torch


def _crop(img: torch.Tensor, x: int, y: int, z: int, w: int, h: int, d: int) -> torch.Tensor:
    """
    torch scriptable function which crops an image

    :param img: torch.Tensor image of shape [C, X, Y, Z]
    :param x: x coord of crop box
    :param y: y coord of crop box
    :param z: z coord of crop box
    :param w: width of crop box
    :param h: height of crop box
    :param d: depth of crop box
    :return:
    """
    if img.ndim == 4:
        img = img[:, x:x + w, y:y + h, z:z + d]
    elif img.ndim == 5:
        img = img[:, :, x:x + w, y:y + h, z:z + d]
    else:
        raise IndexError('Unsupported number of dimensions')

    return img