Skip to content
Snippets Groups Projects
Commit 8d719be0 authored by Gabriele Buondonno's avatar Gabriele Buondonno Committed by Gabriele Buondonno
Browse files

[python] Fix explog for array

parent 5eb23249
Branches
Tags
No related merge requests found
......@@ -15,9 +15,9 @@ def exp(x):
if np.isscalar(x):
return math.exp(x)
if isinstance(x, np.ndarray):
if x.shape == (6, 1):
if x.shape == (6, 1) or x.shape == (6,):
return pin.exp6(pin.Motion(x))
if x.shape == (3, 1):
if x.shape == (3, 1) or x.shape == (3,):
return pin.exp3(x)
raise ValueError('Error only 3 and 6 vectors are allowed.')
raise ValueError('Error exp is only defined for real, vector3, vector6 and pin.Motion objects.')
......
......@@ -62,16 +62,29 @@ class TestExpLog(TestCase):
self.assertApprox(log(42), math.log(42))
self.assertApprox(exp(log(42)), 42)
self.assertApprox(log(exp(42)), 42)
m = rand(3)
self.assertTrue(np.linalg.norm(m) < np.pi) # necessary for next test
self.assertLess(np.linalg.norm(m), np.pi) # necessary for next test
self.assertApprox(log(exp(m)), m)
m = np.random.rand(3)
self.assertLess(np.linalg.norm(m), np.pi) # necessary for next test
self.assertApprox(log(exp(m)), m)
m = pin.SE3.Random()
self.assertApprox(exp(log(m)), m)
m = rand(6)
self.assertTrue(np.linalg.norm(m) < np.pi) # necessary for next test (actually, only angular part)
self.assertLess(np.linalg.norm(m), np.pi) # necessary for next test (actually, only angular part)
self.assertApprox(log(exp(m)), m)
m = np.random.rand(6)
self.assertLess(np.linalg.norm(m), np.pi) # necessary for next test (actually, only angular part)
self.assertApprox(log(exp(m)), m)
m = eye(4)
self.assertApprox(exp(log(m)).homogeneous, m)
with self.assertRaises(ValueError):
exp(eye(4))
with self.assertRaises(ValueError):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment