def test_cross(self): """ For a pair of randomly generated 3-dimensional vectors `a` and `b`, tests whether a matrix product of `hat(a)` and `b` equals the result of a cross product between `a` and `b`. """ device = torch.device("cuda:0") a, b = torch.randn((2, 100, 3), dtype=torch.float32, device=device) hat_a = hat(a) cross = torch.bmm(hat_a, b[:, :, None])[:, :, 0] torch_cross = torch.cross(a, b, dim=1) self.assertClose(torch_cross, cross, atol=1e-4)
def test_cross(self): """ For a pair of randomly generated 3-dimensional vectors `a` and `b`, tests whether a matrix product of `hat(a)` and `b` equals the result of a cross product between `a` and `b`. """ device = torch.device("cuda:0") a, b = torch.randn((2, 100, 3), dtype=torch.float32, device=device) hat_a = hat(a) cross = torch.bmm(hat_a, b[:, :, None])[:, :, 0] torch_cross = torch.cross(a, b, dim=1) max_df = (cross - torch_cross).abs().max() self.assertAlmostEqual(float(max_df), 0.0, 5)