Skip to content

Commit

Permalink
minor fixes for conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Censi committed Aug 5, 2013
1 parent d220e91 commit 8f6ab4d
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 73 deletions.
5 changes: 4 additions & 1 deletion src/geometry/basic_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from . import GeometryConstants, contract, np, new_contract
from .constants import GeometryConstants
from contracts import contract, new_contract
import numpy as np
import warnings


new_contract('R1', 'array[1]')
new_contract('R2', 'array[2]')
new_contract('R3', 'array[3]')
Expand Down
3 changes: 1 addition & 2 deletions src/geometry/manifolds/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
from contracts import contract, check, new_contract
from contracts import new_contract
from .. import assert_allclose, logger

from .exceptions import DoesNotBelong
Expand Down
50 changes: 27 additions & 23 deletions src/geometry/manifolds/embedding_relations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from . import (DifferentiableManifold, SO3, SO2, R1, R2, R3, SE2, SE3, S2, S1,
T1, T2, T3, so2, so3, se2, se3, np, Tran2, tran2, tran3, Tran3, tran1)
T1, T2, T3, so2, so3, se2, se3, Tran2, tran2, tran3, Tran3, tran1)
from .. import (S1_project_from_S2, S2_from_S1, S1_project_from_R2,
S2_project_from_R3, se2_from_so2, so2_project_from_se2, se3_from_so3,
so3_project_from_se3, SE3_from_SO3, SE2_from_SO2, SO2_project_from_SE2,
Expand All @@ -10,6 +10,7 @@
SE3_from_SE2, SO2_from_angle, angle_from_SO2)
from geometry.spheres import normalize_pi

import numpy as np

def embedding(small, big, embed_in, project_from, desc=None):
DifferentiableManifold.embedding(small, big, embed_in, project_from,
Expand All @@ -24,6 +25,31 @@ def isomorphism(A, B, a_to_b, b_to_a, desc=None):
def identity(x):
return x

def tran1_project_from_tran2(b):
return np.array([[0, b[0, -1]],
[0, 0]])


def tran2_from_tran1(b):
return np.array([[0, 0, b[0, -1]],
[0, 0, 0],
[0, 0, 0]])


def tran2_project_from_se2(b):
return np.array([[0, 0, b[0, -1]],
[0, 0, b[1, -1]],
[0, 0, 0]])


def tran3_project_from_se3(b):
return np.array([[0, 0, 0, b[0, -1]],
[0, 0, 0, b[1, -1]],
[0, 0, 0, b[2, -1]],
[0, 0, 0, 0]])




embedding(R1, R2, lambda a: np.array([a[0], 0]),
lambda b: np.array([b[0]]))
Expand Down Expand Up @@ -82,16 +108,6 @@ def T1_from_SO2(y):
embedding(T3, R3, identity, lambda x: T3.normalize(x))


def tran1_project_from_tran2(b):
return np.array([[0, b[0, -1]],
[0, 0]])


def tran2_from_tran1(b):
return np.array([[0, 0, b[0, -1]],
[0, 0, 0],
[0, 0, 0]])

embedding(tran1, tran2, tran2_from_tran1, tran1_project_from_tran2)


Expand All @@ -103,18 +119,6 @@ def tran2_from_tran1(b):
[0, 0, b[1, -1]],
[0, 0, 0]]))


def tran2_project_from_se2(b):
return np.array([[0, 0, b[0, -1]],
[0, 0, b[1, -1]],
[0, 0, 0]])


def tran3_project_from_se3(b):
return np.array([[0, 0, 0, b[0, -1]],
[0, 0, 0, b[1, -1]],
[0, 0, 0, b[2, -1]],
[0, 0, 0, 0]])

embedding(tran2, se2, identity, tran2_project_from_se2)

Expand Down
4 changes: 3 additions & 1 deletion src/geometry/manifolds/product_manifold.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from . import DifferentiableManifold, contract, np
from . import DifferentiableManifold
from contracts import contract
import numpy as np

__all__ = ['ProductManifold']

Expand Down
5 changes: 3 additions & 2 deletions src/geometry/manifolds/special_euclidean_group.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from . import DifferentiableManifold, MatrixLieGroup, SO, se, R, contract, np
from . import DifferentiableManifold, MatrixLieGroup, SO, se, R
from .. import (SE3_from_SE2, assert_allclose, pose_from_rotation_translation,
rotation_translation_from_pose, extract_pieces, se2_from_SE2, SE2_from_se2,
SE2_from_translation_angle)
from contracts import describe_type
from contracts import contract, describe_type
import numpy as np

__all__ = ['SE_group']

