Skip to content
Snippets Groups Projects
Commit dd382151 authored by Joan Solà Ortega's avatar Joan Solà Ortega
Browse files

Upgrade API of composites

parent b2cea5a1
No related branches found
No related tags found
1 merge request!358WIP: Resolve "Complete state vector new data structure?"
......@@ -88,6 +88,7 @@ class HasStateBlocks
bool getState(VectorComposite& _state) const;
void setState(const VectorComposite& _state);
bool setState(const StateStructure& _structure, const std::list<VectorXd>& _vectors);
bool setState(const VectorXd& _state, const StateStructure& _structure, const std::list<int>& _sizes);
// Perturb state with noise
void perturb(double amplitude = 0.01);
......@@ -241,6 +242,23 @@ inline bool HasStateBlocks::setState (const StateStructure& _structure, const st
return true;
}
inline bool HasStateBlocks::setState (const VectorXd& _state, const StateStructure& _structure, const std::list<int>& _sizes)
{
assert(_structure.size() == _sizes.size() && "Structure and sizes mismatch");
int index = 0;
auto sizes_it = _sizes.begin();
for (const auto& ckey : _structure)
{
string key(1,ckey);
state_block_composite_.set(key, _state.segment(index, *sizes_it));
index += *sizes_it;
sizes_it++;
}
return true;
}
} // namespace wolf
#endif /* STATE_BLOCK_HAS_STATE_BLOCKS_H_ */
......@@ -47,6 +47,7 @@ class VectorComposite : public std::unordered_map < std::string, Eigen::VectorXd
* vec_comp["b"].transpose(); // = (3,4,5);
*/
VectorComposite(const VectorXd& _v, const StateStructure& _structure, const std::list<int>& _sizes);
VectorComposite(const StateStructure& _structure, const std::list<VectorXd>& _vectors);
unsigned int size(const StateStructure& _structure) const;
......
......@@ -47,6 +47,19 @@ VectorComposite::VectorComposite (const StateStructure& _s)
}
}
VectorComposite::VectorComposite (const StateStructure& _structure, const std::list<VectorXd>& _vectors)
{
assert(_structure.size() == _vectors.size() && "Structure and vector list size mismatch");
auto vector_it = _vectors.begin();
for (const auto& ckey : _structure)
{
string key(1,ckey);
this->emplace(key, *vector_it);
vector_it++;
}
}
unsigned int VectorComposite::size(const StateStructure &_structure) const
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment