(self, b=10, n=20, max_size=20)
| 111 | class TestGetGridIdx(unittest.TestCase): |
| 112 | |
| 113 | def test(self, b=10, n=20, max_size=20): |
| 114 | points = torch.randn(b, n, 3) |
| 115 | grid_size = (torch.rand(b, 3) * 9 + 1).floor().long() |
| 116 | grid_center = torch.randn(b, 3) |
| 117 | grid_width = torch.rand(b, 3) * 2 + 0.1 |
| 118 | |
| 119 | stime = timer() |
| 120 | grid_idxs_gt, valid_mask_gt = naive.get_grid_idx( |
| 121 | points=points, |
| 122 | grid_size=grid_size, |
| 123 | center=grid_center, |
| 124 | grid_width=grid_width, |
| 125 | mode='ind', |
| 126 | ) |
| 127 | time_python = timer() - stime |
| 128 | |
| 129 | stime = timer() |
| 130 | grid_idxs, valid_mask = pr_cpp.get_grid_idx( |
| 131 | points, |
| 132 | grid_size, |
| 133 | grid_center, |
| 134 | grid_width, |
| 135 | 'ind', |
| 136 | ) |
| 137 | time_cpp = timer() - stime |
| 138 | |
| 139 | print('get_grid_idx:') |
| 140 | print(f'python: {time_python * 1000.:.3f} ms') |
| 141 | print(f'cpp: {time_cpp * 1000.:.3f} ms ({time_python / time_cpp:.2f} speed up)') |
| 142 | |
| 143 | assert torch.allclose(grid_idxs_gt, grid_idxs) |
| 144 | assert torch.allclose(valid_mask_gt, valid_mask) |
| 145 | |
| 146 | |
| 147 |
nothing calls this directly
no outgoing calls
no test coverage detected