import torch


def scale_boxes(bboxes, scale):
    """Expand an array of boxes by a given scale.
        Args:
            bboxes (Tensor): shape (m, 4)
            scale (float): the scale factor of bboxes

        Returns:
            (Tensor): shape (m, 4) scaled bboxes
        """
    w_half = (bboxes[:, 2] - bboxes[:, 0] + 1) * .5
    h_half = (bboxes[:, 3] - bboxes[:, 1] + 1) * .5
    x_c = (bboxes[:, 2] + bboxes[:, 0] + 1) * .5
    y_c = (bboxes[:, 3] + bboxes[:, 1] + 1) * .5

    w_half *= scale
    h_half *= scale

    boxes_exp = torch.zeros_like(bboxes)
    boxes_exp[:, 0] = x_c - w_half
    boxes_exp[:, 2] = x_c + w_half - 1
    boxes_exp[:, 1] = y_c - h_half
    boxes_exp[:, 3] = y_c + h_half - 1
    return boxes_exp