timings-cholesky.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018 CNRS
3 //
4 
16 
17 #include <iostream>
18 
20 
21 int main(int argc, const char ** argv)
22 {
23  using namespace Eigen;
24  using namespace pinocchio;
25 
27 #ifdef NDEBUG
28  const int NBT = 1000 * 100;
29 #else
30  const int NBT = 1;
31  std::cout << "(the time score in debug mode is not relevant) " << std::endl;
32 #endif
33 
35 
36  std::string filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.urdf");
37  if (argc > 1)
38  filename = argv[1];
39  if (filename == "HS")
41  else
43  std::cout << "nq = " << model.nq << std::endl;
44 
46  VectorXd qmax = Eigen::VectorXd::Ones(model.nq);
47 
48  MatrixXd A(model.nv, model.nv), B(model.nv, model.nv);
49  A.setZero();
50  B.setRandom();
51 
52  PINOCCHIO_ALIGNED_STD_VECTOR(VectorXd) qs(NBT);
53  PINOCCHIO_ALIGNED_STD_VECTOR(VectorXd) lhs(NBT);
54  PINOCCHIO_ALIGNED_STD_VECTOR(VectorXd) rhs(NBT);
55  for (size_t i = 0; i < NBT; ++i)
56  {
57  qs[i] = randomConfiguration(model, -qmax, qmax);
58  lhs[i] = Eigen::VectorXd::Zero(model.nv);
59  rhs[i] = Eigen::VectorXd::Random(model.nv);
60  }
61 
62  double total = 0;
63  SMOOTH(NBT)
64  {
65  crba(model, data, qs[_smooth], Convention::WORLD);
66  timer.tic();
68  total += timer.toc(timer.DEFAULT_UNIT);
69  }
70  std::cout << "Cholesky = \t" << (total / NBT) << " " << timer.unitName(timer.DEFAULT_UNIT)
71  << std::endl;
72 
73  total = 0;
74  Eigen::LDLT<Eigen::MatrixXd> Mldlt(data.M);
75  SMOOTH(NBT)
76  {
77  crba(model, data, qs[_smooth], Convention::WORLD);
78  data.M.triangularView<Eigen::StrictlyLower>() =
79  data.M.transpose().triangularView<Eigen::StrictlyLower>();
80  timer.tic();
81  Mldlt.compute(data.M);
82  total += timer.toc(timer.DEFAULT_UNIT);
83  }
84  std::cout << "Dense Eigen Cholesky = \t" << (total / NBT) << " "
85  << timer.unitName(timer.DEFAULT_UNIT) << std::endl;
86 
87  timer.tic();
88  SMOOTH(NBT)
89  {
90  cholesky::solve(model, data, rhs[_smooth]);
91  }
92  std::cout << "Cholesky solve vector = \t\t";
93  timer.toc(std::cout, NBT);
94 
95  timer.tic();
96  SMOOTH(NBT)
97  {
98  cholesky::UDUtv(model, data, rhs[_smooth]);
99  }
100  std::cout << "UDUtv = \t\t";
101  timer.toc(std::cout, NBT);
102 
103  MatrixXd Minv(model.nv, model.nv);
104  Minv.setZero();
105  timer.tic();
106  SMOOTH(NBT)
107  {
109  }
110  std::cout << "Minv from cholesky = \t\t";
111  timer.toc(std::cout, NBT);
112 
113  timer.tic();
114  SMOOTH(NBT)
115  {
116  cholesky::solve(model, data, Minv.col(10));
117  }
118  std::cout << "Cholesky solve column = \t\t";
119  timer.toc(std::cout, NBT);
120 
121  timer.tic();
122  SMOOTH(NBT)
123  {
124  lhs[_smooth].noalias() = Minv * rhs[_smooth];
125  }
126  std::cout << "Minv*v = \t\t";
127  timer.toc(std::cout, NBT);
128 
129  timer.tic();
130  SMOOTH(NBT)
131  {
132  A.noalias() = Minv * B;
133  }
134  std::cout << "A = Minv*B = \t\t";
135  timer.toc(std::cout, NBT);
136 
137  data.M.triangularView<Eigen::StrictlyLower>() =
138  data.M.transpose().triangularView<Eigen::StrictlyLower>();
139  timer.tic();
140  SMOOTH(NBT)
141  {
142  A.noalias() = data.M.inverse();
143  }
144  std::cout << "M.inverse() = \t\t";
145  timer.toc(std::cout, NBT);
146 
147  timer.tic();
148  SMOOTH(NBT)
149  {
150  computeMinverse(model, data, qs[_smooth]);
151  }
152  std::cout << "computeMinverse = \t\t";
153  timer.toc(std::cout, NBT);
154 
155  return 0;
156 }
pinocchio::WORLD
@ WORLD
Definition: multibody/fwd.hpp:48
PinocchioTicToc::toc
double toc()
Definition: timer.hpp:88
fwd.hpp
Eigen
pinocchio::DataTpl
Definition: context/generic.hpp:25
B
B
inverse-kinematics.i
int i
Definition: inverse-kinematics.py:17
model.hpp
setup.data
data
Definition: cmake/cython/setup.in.py:48
pinocchio::buildModels::humanoidRandom
void humanoidRandom(ModelTpl< Scalar, Options, JointCollectionTpl > &model, bool usingFF=true)
Create a humanoid kinematic tree with 6-DOF limbs and random joint placements.
main
int main(int argc, const char **argv)
Definition: timings-cholesky.cpp:21
pinocchio::python::context::JointModelFreeFlyer
JointModelFreeFlyerTpl< Scalar > JointModelFreeFlyer
Definition: bindings/python/context/generic.hpp:126
pinocchio::crba
const DataTpl< Scalar, Options, JointCollectionTpl >::MatrixXs & crba(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Convention convention=Convention::LOCAL)
Computes the upper triangular part of the joint space inertia matrix M by using the Composite Rigid B...
visitor.hpp
PinocchioTicToc::unitName
static std::string unitName(Unit u)
Definition: timer.hpp:58
PinocchioTicToc::DEFAULT_UNIT
Unit DEFAULT_UNIT
Definition: timer.hpp:56
pinocchio::cholesky::UDUtv
Mat & UDUtv(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< Mat > &m)
Performs the multiplication by using the Cholesky decomposition of M stored in data.
pinocchio::randomConfiguration
void randomConfiguration(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorIn1 > &lowerLimits, const Eigen::MatrixBase< ConfigVectorIn2 > &upperLimits, const Eigen::MatrixBase< ReturnType > &qout)
Generate a configuration vector uniformly sampled among provided limits.
Definition: joint-configuration.hpp:315
timer.hpp
pinocchio::computeMinverse
const DataTpl< Scalar, Options, JointCollectionTpl >::RowMatrixXs & computeMinverse(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
Computes the inverse of the joint space inertia matrix using Articulated Body formulation.
aba.hpp
anymal-simulation.model
model
Definition: anymal-simulation.py:8
pinocchio::cholesky::solve
Mat & solve(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< Mat > &y)
Return the solution of using the Cholesky decomposition stored in data given the entry ....
SMOOTH
#define SMOOTH(s)
Definition: timer.hpp:38
joint-configuration.hpp
filename
filename
se3.hpp
urdf.hpp
data.hpp
pinocchio::urdf::buildModel
ModelTpl< Scalar, Options, JointCollectionTpl > & buildModel(const std::string &filename, const typename ModelTpl< Scalar, Options, JointCollectionTpl >::JointModel &rootJoint, const std::string &rootJointName, ModelTpl< Scalar, Options, JointCollectionTpl > &model, const bool verbose=false)
Build the model from a URDF file with a particular joint as root of the model tree inside the model g...
simulation-contact-dynamics.A
A
Definition: simulation-contact-dynamics.py:110
PinocchioTicToc::US
@ US
Definition: timer.hpp:53
cholesky.hpp
pinocchio::cholesky::decompose
const DataTpl< Scalar, Options, JointCollectionTpl >::MatrixXs & decompose(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data)
Compute the Cholesky decomposition of the joint space inertia matrix M contained in data.
pinocchio::cholesky::computeMinv
Mat & computeMinv(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< Mat > &Minv)
Computes the inverse of the joint space inertia matrix M from its Cholesky factorization.
PINOCCHIO_ALIGNED_STD_VECTOR
#define PINOCCHIO_ALIGNED_STD_VECTOR(Type)
Definition: container/aligned-vector.hpp:11
sample-models.hpp
pinocchio::ModelTpl
Definition: context/generic.hpp:20
crba.hpp
PinocchioTicToc
Definition: timer.hpp:47
meshcat-viewer.qs
qs
Definition: meshcat-viewer.py:128
simulation-closed-kinematic-chains.rhs
rhs
Definition: simulation-closed-kinematic-chains.py:138
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27
PINOCCHIO_MODEL_DIR
#define PINOCCHIO_MODEL_DIR
Definition: build-reduced-model.cpp:11
PinocchioTicToc::tic
void tic()
Definition: timer.hpp:82


pinocchio
Author(s):
autogenerated on Sun Dec 22 2024 03:41:12