Пример #1
0
def test_perturb():
    C = SO2.exp(torch.Tensor([np.pi / 4]))
    C_copy = copy.deepcopy(C)
    phi = torch.Tensor([0.1])
    C.perturb(phi)
    assert utils.allclose(
        C.as_matrix(), (SO2.exp(phi).dot(C_copy)).as_matrix())
Пример #2
0
def test_perturb_batch():
    C = SO2.exp(torch.Tensor([-1., 0., 1.]))
    C_copy1 = copy.deepcopy(C)
    C_copy2 = copy.deepcopy(C)

    phi = torch.Tensor([0.1])
    C_copy1.perturb(phi)
    assert utils.allclose(C_copy1.as_matrix(),
                          (SO2.exp(phi).dot(C)).as_matrix())

    phis = torch.Tensor([0.1, 0.2, 0.3])
    C_copy2.perturb(phis)
    assert utils.allclose(C_copy2.as_matrix(),
                          (SO2.exp(phis).dot(C)).as_matrix())
Пример #3
0
def test_exp_log():
    C_big = SO2.exp(torch.Tensor([np.pi / 4]))

    torch.testing.assert_close(torch.tensor([
        [0.7071, -0.7071],
        [0.7071, 0.7071],
    ]),
                               C_big.mat,
                               rtol=1e-5,
                               atol=1e-3)

    C_small = SO2.exp(torch.Tensor([0]))
    torch.testing.assert_close(torch.tensor([
        [1, -0],
        [0, 1],
    ],
                                            dtype=torch.float32),
                               C_small.mat,
                               rtol=1e-5,
                               atol=1e-3)
Пример #4
0
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()
Пример #5
0
def test_adjoint_batch():
    C = SO2.exp(torch.Tensor([-1., 0., 1.]))
    assert (C.adjoint() == torch.ones(C.mat.shape[0])).all()
Пример #6
0
def test_adjoint():
    C = SO2.exp(torch.Tensor([np.pi / 4]))
    assert (C.adjoint() == torch.Tensor([1.])).all()
Пример #7
0
def test_inv_batch():
    C = SO2.exp(torch.Tensor([-1., 0., 1.]))
    assert utils.allclose(C.dot(C.inv()).mat, SO2.identity(C.mat.shape[0]).mat)
Пример #8
0
def test_inv():
    C = SO2.exp(torch.Tensor([np.pi / 4]))
    assert utils.allclose(C.dot(C.inv()).mat, SO2.identity().mat)
Пример #9
0
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()
Пример #10
0
def test_exp_log_batch():
    C = SO2.exp(torch.Tensor([-1., 0., 1.]))
    assert utils.allclose(SO2.exp(SO2.log(C)).mat, C.mat)
Пример #11
0
def test_exp_log():
    C_big = SO2.exp(torch.Tensor([np.pi / 4]))
    assert utils.allclose(SO2.exp(SO2.log(C_big)).mat, C_big.mat)

    C_small = SO2.exp(torch.Tensor([0]))
    assert utils.allclose(SO2.exp(SO2.log(C_small)).mat, C_small.mat)