Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Remove bit length computation and use nn.functional.pad instead of concatenation with ones.

Onur Kaplanfb47d3e5c6bb
diff --git a/torchgeometry/conversions.py b/torchgeometry/conversions.py
index ea256ea2b..18882a71a 100644
--- a/torchgeometry/conversions.py
+++ b/torchgeometry/conversions.py
@@ -115,19 +115,7 @@ def convert_points_to_homogeneous(points):
raise ValueError("Input must be at least a 2D tensor. Got {}".format(
points.shape))
- if torch.is_tensor(points.shape[-1]):
- last_dim_shape = points.shape[-1].float()
- last_dim_bit_length = torch.floor(torch.log2(last_dim_shape)) + 1
- last_dim_bit_length = last_dim_bit_length.long()
- else:
- last_dim_bit_length = points.shape[-1].bit_length()
-
- # create shape for ones tensor: Nx(...)xD-1
- # new_shape = points.shape[:-1] + (int(points.shape[-1]).bit_length() - 1,)
- new_shape = points.shape[:-1] + (last_dim_bit_length - 1,)
- ones = torch.ones(new_shape, dtype=points.dtype)
- return torch.cat([points, ones.to(points.device)], dim=-1)
-
+ return nn.functional.pad(points, (0, 1), "constant", 1.0)
def transform_points(dst_pose_src, points_src):
r"""Function that applies transformations to a set of points.