Skip to content

Commit

Permalink
v1.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain BRÉGIER committed Mar 21, 2024
1 parent 1c27395 commit 69455d6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docsource/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ Bits of code were adapted from SciPy. Documentation is generated, distributed an

Changelog
==========
Version 1.4.4:
- Added :func:`~roma.utils.identity_quat()`.
Version 1.4.3:
- Fix normalization bug in :func:`~roma.utils.quat_composition()` (thanks jamiesalter for reporting).
Version 1.4.2:
Expand Down
20 changes: 19 additions & 1 deletion roma/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@ def random_rotvec(size = tuple(), dtype=torch.float, device=None):
quat = random_unitquat(size, dtype=dtype, device=device)
return roma.mappings.unitquat_to_rotvec(quat)

def identity_quat(size = tuple(), dtype=torch.float, device=None):
"""
Return a batch of identity unit quaternions.
Args:
size (tuple or int): batch size. Use for example ``tuple()`` to generate a single element, and ``(5,2)`` to generate a 5x2 batch.
Returns:
batch of identity quaternions (size x 4 tensor, XYZW convention).
Note:
All returned batch quaternions refer to the same memory location.
Consider cloning the output tensor prior performing any in-place operations.
"""
if type(size) == int:
size = (size,)
quat = torch.zeros(4, dtype=dtype, device=device)
quat[...,-1] = 1.
quat = quat.expand(list(size) + [-1])
return quat

def rotmat_cosine_angle(R):
"""
Returns the cosine angle of the input 3x3 rotation matrix R.
Expand All @@ -110,7 +129,6 @@ def rotmat_cosine_angle(R):
assert R.shape[-2:] == (3,3), "Expecting a ...x3x3 batch of rotation matrices"
return 0.5 * (R[...,0,0] + R[...,1,1] + R[...,2,2] - 1.0)


_ONE_OVER_2SQRT2 = 1.0 / (2 * np.sqrt(2))
def rotmat_geodesic_distance(R1, R2, clamping=1.0):
"""
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 @@

setuptools.setup(
name="roma",
version="1.4.3",
version="1.4.4",
author="Romain Brégier",
author_email="[email protected]",
description="A lightweight library to deal with 3D rotations in PyTorch.",
Expand Down
13 changes: 13 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ def test_other_geodesic_distance(self):
alpha_rotvec = roma.rotvec_geodesic_distance(rotvec1, rotvec2)
self.assertTrue(is_close(alpha_rotvec, alpha_q))

def test_identity_quat(self):
q = roma.identity_quat()
self.assertTrue(q.shape == (4,))
self.assertTrue(is_close(q, roma.quat_inverse(q)))

q = roma.identity_quat(5)
self.assertTrue(q.shape == (5,4))
self.assertTrue(is_close(q, roma.quat_inverse(q)))

q = roma.identity_quat((3,2))
self.assertTrue(q.shape == (3,2,4))
self.assertTrue(is_close(q, roma.quat_inverse(q)))

def test_random_unitquat(self):
q = roma.random_unitquat((3,5))
self.assertTrue(q.shape == (3,5,4))
Expand Down

0 comments on commit 69455d6

Please sign in to comment.