Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add SE3.transform_from and SE3.transform_to #80

Merged
merged 23 commits into from
Feb 10, 2022
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7fa60c5
add SE3 defintions
fantaosha Feb 1, 2022
67e77b4
add initialization method
fantaosha Feb 1, 2022
e72ab40
modify test_so3.check_SO3_to_quaternion to handle cases near pi
fantaosha Feb 2, 2022
fe05db4
add SE3.hat and SE.vee
fantaosha Feb 2, 2022
1ae2dea
add SE3.adjoint
fantaosha Feb 2, 2022
f8cf872
add SE3.adjoint, vee and hat
fantaosha Feb 2, 2022
e5de005
backup before switching to taoshaf.add_SE3
fantaosha Feb 2, 2022
23292d4
add support for single x_y_z_quaternion
fantaosha Feb 2, 2022
b4c1738
modify SO3
fantaosha Feb 2, 2022
ae9e845
Remove repeated if in SE3 construction
fantaosha Feb 2, 2022
19d787d
SE3.exp added but not tested
fantaosha Feb 2, 2022
8a6f88e
add SE3.log_map()
fantaosha Feb 2, 2022
87c5f82
SE3.exp_map() and SE3.log_map() are tested
fantaosha Feb 2, 2022
2c1b729
add SE3.compose()
fantaosha Feb 2, 2022
107c55e
simplify test_se3.py
fantaosha Feb 2, 2022
2486e54
Merge branch 'taoshaf.add_se3.exp_and_log' into taoshaf.add_se3_compose
fantaosha Feb 2, 2022
3a65b2e
modify test_se3.py
fantaosha Feb 3, 2022
0548508
add SE3.transform_from and SE3.transform_to
fantaosha Feb 3, 2022
19419f8
add SE3.transform_from and SE3.transform_to
fantaosha Feb 3, 2022
e4abe1b
change err_msgs for SO3._rotate_shape_check and SE3._rotate_shape_check
fantaosha Feb 10, 2022
6c71afc
change error message for SO3._rotate_shape_check and SE3._transform_s…
fantaosha Feb 10, 2022
01db55e
update err_msg for shape_check
fantaosha Feb 10, 2022
95c9b41
Merge branch 'main' into taoshaf.add_SE3.transfrom
fantaosha Feb 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
SE3.exp_map() and SE3.log_map() are tested
  • Loading branch information
fantaosha committed Feb 2, 2022
commit 87c5f8269bb6c2ac13cab527318f0db1f6ecac1c
114 changes: 109 additions & 5 deletions theseus/geometry/tests/test_se3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,124 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import numpy as np
import pytest # noqa: F401
import torch

import theseus as th
from theseus.constants import EPS

from .common import check_adjoint
from .common import check_adjoint, check_exp_map


def _create_random_se3(batch_size, rng):
x_y_z_quaternion = torch.rand(batch_size, 7, generator=rng).double() - 0.5
quaternion_norm = torch.linalg.norm(x_y_z_quaternion[:, 3:], dim=1, keepdim=True)
x_y_z_quaternion[:, 3:] /= quaternion_norm
tangent_vector_ang = torch.rand(batch_size, 3) - 0.5
tangent_vector_ang /= tangent_vector_ang.norm(dim=1, keepdim=True)
tangent_vector_ang *= torch.rand(batch_size, 1) * 2 * np.pi - np.pi
tangent_vector_lin = torch.randn(batch_size, 3)
tangent_vector = torch.cat([tangent_vector_lin, tangent_vector_ang], dim=1)
return th.SE3.exp_map(tangent_vector.double())

return th.SE3(x_y_z_quaternion=x_y_z_quaternion)

def check_SE3_log_map(tangent_vector, atol=EPS):
g = th.SE3.exp_map(tangent_vector)
err = (th.SE3.exp_map(g.log_map()).data - g.data).abs().max().item()
print(err)
assert torch.allclose(th.SE3.exp_map(g.log_map()).data, g.data, atol=atol)


def test_exp_map():
for batch_size in [1, 20, 100]:
tangent_vector_ang = torch.rand(batch_size, 3).double() - 0.5
tangent_vector_ang /= tangent_vector_ang.norm(dim=1, keepdim=True)
tangent_vector_ang *= torch.rand(batch_size, 1).double() * 2 * np.pi - np.pi
tangent_vector_lin = torch.randn(batch_size, 3).double()
tangent_vector = torch.cat([tangent_vector_lin, tangent_vector_ang], dim=1)

