Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

optimized mod function by using inbuilt torch.remainder by 336% (#3224)

Sidd0798eca3b431
diff --git a/kornia/contrib/models/rt_detr/post_processor.py b/kornia/contrib/models/rt_detr/post_processor.py
index be6532181..629373a4c 100644
--- a/kornia/contrib/models/rt_detr/post_processor.py
+++ b/kornia/contrib/models/rt_detr/post_processor.py
@@ -45,7 +45,9 @@ def mod(a: Tensor, b: int) -> Tensor:
1
"""
- return a - (a // b) * b
+ if not a.dtype.is_floating_point and a.dtype != torch.long:
+ a = a.to(torch.long)
+ return torch.remainder(a, b)
# TODO: deprecate the confidence threshold and add the num_top_queries as a parameter and num_classes as a parameter