bindings/python/pinocchio/utils.py
Go to the documentation of this file.
1 #
2 # Copyright (c) 2015-2022 CNRS INRIA
3 #
4 
5 
6 import sys
7 
8 import numpy as np
9 import numpy.linalg as npl
10 
11 from . import pinocchio_pywrap_default as pin
12 from .pinocchio_pywrap_default.rpy import matrixToRpy, rotate, rpyToMatrix
13 
14 
15 def npToTTuple(M):
16  L = M.tolist()
17  for i in range(len(L)):
18  L[i] = tuple(L[i])
19  return tuple(L)
20 
21 
22 def npToTuple(M):
23  if len(M.shape) == 1:
24  return tuple(M.tolist())
25  if M.shape[0] == 1:
26  return tuple(M.tolist()[0])
27  if M.shape[1] == 1:
28  return tuple(M.T.tolist()[0])
29  return npToTTuple(M)
30 
31 
32 def eye(n):
33  res = np.eye(n)
34  return res
35 
36 
37 def zero(n):
38  return np.zeros(n)
39 
40 
41 def rand(n):
42  return np.random.rand(n) if isinstance(n, int) else np.random.rand(n[0], n[1])
43 
44 
45 def isapprox(a, b, epsilon=1e-6):
46  if "np" in a.__class__.__dict__:
47  a = a.np
48  if "np" in b.__class__.__dict__:
49  b = b.np
50  if isinstance(a, (np.ndarray, list)) and isinstance(b, (np.ndarray, list)):
51  a = np.squeeze(np.array(a))
52  b = np.squeeze(np.array(b))
53  return np.allclose(a, b, epsilon)
54  return abs(a - b) < epsilon
55 
56 
57 def mprint(M, name="ans", eps=1e-15):
58  """
59  Matlab-style pretty matrix print.
60  """
61  if isinstance(M, pin.SE3):
62  M = M.homogeneous
63  if len(M.shape) == 1:
64  M = np.expand_dims(M, axis=0)
65  ncol = M.shape[1]
66  NC = 6
67  print(name, " = ")
68  print()
69 
70  Mm = (abs(M[np.nonzero(M)])).min()
71  MM = (abs(M[np.nonzero(M)])).max()
72 
73  fmt = "% 10.3e" if Mm < 1e-5 or MM > 1e6 or MM / Mm > 1e3 else "% 1.5f"
74 
75  for i in range((ncol - 1) // NC + 1):
76  cmin = i * 6
77  cmax = (i + 1) * 6
78  cmax = ncol if ncol < cmax else cmax
79  print(f"Columns {cmin} through {cmax - 1}")
80  print()
81  for r in range(M.shape[0]):
82  sys.stdout.write(" ")
83  for c in range(cmin, cmax):
84  if abs(M[r, c]) > eps:
85  sys.stdout.write(fmt % M[r, c] + " ")
86  else:
87  sys.stdout.write(" 0" + " " * 9)
88  print()
89  print()
90 
91 
93  vector = pin.StdVec_StdString()
94  vector.extend(item for item in items)
95  return vector
96 
97 
98 __all__ = [
99  "np",
100  "npl",
101  "eye",
102  "zero",
103  "rand",
104  "isapprox",
105  "mprint",
106  "npToTTuple",
107  "npToTuple",
108  "rotate",
109  "rpyToMatrix",
110  "matrixToRpy",
111  "fromListToVectorOfString",
112 ]
pinocchio.utils.fromListToVectorOfString
def fromListToVectorOfString(items)
Definition: bindings/python/pinocchio/utils.py:92
pinocchio.utils.npToTTuple
def npToTTuple(M)
Definition: bindings/python/pinocchio/utils.py:15
pinocchio::cholesky::min
JointCollectionTpl const DataTpl< Scalar, Options, JointCollectionTpl > const Eigen::MatrixBase< Mat > & min
Definition: cholesky.hpp:89
pinocchio.utils.isapprox
def isapprox(a, b, epsilon=1e-6)
Definition: bindings/python/pinocchio/utils.py:45
pinocchio.utils.mprint
def mprint(M, name="ans", eps=1e-15)
Definition: bindings/python/pinocchio/utils.py:57
pinocchio.utils.eye
def eye(n)
Definition: bindings/python/pinocchio/utils.py:32
pinocchio.utils.npToTuple
def npToTuple(M)
Definition: bindings/python/pinocchio/utils.py:22
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
CppAD::max
AD< Scalar > max(const AD< Scalar > &x, const AD< Scalar > &y)
Definition: autodiff/cppad.hpp:181


pinocchio
Author(s):
autogenerated on Thu Dec 19 2024 03:41:33