Expand Down
4 changes: 3 additions & 1 deletion src/geometry/manifolds/special_orthogonal_group.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from . import DifferentiableManifold, MatrixLieGroup, np, S2, so, contract
from . import DifferentiableManifold, MatrixLieGroup, S2, so
from .. import (assert_allclose, rot2d, random_rotation,
axis_angle_from_rotation, rotation_from_axis_angle)
from contracts import check
from contracts import contract
import numpy as np


class SO_group(MatrixLieGroup):
Expand Down
5 changes: 4 additions & 1 deletion src/geometry/manifolds/sphere.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from . import DifferentiableManifold, np, contract, check
from . import DifferentiableManifold
from .. import (any_orthogonal_direction, geodesic_distance_on_sphere,
random_direction, normalize_length, normalize_length_or_zero,
rotation_from_axis_angle, rot2d)
from contracts import contract, check
from numpy.core.numeric import outer
import numpy as np

__all__ = ['Sphere', 'Sphere1']

class Sphere(DifferentiableManifold):
''' These are hyperspheres of unit radius. '''
Expand Down
7 changes: 5 additions & 2 deletions src/geometry/manifolds/tangent_bundle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from . import DifferentiableManifold, contract
from . import DifferentiableManifold
from contracts import contract

__all__ = ['TangentBundle']


class TangentBundle(DifferentiableManifold):
Expand All @@ -25,7 +28,7 @@ def belongs_ts(self, bv):
# XXX: can we make it recursive?
raise ValueError('Not supported')

def project_ts(self, bv): # TODO: test
def project_ts(self, bv): # TODO: test
# XXX: can we make it recursive?
raise ValueError('Not supported')

Expand Down
4 changes: 3 additions & 1 deletion src/geometry/mds_algos.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from . import (best_similarity_transform, contract, np, assert_allclose,
from . import (best_similarity_transform, assert_allclose,
project_vectors_onto_sphere, eigh)
from contracts import check_multiple
import itertools
from geometry.formatting import formatm
from geometry import logger
from contracts import contract
import numpy as np


@contract(S='array[KxN]', returns='array[NxN](>=0)')
Expand Down
7 changes: 4 additions & 3 deletions src/geometry/poses.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from . import (angle_from_rot2d, rotz, axis_angle_from_rotation, hat_map_2d,
contract, assert_allclose, np, rot2d, new_contract,
check_SO, check_skew_symmetric, expm, logm)
from geometry.constants import GeometryConstants
assert_allclose, rot2d, new_contract, check_SO, check_skew_symmetric, expm, logm)
from .constants import GeometryConstants
from contracts import contract
import numpy as np


def check_SE(M):
Expand Down
10 changes: 6 additions & 4 deletions src/geometry/poses_embedding.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import numpy as np
from contracts import contract
from . import (SE3_from_rotation_translation, combine_pieces, extract_pieces,
contract, np, SE2_from_rotation_translation, rotation_translation_from_SE2,
SE2_from_rotation_translation, rotation_translation_from_SE2,
rotation_translation_from_SE3, hat_map, map_hat_2d, SO2_project_from_SO3,
so2_project_from_so3, so3_from_so2)

Expand Down Expand Up @@ -67,23 +69,23 @@ def R3_project_from_SE3(b):

@contract(returns='se3', a='se2')
def se3_from_se2(a):
W, v, zero, one = extract_pieces(a) #@UnusedVariable
W, v, zero, one = extract_pieces(a) # @UnusedVariable
W = so3_from_so2(W)
v = np.array([v[0], v[1], 0])
return combine_pieces(W, v, v * 0, 0)


@contract(returns='SE2', b='SE3')
def SE2_project_from_SE3(b):
R, t, zero, one = extract_pieces(b) #@UnusedVariable
R, t, zero, one = extract_pieces(b) # @UnusedVariable
R = SO2_project_from_SO3(R)
t = t[0:2]
return combine_pieces(R, t, t * 0, 1)


