Matrix Lie groups in Jax
Project description
jaxlie
[ API reference ] [ PyPI ]
jaxlie
is a library containing implementations of Lie groups commonly used for
rigid body transformations, targeted at computer vision & robotics
applications written in JAX. Heavily inspired by the C++ library
Sophus.
We implement Lie groups as high-level (data)classes:
Group | Description | Parameterization |
---|---|---|
jaxlie.SO2 |
Rotations in 2D. | (real, imaginary): unit complex (∈ S2) |
jaxlie.SE2 |
Proper rigid transforms in 2D. | (real, imaginary, x, y): unit complex & translation |
jaxlie.SO3 |
Rotations in 3D. | (qw, qx, qy, qz): wxyz quaternion (∈ S4) |
jaxlie.SE3 |
Proper rigid transforms in 3D. | (qw, qx, qy, qz, x, y, z): wxyz quaternion & translation |
Where each group supports:
- Forward- and reverse-mode AD-friendly
exp()
,log()
,adjoint()
,apply()
,multiply()
,inverse()
,identity()
,from_matrix()
, andas_matrix()
operations. - Helpers + analytical Jacobians for manifold optimization
(
jaxlie.manifold
). - (Un)flattening as pytree nodes.
- Serialization using flax.
- Compatibility with standard JAX function transformations. (we've included some
examples for use with
jax.vmap
)
We also implement various common utilities for things like uniform random
sampling (sample_uniform()
) and converting from/to Euler angles (in the
SO3
class).
Install (Python >=3.7)
# Python 3.6 releases also exist, but are no longer being updated.
pip install jaxlie
Example usage for SE(3)
import numpy as onp
from jaxlie import SE3
#############################
# (1) Constructing transforms.
#############################
# We can compute a w<-b transform by integrating over an se(3) screw, equivalent
# to `SE3.from_matrix(expm(wedge(twist)))`.
twist = onp.array([1.0, 0.0, 0.2, 0.0, 0.5, 0.0])
T_w_b = SE3.exp(twist)
# We can print the (quaternion) rotation term; this is an `SO3` object:
print(T_w_b.rotation())
# Or print the translation; this is a simple array with shape (3,):
print(T_w_b.translation())
# Or the underlying parameters; this is a length-7 (quaternion, translation) array:
print(T_w_b.wxyz_xyz) # SE3-specific field.
print(T_w_b.parameters()) # Helper shared by all groups.
# There are also other helpers to generate transforms, eg from matrices:
T_w_b = SE3.from_matrix(T_w_b.as_matrix())
# Or from explicit rotation and translation terms:
T_w_b = SE3.from_rotation_and_translation(
rotation=T_w_b.rotation(),
translation=T_w_b.translation(),
)
# Or with the dataclass constructor + the underlying length-7 parameterization:
T_w_b = SE3(wxyz_xyz=T_w_b.wxyz_xyz)
#############################
# (2) Applying transforms.
#############################
# Transform points with the `@` operator:
p_b = onp.random.randn(3)
p_w = T_w_b @ p_b
print(p_w)
# or `.apply()`:
p_w = T_w_b.apply(p_b)
print(p_w)
# or the homogeneous matrix form:
p_w = (T_w_b.as_matrix() @ onp.append(p_b, 1.0))[:-1]
print(p_w)
#############################
# (3) Composing transforms.
#############################
# Compose transforms with the `@` operator:
T_b_a = SE3.identity()
T_w_a = T_w_b @ T_b_a
print(T_w_a)
# or `.multiply()`:
T_w_a = T_w_b.multiply(T_b_a)
print(T_w_a)
#############################
# (4) Misc.
#############################
# Compute inverses:
T_b_w = T_w_b.inverse()
identity = T_w_b @ T_b_w
print(identity)
# Compute adjoints:
adjoint_T_w_b = T_w_b.adjoint()
print(adjoint_T_w_b)
# Recover our twist, equivalent to `vee(logm(T_w_b.as_matrix()))`:
twist_recovered = T_w_b.log()
print(twist_recovered)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jaxlie-1.2.9.tar.gz
(14.8 kB
view details)
Built Distribution
jaxlie-1.2.9-py3-none-any.whl
(17.9 kB
view details)
File details
Details for the file jaxlie-1.2.9.tar.gz
.
File metadata
- Download URL: jaxlie-1.2.9.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3396d2115cd5e043af871e791100c1674868a5c8549415357bb934e08f43a6f |
|
MD5 | ef1d660fa59ecfafaf79d5117427ff4e |
|
BLAKE2b-256 | 7fe6629e761f4201cb483a9d818f5b2b7a12c107c45265ac8aec0c9a171fdafc |
File details
Details for the file jaxlie-1.2.9-py3-none-any.whl
.
File metadata
- Download URL: jaxlie-1.2.9-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5424cd20ab61cd8f8cc885d10981e6d22e9b256354d693191b97021b61af5401 |
|
MD5 | f38048b451c589b3beeb668ca6849249 |
|
BLAKE2b-256 | a031f2aef7d3e35f62e820ad9ecfd7574583662aae8a1ce5da9a5cc89a58c349 |