import torch


def xywh2xyxy(inputs: torch.Tensor) -> torch.Tensor:
    """Converts from [x, y, w, h] to [x1, y1, x2, y2] format.

    (x, y) is the object center, w is the width, and h is the height. (x1, y1)
    is the top left corner and (x2, y2) is the bottom right corner.

    [x1, y1, x2, y2] is calculated as:
    x1 = x - w / 2
    y1 = y - h / 2
    x2 = x + w / 2
    y2 = y + w / 2

    Example:
        >>> a = xywh2xyxy(inputs=torch.Tensor([[100, 200, 30, 40]]))
        >>> a
        tensor([[ 85.0, 180.0, 115.0, 220.0]])

    Args:
        inputs (torch.Tensor): Input bounding boxes (2-d array) each with the
            format `(center x, center y, width, height)`.

    Returns:
        (torch.Tensor): Bounding boxes with the format `(top left x, top left y,
        bottom right x, bottom right y)`.
    """
    outputs = torch.empty_like(inputs)
    outputs[:, 0] = inputs[:, 0] - inputs[:, 2] / 2
    outputs[:, 1] = inputs[:, 1] - inputs[:, 3] / 2
    outputs[:, 2] = inputs[:, 0] + inputs[:, 2] / 2
    outputs[:, 3] = inputs[:, 1] + inputs[:, 3] / 2

    return outputs