23#include <gtsam/base/ConcurrentMap.h>
27#include <boost/shared_ptr.hpp>
86 typedef std::map<Key, size_t>
Dims;
96 : values_(init.begin(), init.end()) {}
103 template<
class CONTAINER>
104 explicit VectorValues(
const CONTAINER& c) : values_(c.begin(), c.end()) {}
110 template<
typename ITERATOR>
127 size_t size()
const {
return values_.size(); }
130 size_t dim(
Key j)
const {
return at(j).rows(); }
142 throw std::out_of_range(
143 "Requested variable '" + DefaultKeyFormatter(j) +
"' is not in this VectorValues.");
155 throw std::out_of_range(
156 "Requested variable '" + DefaultKeyFormatter(j) +
"' is not in this VectorValues.");
178 iterator insert(
const std::pair<Key, Vector>& key_value);
184 template<
class... Args>
185 inline std::pair<VectorValues::iterator, bool>
emplace(
Key j, Args&&... args) {
186#if ! defined(GTSAM_USE_TBB) || defined (TBB_GREATER_EQUAL_2020)
187 return values_.emplace(std::piecewise_construct, std::forward_as_tuple(j), std::forward_as_tuple(args...));
189 return values_.insert(std::make_pair(j, Vector(std::forward<Args>(args)...)));
198 return insert(std::make_pair(j, value));
209 inline std::pair<iterator, bool>
tryInsert(
Key j,
const Vector& value) {
210#ifdef TBB_GREATER_EQUAL_2020
211 return values_.emplace(j, value);
213 return values_.insert(std::make_pair(j, value));
220 if (!tryInsert(j, value).second) {
227 if (values_.unsafe_erase(var) == 0)
228 throw std::invalid_argument(
"Requested variable '" +
229 DefaultKeyFormatter(var) +
230 "', is not in this VectorValues.");
254 GTSAM_EXPORT
friend std::ostream& operator<<(std::ostream&,
const VectorValues&);
257 void print(
const std::string& str =
"VectorValues",
258 const KeyFormatter& formatter = DefaultKeyFormatter)
const;
268 Vector vector()
const;
271 template <
typename CONTAINER>
272 Vector
vector(
const CONTAINER& keys)
const {
275 items.reserve(keys.end() - keys.begin());
276 for (
Key key : keys) {
277 const Vector* v = &at(key);
278 totalDim += v->size();
282 Vector result(totalDim);
284 for (
const Vector* v : items) {
285 result.segment(pos, v->size()) = *v;
293 Vector vector(
const Dims& dims)
const;
314 double squaredNorm()
const;
366 const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const;
372 friend class boost::serialization::access;
373 template<
class ARCHIVE>
374 void serialize(ARCHIVE & ar,
const unsigned int ) {
375 ar & BOOST_SERIALIZATION_NVP(values_);
typedef and functions to augment Eigen's VectorXd
A thin wrapper around std::vector that uses a custom allocator.
Variable ordering for the elimination algorithm.
Maps global variable indices to slot indices.
Included from all GTSAM files.
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
FastVector is a type alias to a std::vector with a custom memory allocator.
Definition: FastVector.h:34
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
string html(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of html.
Definition: DiscreteValues.cpp:134
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:106
std::string serialize(const T &input)
serializes to a string
Definition: serialization.h:113
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:156
Errors operator+(const Errors &a, const Errors &b)
Addition.
Definition: Errors.cpp:60
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:47
double dot(const V1 &a, const V2 &b)
Dot product.
Definition: Vector.h:195
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:100
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
Errors operator-(const Errors &a, const Errors &b)
Subtraction.
Definition: Errors.cpp:75
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
Template to create a binary predicate.
Definition: Testable.h:111
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:151
Scatter is an intermediate data structure used when building a HessianFactor incrementally,...
Definition: Scatter.h:49
VectorValues represents a collection of vector-valued variables associated each with a unique integer...
Definition: VectorValues.h:74
value_type KeyValuePair
Typedef to pair<Key, Vector>
Definition: VectorValues.h:85
const_iterator end() const
Iterator over variables.
Definition: VectorValues.h:239
Values::value_type value_type
Typedef to pair<Key, Vector>
Definition: VectorValues.h:84
Values::const_iterator const_iterator
Const iterator over vector values.
Definition: VectorValues.h:82
iterator end()
Iterator over variables.
Definition: VectorValues.h:238
Values::iterator iterator
Iterator over vector values.
Definition: VectorValues.h:81
iterator insert(Key j, const Vector &value)
Insert a vector value with key j.
Definition: VectorValues.h:197
VectorValues(const CONTAINER &c)
Create from another container holding pair<Key,Vector>.
Definition: VectorValues.h:104
Values values_
Vectors making up this VectorValues.
Definition: VectorValues.h:78
std::map< Key, size_t > Dims
Keyed vector dimensions.
Definition: VectorValues.h:86
ConcurrentMap< Key, Vector > Values
Collection of Vectors making up a VectorValues.
Definition: VectorValues.h:77
Vector & operator[](Key j)
Read/write access to the vector value with key j, throws std::out_of_range if j does not exist,...
Definition: VectorValues.h:163
std::pair< VectorValues::iterator, bool > emplace(Key j, Args &&... args)
Emplace a vector value with key j.
Definition: VectorValues.h:185
iterator find(Key j)
Return the iterator corresponding to the requested key, or end() if no variable is present with this ...
Definition: VectorValues.h:245
size_t dim(Key j) const
Return the dimension of variable j.
Definition: VectorValues.h:130
size_t size() const
Number of variables stored.
Definition: VectorValues.h:127
const Vector & operator[](Key j) const
Access the vector value with key j (const version), throws std::out_of_range if j does not exist,...
Definition: VectorValues.h:167
bool exists(Key j) const
Check whether a variable with key j exists.
Definition: VectorValues.h:133
VectorValues()
Default constructor creates an empty VectorValues.
Definition: VectorValues.h:92
const_iterator find(Key j) const
Return the iterator corresponding to the requested key, or end() if no variable is present with this ...
Definition: VectorValues.h:251
VectorValues(ITERATOR first, ITERATOR last)
Create from a pair of iterators over pair<Key,Vector>.
Definition: VectorValues.h:111
const Vector & at(Key j) const
Access the vector value with key j (const version), throws std::out_of_range if j does not exist,...
Definition: VectorValues.h:152
Vector vector(const CONTAINER &keys) const
Access a vector that is a subset of relevant keys.
Definition: VectorValues.h:272
void insert_or_assign(Key j, const Vector &value)
insert_or_assign that mimics the STL map insert_or_assign - if the value already exists,...
Definition: VectorValues.h:219
const_iterator begin() const
Iterator over variables.
Definition: VectorValues.h:237
Vector & at(Key j)
Read/write access to the vector value with key j, throws std::out_of_range if j does not exist,...
Definition: VectorValues.h:139
void erase(Key var)
Erase the vector with the given key, or throw std::out_of_range if it does not exist.
Definition: VectorValues.h:226
VectorValues(std::initializer_list< std::pair< Key, Vector > > init)
Construct from initializer list.
Definition: VectorValues.h:95
std::pair< iterator, bool > tryInsert(Key j, const Vector &value)
insert that mimics the STL map insert - if the value already exists, the map is not modified and an i...
Definition: VectorValues.h:209
VectorValues(const VectorValues &c)
Implicit copy constructor to specialize the explicit constructor from any container.
Definition: VectorValues.h:107
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: VectorValues.h:83
iterator begin()
Iterator over variables.
Definition: VectorValues.h:236
A key-value pair, which you get by dereferencing iterators.
Definition: Values.h:93