check_exp_map(tangent_vector, th.SE3)

for batch_size in [1, 20, 100]:
tangent_vector_ang = torch.rand(batch_size, 3).double() - 0.5
tangent_vector_ang /= tangent_vector_ang.norm(dim=1, keepdim=True)
tangent_vector_ang *= 1e-5
tangent_vector_lin = torch.randn(batch_size, 3).double()
tangent_vector = torch.cat([tangent_vector_lin, tangent_vector_ang], dim=1)

check_exp_map(tangent_vector, th.SE3)

for batch_size in [1, 20, 100]:
tangent_vector_ang = torch.rand(batch_size, 3).double() - 0.5
tangent_vector_ang /= tangent_vector_ang.norm(dim=1, keepdim=True)
tangent_vector_ang *= 3e-3
tangent_vector_lin = torch.randn(batch_size, 3).double()
tangent_vector = torch.cat([tangent_vector_lin, tangent_vector_ang], dim=1)

check_exp_map(tangent_vector, th.SE3)

for batch_size in [1, 20, 100]:
tangent_vector_ang = torch.rand(batch_size, 3).double() - 0.5
tangent_vector_ang /= tangent_vector_ang.norm(dim=1, keepdim=True)
tangent_vector_ang *= 2 * np.pi - 1e-11
tangent_vector_lin = torch.randn(batch_size, 3).double()
tangent_vector = torch.cat([tangent_vector_lin, tangent_vector_ang], dim=1)

check_exp_map(tangent_vector, th.SE3)

for batch_size in [1, 20, 100]:
tangent_vector_ang = torch.rand(batch_size, 3).double() - 0.5
tangent_vector_ang /= tangent_vector_ang.norm(dim=1, keepdim=True)
tangent_vector_ang *= np.pi - 1e-11
tangent_vector_lin = torch.randn(batch_size, 3).double()
tangent_vector = torch.cat([tangent_vector_lin, tangent_vector_ang], dim=1)

check_exp_map(tangent_vector, th.SE3)


def test_log_map():
for batch_size in [1, 20, 100]:
tangent_vector_ang = torch.rand(batch_size, 3) - 0.5
tangent_vector_ang /= tangent_vector_ang.norm(dim=1, keepdim=True)
tangent_vector_ang *= torch.rand(batch_size, 1).double() * 2 * np.pi - np.pi
tangent_vector_lin = torch.randn(batch_size, 3).double()
tangent_vector = torch.cat([tangent_vector_lin, tangent_vector_ang], dim=1)

check_SE3_log_map(tangent_vector)

for batch_size in [1, 20, 100]:
tangent_vector_ang = torch.rand(batch_size, 3).double() - 0.5
tangent_vector_ang /= tangent_vector_ang.norm(dim=1, keepdim=True)
tangent_vector_ang *= 1e-5
tangent_vector_lin = torch.randn(batch_size, 3).double()
tangent_vector = torch.cat([tangent_vector_lin, tangent_vector_ang], dim=1)

check_SE3_log_map(tangent_vector)

for batch_size in [1, 20, 100]:
tangent_vector_ang = torch.rand(batch_size, 3).double() - 0.5
tangent_vector_ang /= tangent_vector_ang.norm(dim=1, keepdim=True)
tangent_vector_ang *= 3e-3
tangent_vector_lin = torch.randn(batch_size, 3).double()
tangent_vector = torch.cat([tangent_vector_lin, tangent_vector_ang], dim=1)

check_SE3_log_map(tangent_vector)

for batch_size in [1, 20, 100]:
tangent_vector_ang = torch.rand(batch_size, 3).double() - 0.5
tangent_vector_ang /= tangent_vector_ang.norm(dim=1, keepdim=True)
tangent_vector_ang *= 2 * np.pi - 1e-11
tangent_vector_lin = torch.randn(batch_size, 3).double()
tangent_vector = torch.cat([tangent_vector_lin, tangent_vector_ang], dim=1)

check_SE3_log_map(tangent_vector)

for batch_size in [1, 20, 100]:
tangent_vector_ang = torch.rand(batch_size, 3).double() - 0.5
tangent_vector_ang /= tangent_vector_ang.norm(dim=1, keepdim=True)
tangent_vector_ang *= np.pi - 1e-11
tangent_vector_lin = torch.randn(batch_size, 3).double()
tangent_vector = torch.cat([tangent_vector_lin, tangent_vector_ang], dim=1)

check_SE3_log_map(tangent_vector)


def test_adjoint():
Expand Down