@contract(returns='se2', b='se3')
def se2_project_from_se3(b):
W, v, zero, one = extract_pieces(b) #@UnusedVariable
W, v, zero, one = extract_pieces(b) # @UnusedVariable
W = so2_project_from_so3(W)
v = v[0:2]
return combine_pieces(W, v, v * 0, 0)
Expand Down
27 changes: 15 additions & 12 deletions src/geometry/rotations.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
''' Contains all about rotation matrices, quaternions, and various conversions.
'''
Contains all about rotation matrices, quaternions, and various conversions.
conventions: q=( a + bi + cj + dk), with a>0
conventions: q=( a + bi + cj + dk), with a>0
'''
from . import (assert_allclose, new_contract, contract, safe_arccos, np,
from . import (assert_allclose, safe_arccos,
default_axis, normalize_length)
import itertools
from contracts import contract, new_contract
import numpy as np


new_contract('unit_quaternion', 'array[4], unit_length')
Expand All @@ -17,7 +20,7 @@
def check_SO(x):
''' Checks that the given value is a rotation matrix of arbitrary size. '''
check_orthogonal(x)
determinant = np.linalg.det(x * 1.0) # XXX: voodoo
determinant = np.linalg.det(x * 1.0) # XXX: voodoo
# lapack_lite.LapackError:
# Parameter a has non-native byte order in lapack_lite.dgetrf
assert_allclose(determinant, 1.0)
Expand All @@ -28,7 +31,7 @@ def check_orthogonal(x):
''' Check that the argument is an orthogonal matrix. '''
N = x.shape[0]
I = np.eye(N)
rtol = 10E-10 # XXX:
rtol = 10E-10 # XXX:
atol = 10E-7 # XXX:
assert_allclose(I, np.dot(x, x.T), rtol=rtol, atol=atol)
assert_allclose(I, np.dot(x.T, x), rtol=rtol, atol=atol)
Expand All @@ -48,7 +51,7 @@ def check_skew_symmetric(x):
if i < j:
continue
if x[i, j] != -x[j, i]:
raise ValueError('Expected skew symmetric, but ' +
raise ValueError('Expected skew symmetric, but ' +
'a[%d][%d] = %f, a[%d][%d] = %f' % \
(i, j, x[i, j], j, i, x[j, i]))

Expand Down Expand Up @@ -103,8 +106,8 @@ def hat_map_2d(omega):
def map_hat_2d(W):
return W[1, 0]

rot2d = SO2_from_angle # TODO: deprecated
rot2d_from_angle = SO2_from_angle# TODO: deprecated
rot2d = SO2_from_angle # TODO: deprecated
rot2d_from_angle = SO2_from_angle # TODO: deprecated
angle_from_rot2d = angle_from_SO2


Expand Down Expand Up @@ -159,7 +162,7 @@ def geodesic_distance_for_rotations(R1, R2):
'''
R = np.dot(R1, R2.T)
axis1, angle1 = axis_angle_from_rotation(R) #@UnusedVariable
axis1, angle1 = axis_angle_from_rotation(R) # @UnusedVariable
return angle1


Expand Down Expand Up @@ -226,7 +229,7 @@ def quaternion_from_rotation(R):
rr = 1 + R[u, u] - R[v, v] - R[w, w]
assert rr >= 0
r = np.sqrt(rr)
if r == 0: # TODO: add tolerance
if r == 0: # TODO: add tolerance
return quaternion_from_axis_angle(default_axis(), 0.0)
else:
q0 = (R[w, v] - R[v, w]) / (2 * r)
Expand Down Expand Up @@ -268,7 +271,7 @@ def axis_angle_from_quaternion(q):
This is the inverse of :py:func:`quaternion_from_axis_angle`.
'''
angle = 2 * safe_arccos(q[0])
if angle == 0: # XXX: use tolerance
if angle == 0: # XXX: use tolerance
axis = default_axis()
else:
axis = q[1:] / np.sin(angle / 2)
Expand Down Expand Up @@ -343,7 +346,7 @@ def rotation_from_axis_angle2(axis, angle):

@contract(x_axis='direction', vector_on_xy_plane='direction',
returns='rotation_matrix')
def rotation_from_axes_spec(x_axis, vector_on_xy_plane): # TODO: docs
def rotation_from_axes_spec(x_axis, vector_on_xy_plane): # TODO: docs
"""
Creates a rotation matrix from the axes.
``x_axis`` is the new direction of the (1,0,0) vector
Expand Down
7 changes: 5 additions & 2 deletions src/geometry/rotations_embedding.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from . import (map_hat_2d, contract, np, angle_from_rot2d,
from . import (map_hat_2d, angle_from_rot2d,
rotation_from_axis_angle, hat_map, rot2d)

from contracts import contract
import numpy as np


@contract(returns='SO3', a='SO2')
def SO3_from_SO2(a):
Expand All @@ -13,7 +16,7 @@ def SO2_project_from_SO3(b):
direction = np.array([1, 0, 0])
vector = np.dot(b, direction)
n = np.linalg.norm(vector)
atol = 1e-8 # XXX: make common
atol = 1e-8 # XXX: make common
if n < atol:
return rot2d(0)
else:
Expand Down
Loading

0 comments on commit 8f6ab4d

Please sign in to comment.