Skip to content

Commit

Permalink
Add .from_translation() for SE(2), SE(3) classes, bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed May 6, 2024
1 parent b41953b commit 5189178
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
12 changes: 11 additions & 1 deletion jaxlie/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import jax
import numpy as onp
from jax import numpy as jnp
from typing_extensions import Self, final, override
from typing_extensions import Self, final, get_args, override

from . import hints

Expand Down Expand Up @@ -238,6 +238,16 @@ def from_rotation(cls, rotation: ContainedSOType) -> Self:
),
)

@final
@classmethod
def from_translation(cls, translation: hints.Array) -> Self:
# Extract rotation class from type parameter.
assert len(cls.__orig_bases__) == 1 # type: ignore
return cls.from_rotation_and_translation(
rotation=get_args(cls.__orig_bases__[0])[0].identity(), # type: ignore
translation=translation,
)

@abc.abstractmethod
def rotation(self) -> ContainedSOType:
"""Returns a transform's rotation term."""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="jaxlie",
version="1.4.0",
version="1.4.1",
description="Matrix Lie groups in JAX",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
16 changes: 14 additions & 2 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Tests with explicit examples."""

import jaxlie
import numpy as onp
from hypothesis import given, settings
from hypothesis import strategies as st
from utils import assert_arrays_close, assert_transforms_close, sample_transform

import jaxlie
from utils import assert_arrays_close, assert_transforms_close, sample_transform


@settings(deadline=None)
Expand Down Expand Up @@ -54,6 +54,18 @@ def test_se3_rotation():
assert_arrays_close(T_w_b @ p_b, T_w_b_alt @ p_b, p_w)


def test_se3_from_translation():
"""Simple test for SE(3) rotation terms."""
T_w_b = jaxlie.SE3.from_rotation_and_translation(
rotation=jaxlie.SO3.identity(),
translation=onp.arange(3) * 1.0,
)
T_w_b_alt = jaxlie.SE3.from_translation(onp.arange(3) * 1.0)
p_b = onp.array([0.0, 1.0, 0.0])
p_w = onp.array([0.0, 2.0, 2.0])
assert_arrays_close(T_w_b @ p_b, T_w_b_alt @ p_b, p_w)


def test_so3_xyzw_basic():
"""Check that we can create an SO3 object from an xyzw quaternion."""
assert_transforms_close(
Expand Down

0 comments on commit 5189178

Please sign in to comment.