def _points2bbox(F, pts, transform="minmax", y_first=True, **kwargs):
    """ Converting the points set into bounding box.
    :param pts: the input points sets (fields), each points set (fields) is represented
        as 2n scalar.
    :param transform: the transform from points to bbox: "minmax", "partial_minmax" or "moment"
    :param y_first: if y_first=True, the point set is represented as
        [y1, x1, y2, x2 ... yn, xn], otherwise the point set is represented as
        [x1, y1, x2, y2 ... xn, yn].
    :return: each points set is converting to a bbox [x1, y1, x2, y2].
    """
    pts = F.reshape(pts, (0, -4, -1, 2, -2))
    if y_first:
        pts_y, pts_x = F.split(pts, num_outputs=2, axis=2, squeeze_axis=True)
    else:
        pts_x, pts_y = F.split(pts, num_outputs=2, axis=2, squeeze_axis=True)

    if transform == "minmax":
        bbox_left = F.min(pts_x, axis=1, keepdims=True)
        bbox_right = F.max(pts_x, axis=1, keepdims=True)
        bbox_top = F.min(pts_y, axis=1, keepdims=True)
        bbox_bottom = F.max(pts_y, axis=1, keepdims=True)
        bbox = F.concat(bbox_left, bbox_top, bbox_right, bbox_bottom, dim=1)
    elif transform == "partial_minmax":
        pts_x = F.slice_axis(pts_x, begin=0, end=4, axis=1)
        pts_y = F.slice_axis(pts_y, begin=0, end=4, axis=1)
        bbox_left = F.min(pts_x, axis=1, keepdims=True)
        bbox_right = F.max(pts_x, axis=1, keepdims=True)
        bbox_top = F.min(pts_y, axis=1, keepdims=True)
        bbox_bottom = F.max(pts_y, axis=1, keepdims=True)
        bbox = F.concat(bbox_left, bbox_top, bbox_right, bbox_bottom, dim=1)
    elif transform == "moment":
        moment_transfer = kwargs.get("moment_transfer", None)
        if moment_transfer is None:
            raise ValueError("Variable moment_transfer is needed for moment transfrom.")
        pts_y_mean = F.mean(pts_y, axis=1, keepdims=True)
        pts_x_mean = F.mean(pts_x, axis=1, keepdims=True)
        pts_y_std = F.sqrt(
            F.mean(F.square(F.broadcast_sub(pts_y, pts_y_mean)), axis=1, keepdims=True)
        )
        pts_x_std = F.sqrt(
            F.mean(F.square(F.broadcast_sub(pts_x, pts_x_mean)), axis=1, keepdims=True)
        )
        moment_width_transfer, moment_height_transfer = F.split(
            moment_transfer, num_outputs=2, axis=0, squeeze_axis=False
        )
        half_width = F.broadcast_mul(pts_x_std, F.exp(moment_width_transfer))
        half_height = F.broadcast_mul(pts_y_std, F.exp(moment_height_transfer))
        bbox = F.concat(
            pts_x_mean - half_width, pts_y_mean - half_height,
            pts_x_mean + half_width, pts_y_mean + half_height,
            dim=1
        )
    else:
        raise NotImplementedError("Transform {} is not implemented.".format(transform))

    return bbox