import torch


def xywh2xyxy(xywh: torch.Tensor) -> torch.Tensor:
    """Convert nx4 boxes from [x, y, w, h] to [x1, y1, x2, y2]

    Args:
        xywh (torch.Tensor): tensor of 4 float [center_x, center_y, width, height]

    Returns:
        torch.Tensor: tensor of 4 float [x1, y1, x2, y2] where (x1,y1)==top-left
        and (x2,y2)==bottom-right.
    """
    xyxy = xywh.clone()
    xyxy[:, 0] = xywh[:, 0] - xywh[:, 2] / 2  # top left x
    xyxy[:, 1] = xywh[:, 1] - xywh[:, 3] / 2  # top left y
    xyxy[:, 2] = xywh[:, 0] + xywh[:, 2] / 2  # bottom right x
    xyxy[:, 3] = xywh[:, 1] + xywh[:, 3] / 2  # bottom right y
    return xyxy