multibody/pool/model.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2021-2022 INRIA
3 //
4 
5 #ifndef __pinocchio_multibody_pool_model_hpp__
6 #define __pinocchio_multibody_pool_model_hpp__
7 
8 #include <algorithm>
9 
13 
15 
16 namespace pinocchio
17 {
18  template<typename _Scalar, int _Options, template<typename, int> class JointCollectionTpl>
19  class ModelPoolTpl
20  {
21  public:
22  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
23 
24  typedef _Scalar Scalar;
25  enum
26  {
27  Options = _Options
28  };
29 
32 
33  typedef std::vector<Model, Eigen::aligned_allocator<Model>> ModelVector;
34  typedef std::vector<Data, Eigen::aligned_allocator<Data>> DataVector;
35 
41  explicit ModelPoolTpl(
42  const Model & model, const size_t pool_size = (size_t)omp_get_max_threads())
43  : m_models(pool_size, model)
44  , m_datas(pool_size, Data(model))
45  {
46  }
47 
55  {
56  }
57 
62  void update(const Data & data)
63  {
64  std::fill(m_datas.begin(), m_datas.end(), data);
65  }
66 
68  size_t size() const
69  {
70  return m_datas.size();
71  }
72 
74  void resize(const size_t new_size)
75  {
76  const size_t size = m_datas.size();
77  m_models.resize((size_t)new_size);
78  m_datas.resize((size_t)new_size);
79 
80  if (size < new_size)
81  {
82  typename ModelVector::iterator model_it = m_models.begin();
83  std::advance(model_it, (long)(new_size - size));
84  std::fill(model_it, m_models.end(), m_models[0]);
85 
86  typename DataVector::iterator data_it = m_datas.begin();
87  std::advance(data_it, (long)(new_size - size));
88  std::fill(data_it, m_datas.end(), m_datas[0]);
89  }
90 
91  doResize(new_size); // call Derived::doResize();
92  }
93 
95  const ModelVector & getModels() const
96  {
97  return m_models;
98  }
99 
102  {
103  return m_models;
104  }
105 
107  const Model & getModel(const size_t index) const
108  {
110  index < m_models.size(), "Index greater than the size of the model vector.");
111  return m_models[index];
112  }
113 
115  Model & getModel(const size_t index)
116  {
118  index < m_models.size(), "Index greater than the size of the model vector.");
119  return m_models[index];
120  }
121 
123  const DataVector & getDatas() const
124  {
125  return m_datas;
126  }
127 
130  {
131  return m_datas;
132  }
133 
135  const Data & getData(const size_t index) const
136  {
138  index < m_datas.size(), "Index greater than the size of the datas vector.");
139  return m_datas[index];
140  }
141 
143  Data & getData(const size_t index)
144  {
146  index < m_datas.size(), "Index greater than the size of the datas vector.");
147  return m_datas[index];
148  }
149 
151  virtual ~ModelPoolTpl() {};
152 
153  protected:
156 
159 
161  virtual void doResize(const size_t new_size)
162  {
163  PINOCCHIO_UNUSED_VARIABLE(new_size);
164  }
165  };
166 
167 } // namespace pinocchio
168 
169 #endif // ifndef __pinocchio_multibody_pool_model_hpp__
pinocchio::ModelPoolTpl::resize
void resize(const size_t new_size)
Set the size of the pool and perform the appropriate resize.
Definition: multibody/pool/model.hpp:74
pinocchio::DataTpl
Definition: context/generic.hpp:25
PINOCCHIO_CHECK_INPUT_ARGUMENT
#define PINOCCHIO_CHECK_INPUT_ARGUMENT(...)
Macro to check an assert-like condition and throw a std::invalid_argument exception (with a message) ...
Definition: include/pinocchio/macros.hpp:192
index
index
pinocchio::ModelPoolTpl::getModels
const ModelVector & getModels() const
Returns the vector of models.
Definition: multibody/pool/model.hpp:95
model.hpp
setup.data
data
Definition: cmake/cython/setup.in.py:48
pinocchio::ModelPoolTpl::ModelPoolTpl
ModelPoolTpl(const Model &model, const size_t pool_size=(size_t) omp_get_max_threads())
Default constructor from a model and a pool size.
Definition: multibody/pool/model.hpp:41
pinocchio::ModelPoolTpl::getModel
const Model & getModel(const size_t index) const
Return a specific model.
Definition: multibody/pool/model.hpp:107
pinocchio::ModelPoolTpl::Data
DataTpl< Scalar, Options, JointCollectionTpl > Data
Definition: multibody/pool/model.hpp:31
pinocchio::ModelPoolTpl::Options
@ Options
Definition: multibody/pool/model.hpp:27
pinocchio::ModelPoolTpl::ModelPoolTpl
ModelPoolTpl(const ModelPoolTpl &pool)
Copy constructor from an other PoolModel.
Definition: multibody/pool/model.hpp:52
pinocchio::ModelPoolTpl::getModels
ModelVector & getModels()
Returns the vector of models.
Definition: multibody/pool/model.hpp:101
pinocchio::ModelPoolTpl::~ModelPoolTpl
virtual ~ModelPoolTpl()
&#160;
Definition: multibody/pool/model.hpp:151
pinocchio::ModelPoolTpl::getData
const Data & getData(const size_t index) const
Return a specific data.
Definition: multibody/pool/model.hpp:135
pinocchio::ModelPoolTpl::getDatas
DataVector & getDatas()
Returns the data vector.
Definition: multibody/pool/model.hpp:129
data.hpp
pinocchio::ModelPoolTpl
Definition: multibody/pool/fwd.hpp:17
run-algo-in-parallel.pool
pool
Definition: run-algo-in-parallel.py:8
pinocchio::ModelPoolTpl::getData
Data & getData(const size_t index)
Returns a specific data.
Definition: multibody/pool/model.hpp:143
pinocchio::ModelPoolTpl::update
void update(const Data &data)
Update all the datas with the input data value.
Definition: multibody/pool/model.hpp:62
pinocchio::ModelPoolTpl::Model
ModelTpl< Scalar, Options, JointCollectionTpl > Model
Definition: multibody/pool/model.hpp:30
pinocchio::ModelPoolTpl::getDatas
const DataVector & getDatas() const
Returns the data vector.
Definition: multibody/pool/model.hpp:123
pinocchio::ModelPoolTpl::m_models
ModelVector m_models
&#160;
Definition: multibody/pool/model.hpp:151
pinocchio::ModelPoolTpl::getModel
Model & getModel(const size_t index)
Returns a specific model.
Definition: multibody/pool/model.hpp:115
pinocchio::ModelPoolTpl::doResize
virtual void doResize(const size_t new_size)
&#160;
Definition: multibody/pool/model.hpp:161
pinocchio::ModelPoolTpl::m_datas
DataVector m_datas
&#160;
Definition: multibody/pool/model.hpp:158
fwd.hpp
pinocchio::ModelPoolTpl::DataVector
std::vector< Data, Eigen::aligned_allocator< Data > > DataVector
Definition: multibody/pool/model.hpp:34
pinocchio::ModelPoolTpl::ModelVector
std::vector< Model, Eigen::aligned_allocator< Model > > ModelVector
Definition: multibody/pool/model.hpp:33
pinocchio::ModelPoolTpl::size
size_t size() const
Returns the size of the pool.
Definition: multibody/pool/model.hpp:68
pinocchio::ModelTpl
Definition: context/generic.hpp:20
pinocchio::ModelPoolTpl::Scalar
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar
Definition: multibody/pool/model.hpp:24
pinocchio::model
JointCollectionTpl & model
Definition: joint-configuration.hpp:1082
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27
PINOCCHIO_UNUSED_VARIABLE
#define PINOCCHIO_UNUSED_VARIABLE(var)
Helper to declare that a parameter is unused.
Definition: include/pinocchio/macros.hpp:72
openmp.hpp


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