unittest/python/explog.py
Go to the documentation of this file.
1 import math
2 import unittest
3 
4 import numpy as np
5 import pinocchio as pin
6 from pinocchio.explog import exp, log
7 from pinocchio.utils import eye, rand, zero
8 from test_case import PinocchioTestCase as TestCase
9 
10 
11 class TestExpLog(TestCase):
12  def test_exp3(self):
13  v = zero(3)
14  m = pin.exp3(v)
15  self.assertApprox(m, eye(3))
16 
17  def test_Jexp3(self):
18  v = zero(3)
19  m = pin.Jexp3(v)
20  self.assertApprox(m, eye(3))
21 
22  def test_log3(self):
23  m = eye(3)
24  v = pin.log3(m)
25  self.assertApprox(v, zero(3))
26 
27  def test_log3_quat(self):
28  """Test log3 over the quaternions."""
29  from eigenpy import Quaternion
30 
31  quat_v = np.array([0.0, 0.0, 0.0, 1.0])
32  quat = Quaternion(quat_v)
33  v0 = pin.log3(quat)
34  self.assertApprox(v0, zero(3))
35 
36  v1 = pin.log3(quat_v)
37  self.assertApprox(v1, zero(3))
38 
39  def test_exp3_quat(self):
40  self.assertApprox(pin.exp3_quat(zero(3)), np.array([0.0, 0.0, 0.0, 1.0]))
41 
42  def test_Jlog3(self):
43  m = eye(3)
44  J = pin.Jlog3(m)
45  self.assertApprox(J, eye(3))
46 
47  def test_exp6(self):
48  v = pin.Motion.Zero()
49  M = pin.exp6(v)
50  self.assertTrue(M.isIdentity())
51 
52  M2 = pin.exp6(np.array(v))
53  self.assertTrue(M2.isIdentity())
54 
55  def test_Jexp6(self):
56  v = pin.Motion.Zero()
57  J = pin.Jexp6(v)
58  self.assertApprox(J, eye(6))
59 
60  J2 = pin.Jexp6(np.array(v))
61  self.assertApprox(J, J2)
62 
63  def test_log6(self):
64  m = pin.SE3.Identity()
65  v = pin.log6(m)
66  self.assertApprox(v.vector, zero(6))
67 
69  m = eye(4)
70  v = pin.log6(m)
71  self.assertApprox(v.vector, zero(6))
72 
73  def test_log6_quat(self):
74  q0 = np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0])
75  v = pin.log6_quat(q0)
76  self.assertApprox(v.vector, zero(6))
77 
78  def test_Jlog6(self):
79  m = pin.SE3.Identity()
80  J = pin.Jlog6(m)
81  self.assertApprox(J, eye(6))
82 
83  def test_skew(self):
84  u = np.random.rand(3)
85  v = np.random.rand(3)
86 
87  u_skew = pin.skew(u)
88  u_unskew = pin.unSkew(u_skew)
89 
90  self.assertApprox(u, u_unskew)
91 
92  v_skew = pin.skew(v)
93  u_v_square = pin.skewSquare(u, v)
94 
95  self.assertApprox(u_v_square, u_skew.dot(v_skew))
96 
97  def test_explog(self):
98  self.assertApprox(exp(42), math.exp(42))
99  self.assertApprox(log(42), math.log(42))
100  self.assertApprox(exp(log(42)), 42)
101  self.assertApprox(log(exp(42)), 42)
102 
103  m = rand(3)
104  self.assertLess(np.linalg.norm(m), np.pi) # necessary for next test
105  self.assertApprox(log(exp(m)), m)
106 
107  m = np.random.rand(3)
108  self.assertLess(np.linalg.norm(m), np.pi) # necessary for next test
109  self.assertApprox(log(exp(m)), m)
110 
111  m = pin.SE3.Random()
112  self.assertApprox(exp(log(m)), m)
113 
114  m = rand(6)
115  self.assertLess(
116  np.linalg.norm(m), np.pi
117  ) # necessary for next test (actually, only angular part)
118  self.assertApprox(log(exp(m)), m)
119 
120  m = np.random.rand(6)
121  self.assertLess(
122  np.linalg.norm(m), np.pi
123  ) # necessary for next test (actually, only angular part)
124  self.assertApprox(log(exp(m)), m)
125 
126  m = eye(4)
127  self.assertApprox(exp(log(m)).homogeneous, m)
128 
129  with self.assertRaises(ValueError):
130  exp(eye(4))
131  with self.assertRaises(ValueError):
132  exp(list(range(3)))
133  with self.assertRaises(ValueError):
134  log(list(range(3)))
135  with self.assertRaises(ValueError):
136  log(zero(5))
137  with self.assertRaises(ValueError):
138  log(zero((3, 1)))
139 
140 
141 if __name__ == "__main__":
142  unittest.main()
explog.TestExpLog.test_Jexp3
def test_Jexp3(self)
Definition: unittest/python/explog.py:17
explog.TestExpLog.test_Jlog6
def test_Jlog6(self)
Definition: unittest/python/explog.py:78
explog.TestExpLog.test_Jlog3
def test_Jlog3(self)
Definition: unittest/python/explog.py:42
explog.TestExpLog.test_Jexp6
def test_Jexp6(self)
Definition: unittest/python/explog.py:55
pinocchio.explog.exp
def exp(x)
Definition: bindings/python/pinocchio/explog.py:13
explog.TestExpLog.test_log3_quat
def test_log3_quat(self)
Definition: unittest/python/explog.py:27
explog.TestExpLog.test_exp6
def test_exp6(self)
Definition: unittest/python/explog.py:47
explog.TestExpLog
Definition: unittest/python/explog.py:11
explog.TestExpLog.test_skew
def test_skew(self)
Definition: unittest/python/explog.py:83
explog.TestExpLog.test_exp3
def test_exp3(self)
Definition: unittest/python/explog.py:12
pinocchio::python::context::Quaternion
Eigen::Quaternion< Scalar, Options > Quaternion
Definition: bindings/python/context/generic.hpp:49
explog.TestExpLog.test_exp3_quat
def test_exp3_quat(self)
Definition: unittest/python/explog.py:39
pinocchio.utils
Definition: bindings/python/pinocchio/utils.py:1
pinocchio.explog
Definition: bindings/python/pinocchio/explog.py:1
pinocchio.utils.eye
def eye(n)
Definition: bindings/python/pinocchio/utils.py:32
explog.TestExpLog.test_log6_quat
def test_log6_quat(self)
Definition: unittest/python/explog.py:73
explog.TestExpLog.test_log3
def test_log3(self)
Definition: unittest/python/explog.py:22
pinocchio.explog.log
def log(x)
Definition: bindings/python/pinocchio/explog.py:29
explog.TestExpLog.test_log6_homogeneous
def test_log6_homogeneous(self)
Definition: unittest/python/explog.py:68
pinocchio.utils.rand
def rand(n)
Definition: bindings/python/pinocchio/utils.py:41
pinocchio.utils.zero
def zero(n)
Definition: bindings/python/pinocchio/utils.py:37
explog.TestExpLog.test_explog
def test_explog(self)
Definition: unittest/python/explog.py:97
explog.TestExpLog.test_log6
def test_log6(self)
Definition: unittest/python/explog.py:63


pinocchio
Author(s):
autogenerated on Fri Jan 10 2025 03:41:32