import torch


def xy_to_cxcy(xy):
    """
    Convert bounding boxes from boundary coords (x_min, y_min, x_max, y_max) to
    center-size coords (c_x, c_y, w, h).

    Args:
        xy: bounding boxes in boundary coords - a tensor of size (n_boxes, 4)

    Returns:
        bounding boxes in center-size coords - a tensor of size(n_boxes, 4)
    """
    return torch.cat(
        [(xy[:, 2:] + xy[:, :2]) / 2, (xy[:, 2:] - xy[:, :2])], 1  # (c_x, c_y), (w, h)
    )