21 #include <gtsam/base/ConcurrentMap.h>
26 #include <boost/shared_ptr.hpp>
103 typedef std::map<Key,size_t> Dims;
117 template<
class CONTAINER>
118 explicit VectorValues(
const CONTAINER& c) : values_(c.begin(), c.end()) {}
124 template<
typename ITERATOR>
141 size_t dim(
Key j)
const {
return at(j).rows(); }
150 throw std::out_of_range(
151 "Requested variable '" + DefaultKeyFormatter(j) +
"' is not in this VectorValues.");
160 throw std::out_of_range(
161 "Requested variable '" + DefaultKeyFormatter(j) +
"' is not in this VectorValues.");
184 return insert(std::make_pair(j, value));
194 std::pair<iterator, bool> result = values_.insert(key_value);
196 throw std::invalid_argument(
197 "Requested to insert variable '" + DefaultKeyFormatter(key_value.first)
198 +
"' already in this VectorValues.");
211 return values_.insert(std::make_pair(j, value)); }
215 if(values_.unsafe_erase(var) == 0)
216 throw std::invalid_argument(
"Requested variable '" + DefaultKeyFormatter(var) +
"', is not in this VectorValues.");
238 void print(
const std::string& str =
"VectorValues: ",
239 const KeyFormatter& formatter = DefaultKeyFormatter)
const;
249 Vector vector()
const;
255 Vector vector(
const Dims& dims)
const;
276 double squaredNorm()
const;
377 friend class boost::serialization::access;
378 template<
class ARCHIVE>
379 void serialize(ARCHIVE & ar,
const unsigned int version) {
380 ar & BOOST_SERIALIZATION_NVP(values_);
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:214
Values::iterator iterator
Iterator over vector values.
Definition: VectorValues.h:96
VectorValues(ITERATOR first, ITERATOR last)
Create from a pair of iterators over pair<Key,Vector>.
Definition: VectorValues.h:125
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:147
typedef and functions to augment Eigen's VectorXd
double dot(const V1 &a, const V2 &b)
Dot product.
Definition: Vector.h:259
const_iterator begin() const
Iterator over variables.
Definition: VectorValues.h:223
iterator find(Key j)
Return the iterator corresponding to the requested key, or end() if no variable is present with this ...
Definition: VectorValues.h:232
iterator insert(const std::pair< Key, Vector > &key_value)
Insert a vector value with key j.
Definition: VectorValues.h:191
Values values_
Collection of Vectors making up this VectorValues.
Definition: VectorValues.h:93
Values::const_iterator const_iterator
Const iterator over vector values.
Definition: VectorValues.h:97
ConcurrentMap< Key, Vector > Values
Typedef for the collection of Vectors making up a VectorValues.
Definition: VectorValues.h:92
Included from all GTSAM files.
Values::value_type value_type
Typedef to pair<Key, Vector>, a key-value pair.
Definition: VectorValues.h:101
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:249
const_iterator end() const
Iterator over variables.
Definition: VectorValues.h:225
Key size() const
Number of variables stored.
Definition: VectorValues.h:138
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: VectorValues.h:100
void print(const Matrix &A, const string &s, ostream &stream)
print a matrix
Definition: Matrix.cpp:183
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:157
iterator begin()
Iterator over variables.
Definition: VectorValues.h:222
VectorValues(const VectorValues &c)
Implicit copy constructor to specialize the explicit constructor from any container.
Definition: VectorValues.h:121
Template to create a binary predicate.
Definition: Testable.h:102
size_t Key
Integer nonlinear key type.
Definition: types.h:59
VectorValues(const CONTAINER &c)
Create from another container holding pair<Key,Vector>.
Definition: VectorValues.h:118
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:172
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:89
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:235
size_t dim(Key j) const
Return the dimension of variable j.
Definition: VectorValues.h:141
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:168
bool exists(Key j) const
Check whether a variable with key j exists.
Definition: VectorValues.h:144
iterator insert(Key j, const Vector &value)
Insert a vector value with key j.
Definition: VectorValues.h:183
iterator end()
Iterator over variables.
Definition: VectorValues.h:224
VectorValues()
Default constructor creates an empty VectorValues.
Definition: VectorValues.h:111
A key-value pair, which you get by dereferencing iterators.
Definition: Values.h:106
boost::transform_iterator< boost::function1< ConstKeyValuePair, const ConstKeyValuePtrPair & >, KeyValueMap::const_iterator > const_iterator
Const forward iterator, with value type ConstKeyValuePair.
Definition: Values.h:128
value_type KeyValuePair
Typedef to pair<Key, Vector>, a key-value pair.
Definition: VectorValues.h:102
boost::transform_iterator< boost::function1< KeyValuePair, const KeyValuePtrPair & >, KeyValueMap::iterator > iterator
Mutable forward iterator, with value type KeyValuePair.
Definition: Values.h:124
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:210
A thin wrapper around std::vector that uses boost's pool_allocator.
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: types.h:62