import torch


def sort_corners(a):
    """
    Sort corners points (xmin, ymin, xmax, ymax)
    :param a: Box Tensor, shape is ([nums, ]*, 4=(x1,y1,x2,y2))
    :return a: Box Tensor, shape is ([nums, ]*, 4=(xmin, ymin, xmax, ymax))
    """
    return torch.cat((a[:, ::2].min(dim=-1, keepdims=True),
                      a[:, 1::2].min(dim=-1, keepdims=True),
                      a[:, ::2].max(dim=-1, keepdims=True),
                      a[:, 1::2].max(dim=-1, keepdims=True)), dim=-1)