def test_from_matrix(): C_good = SO2.from_matrix(torch.eye(2)) assert isinstance(C_good, SO2) \ and C_good.mat.dim() == 2 \ and C_good.mat.shape == (2, 2) \ and SO2.is_valid_matrix(C_good.mat).all() C_bad = SO2.from_matrix(torch.eye(2).add_(1e-3), normalize=True) assert isinstance(C_bad, SO2) \ and C_bad.mat.dim() == 2 \ and C_bad.mat.shape == (2, 2) \ and SO2.is_valid_matrix(C_bad.mat).all()
def test_normalize_batch(): C = SO2.exp(torch.Tensor([-1., 0., 1.])) assert SO2.is_valid_matrix(C.mat).all() C.mat.add_(0.1) assert (SO2.is_valid_matrix(C.mat) == torch.ByteTensor([0, 0, 0])).all() C.normalize(inds=[0, 2]) assert (SO2.is_valid_matrix(C.mat) == torch.ByteTensor([1, 0, 1])).all() C.normalize() assert SO2.is_valid_matrix(C.mat).all()
def test_from_matrix_batch(): C_good = SO2.from_matrix(torch.eye(2).repeat(5, 1, 1)) assert isinstance(C_good, SO2) \ and C_good.mat.dim() == 3 \ and C_good.mat.shape == (5, 2, 2) \ and SO2.is_valid_matrix(C_good.mat).all() C_bad = copy.deepcopy(C_good.mat) C_bad[3].add_(0.1) C_bad = SO2.from_matrix(C_bad, normalize=True) assert isinstance(C_bad, SO2) \ and C_bad.mat.dim() == 3 \ and C_bad.mat.shape == (5, 2, 2) \ and SO2.is_valid_matrix(C_bad.mat).all()
def test_from_matrix(): C_good = SO2.from_matrix(torch.eye(2)) print(C_good.mat) print(SO2.is_valid_matrix(C_good.mat)) C_bad = SO2.from_matrix(torch.eye(2).add_(1e-3), normalize=True) print(isinstance(C_bad, SO2)) print(C_bad.mat)
def test_normalize(): C = SO2.exp(torch.Tensor([np.pi / 4])) C.mat.add_(0.1) C.normalize() assert SO2.is_valid_matrix(C.mat).all()