Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

move test_convert_points_to_homogeneous to conversions tests

edgarriba3fde893f0a22
diff --git a/.gitignore b/.gitignore
index 7392d07da..1f9f6127b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,7 @@ torchgeometry.egg-info/
*~
*.swp
*.swo
+*.swn
.eggs/*
.cache/*
.pytest_cache/*
diff --git a/test/test_conversions.py b/test/test_conversions.py
index e4dceb0e2..c9cb51739 100644
--- a/test/test_conversions.py
+++ b/test/test_conversions.py
@@ -1,4 +1,5 @@
import unittest
+import pytest
import numpy as np
import torch
@@ -7,6 +8,31 @@ from torch.autograd import gradcheck
import utils # test utils
from utils import check_equal_torch, check_equal_numpy
+from common import TEST_DEVICES
+
+
[email protected]("device_type", TEST_DEVICES)
[email protected]("batch_shape", [
+ (2, 3), (1, 2, 3), (2, 3, 3), (5, 5, 3),])
+def test_convert_points_to_homogeneous(batch_shape, device_type):
+ # generate input data
+ points = torch.rand(batch_shape)
+ points = points.to(torch.device(device_type))
+
+ # to homogeneous
+ points_h = tgm.convert_points_to_homogeneous(points)
+
+ assert points_h.shape[-2] == batch_shape[-2]
+ assert (points_h[..., -1] == torch.ones(points_h[..., -1].shape)).all()
+
+ # functional
+ assert torch.allclose(points_h, tgm.ConvertPointsToHomogeneous()(points))
+
+ # evaluate function gradient
+ points = utils.tensor_to_gradcheck_var(points) # to var
+ assert gradcheck(tgm.convert_points_to_homogeneous, (points,),
+ raise_exception=True)
+
class Tester(unittest.TestCase):
diff --git a/test/test_functional.py b/test/test_functional.py
index 198883567..2bd77a0ff 100644
--- a/test/test_functional.py
+++ b/test/test_functional.py
@@ -6,40 +6,6 @@ import torchgeometry as tgm
from torch.autograd import gradcheck
import utils # test utilities
-from common import TEST_DEVICES
-
-
[email protected]("device_type", TEST_DEVICES)
[email protected]("batch_shape", [
- (2, 3), (1, 2, 3), (2, 3, 3), (5, 5, 3),])
-def test_convert_points_to_homogeneous(batch_shape, device_type):
- # generate input data
- points = torch.rand(batch_shape)
- points = points.to(torch.device(device_type))
-
- # to homogeneous
- points_h = tgm.convert_points_to_homogeneous(points)
-
- assert points_h.shape[-2] == batch_shape[-2]
- assert (points_h[..., -1] == torch.ones(points_h[..., -1].shape)).all()
-
- # functional
- assert torch.allclose(points_h, tgm.ConvertPointsToHomogeneous()(points))
-
-
[email protected]("expand", [True, False])
[email protected]("batch_size", [1, 2, 5])
-def test_convert_points_to_homogeneous_gradcheck(batch_size, expand):
- # generate input data
- points = torch.rand(2, 3)
- if expand:
- points = torch.rand(batch_size, 2, 3)
- points = utils.tensor_to_gradcheck_var(points) # to var
-
- # evaluate function gradient
- assert gradcheck(tgm.convert_points_to_homogeneous, (points,),
- raise_exception=True)
-
@pytest.mark.parametrize("expand", [True, False])
@pytest.mark.parametrize("batch_size", [1, 2, 5])