Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
result,
expected))
tait_bryan_angles = gs.array([0., angle, 0.])
matrix = self.group.matrix_from_tait_bryan_angles(
tait_bryan_angles,
extrinsic_or_intrinsic=extrinsic_or_intrinsic,
order=order)
result = self.group.tait_bryan_angles_from_matrix(
matrix,
extrinsic_or_intrinsic=extrinsic_or_intrinsic,
order=order)
expected = tait_bryan_angles
self.assertTrue(gs.allclose(result, expected),
' for tait-bryan angles = {}'
' result = \n{};'
' expected = \n{}.'.format(
tait_bryan_angles,
result,
expected))
tait_bryan_angles = gs.array([0., 0., angle])
matrix = self.group.matrix_from_tait_bryan_angles(
tait_bryan_angles,
extrinsic_or_intrinsic=extrinsic_or_intrinsic,
order=order)
result = self.group.tait_bryan_angles_from_matrix(
matrix,
extrinsic_or_intrinsic=extrinsic_or_intrinsic,
order=order)
Tait-Bryan angles[0, 0, 0] is [1, 0., 0., 0.] as expected.
"""
n = 3
group = self.so[n]
order = 'zyx'
extrinsic_or_intrinsic = 'intrinsic'
tait_bryan_angles = gs.array([0., 0., 0.])
result = group.matrix_from_tait_bryan_angles(
tait_bryan_angles,
extrinsic_or_intrinsic=extrinsic_or_intrinsic,
order=order)
expected = gs.eye(n)
self.assertTrue(gs.allclose(result, expected),
' result = \n{};'
' expected = \n{}.'.format(
result,
expected))
expected = gs.array([0., angle, 0.])
self.assertTrue(gs.allclose(result, expected),
' result = {};'
' expected = {}.'.format(
result,
expected))
quaternion = gs.array([cos_half_angle, 0., 0., sin_half_angle])
result = self.group.tait_bryan_angles_from_quaternion(
quaternion,
extrinsic_or_intrinsic=extrinsic_or_intrinsic,
order=order)
expected = gs.array([angle, 0., 0.])
self.assertTrue(gs.allclose(result, expected),
' result = {};'
' expected = {}.'.format(
result,
expected))
if point_type == 'vector':
self.assertTrue(
gs.allclose(
result.shape, (n_samples, group.dimension)))
if point_type == 'matrix':
self.assertTrue(
gs.allclose(
result.shape, (n_samples, n, n)))
expected = gs.zeros_like(rot_vecs)
for i in range(n_samples):
expected[i] = group.regularize(rot_vecs[i])
self.assertTrue(gs.allclose(expected, result))
angle_types = self.angles_close_to_pi[3]
for metric_type in self.metrics[3]:
for angle_type in angle_types:
metric = self.metrics[3][metric_type]
tangent_vec = self.elements[3][angle_type]
result = helper.exp_then_log_from_identity(metric, tangent_vec)
expected = group.regularize_tangent_vec_at_identity(
tangent_vec=tangent_vec,
metric=metric)
inv_expected = - expected
self.assertTrue(gs.allclose(result, expected)
or gs.allclose(result, inv_expected),
'\nmetric {}\n'
'- on tangent_vec {}: {}\n'
'result = {}\n'
'expected = {}'.format(
metric_type,
angle_type,
tangent_vec,
result,
expected))
one_point = group.random_uniform(n_samples=1)
one_base_point = group.random_uniform(n_samples=1)
n_point = group.random_uniform(n_samples=n_samples)
n_base_point = group.random_uniform(n_samples=n_samples)
# Test with the 1 base point, and several different points
result = metric.log(n_point, one_base_point)
self.assertTrue(gs.allclose(result.shape,
(n_samples, group.dimension)))
expected = gs.vstack([metric.log(point, one_base_point)
for point in n_point])
self.assertTrue(gs.allclose(expected.shape,
(n_samples, group.dimension)))
self.assertTrue(gs.allclose(result, expected),
'with metric {}'.format(metric_type))
# Test with the several base point, and 1 point
result = metric.log(one_point, n_base_point)
self.assertTrue(gs.allclose(result.shape,
(n_samples, group.dimension)))
expected = gs.vstack([metric.log(one_point, base_point)
for base_point in n_base_point])
self.assertTrue(gs.allclose(expected.shape,
(n_samples, group.dimension)))
self.assertTrue(gs.allclose(result, expected),
'with metric {}'.format(metric_type))
# Test with the same number n of base point and point
result = metric.log(n_point, n_base_point)
result = metric.dist(n_point_1, one_point_2)
gs.testing.assert_allclose(result.shape, (n_samples, 1))
expected = gs.vstack([metric.dist(point_1, one_point_2)
for point_1 in n_point_1])
self.assertTrue(gs.allclose(result, expected),
'with metric {}'.format(metric_type))
# n points 1 and n points 2
result = metric.dist(n_point_1, n_point_2)
gs.testing.assert_allclose(result.shape, (n_samples, 1))
expected = gs.vstack([metric.dist(point_1, point_2)
for point_1, point_2 in zip(n_point_1,
n_point_2)])
self.assertTrue(gs.allclose(result, expected),
'with metric {}'.format(metric_type))
result = group.quaternion_from_tait_bryan_angles_intrinsic_xyz(
tait_bryan_angles)
expected = gs.array([[cos_half_angle, sin_half_angle, 0., 0.]])
self.assertTrue(gs.allclose(result, expected),
' result = \n{};'
' expected = \n{}.'.format(
result,
expected))
tait_bryan_angles = gs.array([0., angle, 0.])
result = group.quaternion_from_tait_bryan_angles_intrinsic_xyz(
tait_bryan_angles)
expected = gs.array([[cos_half_angle, 0., sin_half_angle, 0.]])
self.assertTrue(gs.allclose(result, expected),
' result = \n{};'
' expected = \n{}.'.format(
result,
expected))
tait_bryan_angles = gs.array([0., 0., angle])
result = group.quaternion_from_tait_bryan_angles_intrinsic_xyz(
tait_bryan_angles)
expected = gs.array([[cos_half_angle, 0., 0., sin_half_angle]])
self.assertTrue(gs.allclose(result, expected),
' result = \n{};'
' expected = \n{}.'.format(
result,
expected))
for angle_type in self.elements[3]:
point = self.elements[3][angle_type]
jacobian = group.jacobian_translation(point=point,
left_or_right='left')
result = gs.linalg.det(jacobian)
point = group.regularize(point)
angle = gs.linalg.norm(point)
if angle_type in ['with_angle_0',
'with_angle_close_0',
'with_angle_2pi',
'with_angle_close_2pi_high']:
expected = 1. + angle ** 2 / 12. + angle ** 4 / 240.
else:
expected = angle ** 2 / (4 * gs.sin(angle / 2) ** 2)
self.assertTrue(gs.allclose(result, expected),
'for point {}:\n'
'result = {}; expected = {}.'.format(
angle_type,
result,
expected))
Point in the group, from which to compute the log,
(the default is identity).
Returns
-------
log : array-like, shape=[..., dim]
Tangent vector at the base point equal to the Riemannian logarithm
of point at the base point.
"""
identity = self.group.identity
if base_point is None:
base_point = identity
base_point = self.group.regularize(base_point)
if gs.allclose(base_point, identity):
return self.log_from_identity(point)
point = self.group.regularize(point)
if self.left_or_right == 'left':
point_near_id = self.group.compose(
self.group.inverse(base_point), point)
else:
point_near_id = self.group.compose(
point, self.group.inverse(base_point))
log_from_id = self.log_from_identity(point_near_id)
jacobian = self.group.jacobian_translation(
base_point, left_or_right=self.left_or_right)
log = gs.einsum('...ij,...j->...i', jacobian, log_from_id)