def test_diou_loss(self):
        """
        loss = 1 - iou + d/c
        where,
        d = (distance between centers of the 2 boxes)^2
        c = (diagonal length of the smallest enclosing box covering the 2 boxes)^2
        """
        # Identical boxes should have loss of 0
        box = torch.tensor([-1, -1, 1, 1], dtype=torch.float32)
        loss = diou_loss(box, box)
        self.assertTrue(np.allclose(loss, [0.0]))

        # Half size box inside other box
        # iou = 0.5, d = 0.25, c = 8
        box2 = torch.tensor([0, -1, 1, 1], dtype=torch.float32)
        loss = diou_loss(box, box2)
        self.assertTrue(np.allclose(loss, [0.53125]))

        # Two diagonally adjacent boxes
        # iou = 0, d = 2, c = 8
        box3 = torch.tensor([0, 0, 1, 1], dtype=torch.float32)
        box4 = torch.tensor([1, 1, 2, 2], dtype=torch.float32)
        loss = diou_loss(box3, box4)
        self.assertTrue(np.allclose(loss, [1.25]))

        # Test batched loss and reductions
        box1s = torch.stack([box, box3], dim=0)
        box2s = torch.stack([box2, box4], dim=0)

        loss = diou_loss(box1s, box2s, reduction="sum")
        self.assertTrue(np.allclose(loss, [1.78125]))

        loss = diou_loss(box1s, box2s, reduction="mean")
        self.assertTrue(np.allclose(loss, [0.890625]))

        loss = 1 - iou + d/c
        where,
        d = (distance between centers of the 2 boxes)^2
        c = (diagonal length of the smallest enclosing box covering the 2 boxes)^2
        
EVA-02/det/tests/layers/test_losses.py