(test_data)
| 90 | |
| 91 | @pytest.mark.skipif(not torch.cuda.is_available(), reason="No CUDA device") |
| 92 | def test_world_to_cam(test_data): |
| 93 | from gsplat.cuda._torch_impl import _world_to_cam |
| 94 | from gsplat.cuda._wrapper import quat_scale_to_covar_preci, world_to_cam |
| 95 | |
| 96 | torch.manual_seed(42) |
| 97 | |
| 98 | viewmats = test_data["viewmats"] |
| 99 | means = test_data["means"] |
| 100 | scales = test_data["scales"] |
| 101 | quats = test_data["quats"] |
| 102 | covars, _ = quat_scale_to_covar_preci(quats, scales) |
| 103 | means.requires_grad = True |
| 104 | covars.requires_grad = True |
| 105 | viewmats.requires_grad = True |
| 106 | |
| 107 | # forward |
| 108 | means_c, covars_c = world_to_cam(means, covars, viewmats) |
| 109 | _means_c, _covars_c = _world_to_cam(means, covars, viewmats) |
| 110 | torch.testing.assert_close(means_c, _means_c) |
| 111 | torch.testing.assert_close(covars_c, _covars_c) |
| 112 | |
| 113 | # backward |
| 114 | v_means_c = torch.randn_like(means_c) |
| 115 | v_covars_c = torch.randn_like(covars_c) |
| 116 | v_means, v_covars, v_viewmats = torch.autograd.grad( |
| 117 | (means_c * v_means_c).sum() + (covars_c * v_covars_c).sum(), |
| 118 | (means, covars, viewmats), |
| 119 | ) |
| 120 | _v_means, _v_covars, _v_viewmats = torch.autograd.grad( |
| 121 | (_means_c * v_means_c).sum() + (_covars_c * v_covars_c).sum(), |
| 122 | (means, covars, viewmats), |
| 123 | ) |
| 124 | torch.testing.assert_close(v_means, _v_means) |
| 125 | torch.testing.assert_close(v_covars, _v_covars) |
| 126 | torch.testing.assert_close(v_viewmats, _v_viewmats, rtol=1e-3, atol=1e-3) |
| 127 | |
| 128 | |
| 129 | @pytest.mark.skipif(not torch.cuda.is_available(), reason="No CUDA device") |
nothing calls this directly
no test coverage detected