timings-cholesky.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018 CNRS
3 //
4 
5 #include "pinocchio/spatial/fwd.hpp"
6 #include "pinocchio/spatial/se3.hpp"
7 #include "pinocchio/multibody/visitor.hpp"
8 #include "pinocchio/multibody/model.hpp"
9 #include "pinocchio/multibody/data.hpp"
10 #include "pinocchio/algorithm/joint-configuration.hpp"
11 #include "pinocchio/algorithm/crba.hpp"
12 #include "pinocchio/algorithm/aba.hpp"
13 #include "pinocchio/algorithm/cholesky.hpp"
14 #include "pinocchio/parsers/urdf.hpp"
15 #include "pinocchio/parsers/sample-models.hpp"
16 
17 #include <iostream>
18 
19 #include "pinocchio/utils/timer.hpp"
20 
21 #include <Eigen/StdVector>
22 EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(Eigen::VectorXd)
23 
24 int main(int argc, const char ** argv)
25 {
26  using namespace Eigen;
27  using namespace pinocchio;
28 
30  #ifdef NDEBUG
31  const int NBT = 1000*100;
32  #else
33  const int NBT = 1;
34  std::cout << "(the time score in debug mode is not relevant) " << std::endl;
35  #endif
36 
38 
39  std::string filename = PINOCCHIO_MODEL_DIR + std::string("/simple_humanoid.urdf");
40  if(argc>1) filename = argv[1];
41  if( filename == "HS")
43  else
45  std::cout << "nq = " << model.nq << std::endl;
46 
47  pinocchio::Data data(model);
48  VectorXd qmax = Eigen::VectorXd::Ones(model.nq);
49 
50  MatrixXd A(model.nv,model.nv), B(model.nv,model.nv);
51  A.setZero(); B.setRandom();
52 
53  std::vector<VectorXd> qs (NBT);
54  std::vector<VectorXd> lhs (NBT);
55  std::vector<VectorXd> rhs (NBT);
56  for(size_t i=0;i<NBT;++i)
57  {
58  qs[i] = randomConfiguration(model,-qmax,qmax);
59  lhs[i] = Eigen::VectorXd::Zero(model.nv);
60  rhs[i] = Eigen::VectorXd::Random(model.nv);
61  }
62 
63  double total = 0;
64  SMOOTH(NBT)
65  {
66  crba(model,data,qs[_smooth]);
67  timer.tic();
68  cholesky::decompose(model,data);
69  total += timer.toc(timer.DEFAULT_UNIT);
70  }
71  std::cout << "Cholesky = \t" << (total/NBT)
72  << " " << timer.unitName(timer.DEFAULT_UNIT) <<std::endl;
73 
74  total = 0;
75  Eigen::LDLT<Eigen::MatrixXd> Mldlt(data.M);
76  SMOOTH(NBT)
77  {
78  crba(model,data,qs[_smooth]);
79  data.M.triangularView<Eigen::StrictlyLower>()
80  = data.M.transpose().triangularView<Eigen::StrictlyLower>();
81  timer.tic();
82  Mldlt.compute(data.M);
83  total += timer.toc(timer.DEFAULT_UNIT);
84  }
85  std::cout << "Dense Eigen Cholesky = \t" << (total/NBT)
86  << " " << timer.unitName(timer.DEFAULT_UNIT) <<std::endl;
87 
88  timer.tic();
89  SMOOTH(NBT)
90  {
91  cholesky::solve(model,data,rhs[_smooth]);
92  }
93  std::cout << "Cholesky solve vector = \t\t"; 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"; timer.toc(std::cout,NBT);
101 
102  MatrixXd Minv(model.nv,model.nv); Minv.setZero();
103  timer.tic();
104  SMOOTH(NBT)
105  {
106  cholesky::computeMinv(model,data,Minv);
107  }
108  std::cout << "Minv from cholesky = \t\t"; timer.toc(std::cout,NBT);
109 
110  timer.tic();
111  SMOOTH(NBT)
112  {
113  cholesky::solve(model,data,Minv.col(10));
114  }
115  std::cout << "Cholesky solve column = \t\t"; timer.toc(std::cout,NBT);
116 
117  timer.tic();
118  SMOOTH(NBT)
119  {
120  lhs[_smooth].noalias() = Minv*rhs[_smooth];
121  }
122  std::cout << "Minv*v = \t\t"; timer.toc(std::cout,NBT);
123 
124  timer.tic();
125  SMOOTH(NBT)
126  {
127  A.noalias() = Minv*B;
128  }
129  std::cout << "A = Minv*B = \t\t"; timer.toc(std::cout,NBT);
130 
131  data.M.triangularView<Eigen::StrictlyLower>()
132  = data.M.transpose().triangularView<Eigen::StrictlyLower>();
133  timer.tic();
134  SMOOTH(NBT)
135  {
136  A.noalias() = data.M.inverse();
137  }
138  std::cout << "M.inverse() = \t\t"; timer.toc(std::cout,NBT);
139 
140  timer.tic();
141  SMOOTH(NBT)
142  {
143  computeMinverse(model,data,qs[_smooth]);
144  }
145  std::cout << "computeMinverse = \t\t"; timer.toc(std::cout,NBT);
146 
147  return 0;
148 }
double toc()
Definition: timer.hpp:68
Unit DEFAULT_UNIT
Definition: timer.hpp:50
const DataTpl< Scalar, Options, JointCollectionTpl >::MatrixXs & crba(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
Computes the upper triangular part of the joint space inertia matrix M by using the Composite Rigid B...
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.
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.
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...
static std::string unitName(Unit u)
Definition: timer.hpp:52
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.
data
#define PINOCCHIO_MODEL_DIR
void tic()
Definition: timer.hpp:63
int main(int argc, const char **argv)
MatrixXs M
The joint space inertia matrix (a square matrix of dim model.nv).
#define SMOOTH(s)
Definition: timer.hpp:38
ModelTpl< Scalar, Options, JointCollectionTpl > & buildModel(const std::string &filename, const typename ModelTpl< Scalar, Options, JointCollectionTpl >::JointModel &rootJoint, 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...
Main pinocchio namespace.
Definition: timings.cpp:30
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.
int nv
Dimension of the velocity vector space.
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 ...
JointModelFreeFlyerTpl< double > JointModelFreeFlyer
A
void humanoidRandom(ModelTpl< Scalar, Options, JointCollectionTpl > &model, bool usingFF=true)
Create a humanoid kinematic tree with 6-DOF limbs and random joint placements.
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > VectorXd
Definition: conversions.cpp:14
int nq
Dimension of the configuration vector representation.


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:04