MCPcopy Create free account
hub / github.com/apple/ml-pointersect / Test_Point_Ray_Distance

Class Test_Point_Ray_Distance

tests/plib/test_utils.py:59–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57
58
59class Test_Point_Ray_Distance(unittest.TestCase):
60 def test_1(self):
61 N = 5
62 points = torch.randn(N, 3)
63 ray_origins = torch.zeros(1, 3)
64 ray_directions = torch.zeros(1, 3)
65 ray_directions[0, 2] = 1.
66
67 out_dict = utils.compute_point_ray_distance(
68 points=points,
69 ray_origins=ray_origins,
70 ray_directions=ray_directions,
71 )
72 dists = out_dict['dists']
73 projections = out_dict['projections']
74 ts = out_dict['ts']
75
76 assert dists.shape == (1, N)
77 assert projections.shape == (1, N, 3)
78 assert ts.shape == (1, N)
79 assert torch.allclose(dists, torch.linalg.norm(points[None, :, :2], dim=-1))
80 assert torch.allclose(ts.sign(), points[:, 2:3].t().sign())
81
82 projs = torch.zeros(N, 3)
83 projs[..., 2] = points[:, 2]
84 projs = projs.unsqueeze(0)
85 assert torch.allclose(projections, projs)
86
87 def test_chunk(self):
88 b_shape = [3, 5]
89 n = 10
90 m = 7
91 points = torch.randn(*b_shape, n, 3)
92 ray_origins = torch.randn(*b_shape, m, 3)
93 ray_directions = torch.zeros(*b_shape, m, 3)
94 ray_directions[..., 2] = 1.
95
96 # standard (no chunking)
97 out_dict_gt = utils.compute_point_ray_distance(
98 points=points,
99 ray_origins=ray_origins,
100 ray_directions=ray_directions,
101 )
102
103 # with chunking
104 mn = m * n
105 for max_chunk_size in [int(1e9), mn//2, mn+1]:
106 out_dict = utils.compute_point_ray_distance_in_chunks(
107 points=points,
108 ray_origins=ray_origins,
109 ray_directions=ray_directions,
110 max_chunk_size=max_chunk_size,
111 )
112 for key in out_dict_gt:
113 assert torch.allclose(out_dict_gt[key], out_dict[key]), f'{max_chunk_size}'
114
115
116

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected