import torch


def torch_generate_spatial_feature(bounding_box, W, H):
    """
    This function generate spatial features.
    :param bounding_box: set of bounding boxes in format [xmin, ymin, xmax, ymax]
    :param W: images width.
    :param H: images height.
    :return: set of spatial features.
    """
    res_1 = bounding_box[:, 0] / W
    res_2 = bounding_box[:, 1] / H
    res_3 = bounding_box[:, 2] / W
    res_4 = bounding_box[:, 3] / H
    width = torch.clamp(bounding_box[:, 2] - bounding_box[:, 0], min=0)
    heigth = torch.clamp(bounding_box[:, 3] - bounding_box[:, 1], min=0)
    res_5 = (width * heigth) / (W * H)

    results = torch.cat([res_1, res_2, res_3, res_4, res_5], dim=-1)
    return results