(self, b=10, n=20, max_size=20)
| 39 | |
| 40 | |
| 41 | def test_ind2sub(self, b=10, n=20, max_size=20): |
| 42 | size = torch.randint(max_size-1, size=[b, 3]) + 1 # (b, 3) |
| 43 | total_cells = torch.prod(size, dim=-1) # (b,) |
| 44 | ind = (torch.rand(b, n) * total_cells.unsqueeze(-1)).floor().long() |
| 45 | |
| 46 | # python |
| 47 | stime = timer() |
| 48 | out_gt = naive.ind2sub(ind, size) |
| 49 | time_python = timer() - stime |
| 50 | |
| 51 | # cpp |
| 52 | stime = timer() |
| 53 | out_cpp = pr_cpp.ind2sub(ind, size) |
| 54 | time_cpp = timer() - stime |
| 55 | |
| 56 | print('ind2sub') |
| 57 | print(f'python: {time_python * 1000.:.3f} ms') |
| 58 | print(f'cpp: {time_cpp * 1000.:.3f} ms ({time_python/time_cpp:.2f} speed up)') |
| 59 | |
| 60 | assert torch.allclose(out_gt, out_cpp) |
| 61 | |
| 62 | |
| 63 | class TestGatherPoints(unittest.TestCase): |
nothing calls this directly
no outgoing calls
no test coverage detected