import torch
from typing import Tuple


def clip_boxes_to_image_2d_(boxes: torch.Tensor, img_shape: Tuple[int, int]):
    """
    Clip boxes to image dimensions

    Args:
        boxes (Tensor): tensor with boxes [N x 4] (x_min, y_min, x_max, y_max)
        img_shape (Tuple[x_max, y_max]): size of image

    Returns:
        Tensor: clipped boxes as tensor
    """
    s0, s1 = img_shape
    boxes[..., 0::2].clamp_(min=0, max=s0)
    boxes[..., 1::2].clamp_(min=0, max=s1)
    return boxes