Skip to content

Commit eed3031

Browse files
committed
Add unit test for original bug
Signed-off-by: reworld223 <[email protected]>
1 parent e2a4549 commit eed3031

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

tests/data/test_box_utils.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,23 +223,23 @@ class TestBoxUtilsDtype(unittest.TestCase):
223223
@parameterized.expand(
224224
[
225225
# numpy dtypes
226-
(np.array([[0, 0, 0, 2, 2, 2]], dtype=np.int32), np.array([[0, 0, 0, 2, 2, 2]], dtype=np.int32)),
227-
(np.array([[0, 0, 0, 2, 2, 2]], dtype=np.float32), np.array([[0, 0, 0, 2, 2, 2]], dtype=np.float32)),
226+
(np.array([[1, 1, 1, 2, 2, 2]], dtype=np.int32), np.array([[1, 1, 1, 2, 2, 2]], dtype=np.int32)),
227+
(np.array([[1, 1, 1, 2, 2, 2]], dtype=np.float32), np.array([[1, 1, 1, 2, 2, 2]], dtype=np.float32)),
228228
# torch dtypes
229229
(
230-
torch.tensor([[0, 0, 0, 2, 2, 2]], dtype=torch.int64),
231-
torch.tensor([[0, 0, 0, 2, 2, 2]], dtype=torch.int64),
230+
torch.tensor([[1, 1, 1, 2, 2, 2]], dtype=torch.int64),
231+
torch.tensor([[1, 1, 1, 2, 2, 2]], dtype=torch.int64),
232232
),
233233
(
234-
torch.tensor([[0, 0, 0, 2, 2, 2]], dtype=torch.float32),
235-
torch.tensor([[0, 0, 0, 2, 2, 2]], dtype=torch.float32),
234+
torch.tensor([[1, 1, 1, 2, 2, 2]], dtype=torch.float32),
235+
torch.tensor([[1, 1, 1, 2, 2, 2]], dtype=torch.float32),
236236
),
237237
# mixed numpy (int + float)
238-
(np.array([[0, 0, 0, 2, 2, 2]], dtype=np.int32), np.array([[0, 0, 0, 2, 2, 2]], dtype=np.float32)),
238+
(np.array([[1, 1, 1, 2, 2, 2]], dtype=np.int32), np.array([[1, 1, 1, 2, 2, 2]], dtype=np.float32)),
239239
# mixed torch (int + float)
240240
(
241-
torch.tensor([[0, 0, 0, 2, 2, 2]], dtype=torch.int64),
242-
torch.tensor([[0, 0, 0, 2, 2, 2]], dtype=torch.float32),
241+
torch.tensor([[1, 1, 1, 2, 2, 2]], dtype=torch.int64),
242+
torch.tensor([[1, 1, 1, 2, 2, 2]], dtype=torch.float32),
243243
),
244244
]
245245
)
@@ -259,6 +259,15 @@ def test_dtype_behavior(self, boxes1, boxes2):
259259
else:
260260
self.fail(f"Unexpected return type {type(result)}")
261261

262+
def test_integer_truncation_bug(self):
263+
# Verify fix for #8553: IoU < 1.0 with integer inputs should not truncate to 0
264+
boxes1 = np.array([[0, 0, 0, 2, 2, 2]], dtype=np.int32)
265+
boxes2 = np.array([[1, 1, 1, 3, 3, 3]], dtype=np.int32)
266+
267+
iou = box_iou(boxes1, boxes2)
268+
self.assertTrue(np.issubdtype(iou.dtype, np.floating))
269+
self.assertGreater(iou[0, 0], 0.0, "IoU should not be truncated to 0")
270+
262271

263272
if __name__ == "__main__":
264273
unittest.main()

0 commit comments

Comments
 (0)