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

Class TestFindNeighborPointsOfRays

tests/pointersect/pr/cpp/test_cpp.py:264–434  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

262
263
264class TestFindNeighborPointsOfRays(unittest.TestCase):
265 def _test(
266 self,
267 points: torch.Tensor, # (b, n, 3)
268 ray_origins: torch.Tensor, # (b, m, 3)
269 ray_directions: torch.Tensor, # (b, m, 3)
270 ray_radius: T.Union[torch.Tensor, float], # (b,)
271 grid_size: T.Union[torch.Tensor, int], # (b, 3)
272 grid_center: T.Union[torch.Tensor, float, None] = 0., # (b, 3)
273 grid_width: T.Union[torch.Tensor, float, None] = 1., # (b, 3)
274 ):
275 batch_size, n_rays, _ = ray_origins.shape
276
277 if isinstance(grid_center, float):
278 grid_center = torch.tensor(grid_center, dtype=points.dtype, device=points.device)
279 grid_center = grid_center.view(1, 1).expand(batch_size, 3) # (b, 3)
280 if isinstance(grid_width, (float, int)):
281 grid_width = torch.tensor(grid_width, dtype=points.dtype, device=points.device)
282 grid_width = grid_width.view(1, 1).expand(batch_size, 3) # (b, 3)
283 if isinstance(grid_size, (float, int)):
284 grid_size = torch.tensor(grid_size, dtype=torch.long, device=points.device)
285 grid_size = grid_size.view(1, 1).expand(batch_size, 3) # (b, 3)
286 grid_size = grid_size.long() # (b, 3)
287
288
289 # stime = timer()
290 # all_ray2pidxs_python = naive.find_neighbor_points_of_rays(
291 # points=points,
292 # ray_origins=ray_origins,
293 # ray_directions=ray_directions,
294 # ray_radius=ray_radius,
295 # grid_size=grid_size,
296 # grid_center=grid_center,
297 # grid_width=grid_width,
298 # # include_outside=include_outside,
299 # )
300 # total_time_python = timer() - stime
301
302 stime = timer()
303 all_ray2pidxs_gt = naive.find_neighbor_points_of_rays_brute_force(
304 points=points,
305 ray_origins=ray_origins,
306 ray_directions=ray_directions,
307 ray_radius=ray_radius,
308 grid_size=grid_size,
309 grid_center=grid_center,
310 grid_width=grid_width,
311 # include_outside=include_outside,
312 )
313 total_time_brute_force = timer() - stime
314 # print(f'python/gt = {total_time_python:1f}/{total_time_brute_force:1f} = {total_time_python/total_time_brute_force*100:.3f}%')
315
316 # stime = timer()
317 # all_ray2pidxs = pr_cpp.find_neighbor_points_of_rays(
318 # points,
319 # ray_origins,
320 # ray_directions,
321 # ray_radius,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected