def test_rad2deg(self): # generate input data x_rad = tgm.pi * torch.rand(2, 3, 4) # convert radians/degrees x_deg = tgm.rad2deg(x_rad) x_deg_to_rad = tgm.deg2rad(x_deg) # compute error error = utils.compute_mse(x_rad, x_deg_to_rad) self.assertAlmostEqual(error.item(), 0.0, places=4) # functional self.assertTrue(torch.allclose(x_deg, tgm.RadToDeg()(x_rad)))
def test_rad2deg(batch_shape, device_type): # generate input data x_rad = tgm.pi * torch.rand(batch_shape) x_rad = x_rad.to(torch.device(device_type)) # convert radians/degrees x_deg = tgm.rad2deg(x_rad) x_deg_to_rad = tgm.deg2rad(x_deg) # compute error error = utils.compute_mse(x_rad, x_deg_to_rad) assert pytest.approx(error.item(), 0.0) # functional assert torch.allclose(x_deg, tgm.RadToDeg()(x_rad)) # evaluate function gradient assert gradcheck(tgm.rad2deg, (utils.tensor_to_gradcheck_var(x_rad), ), raise_exception=True)