23 #include <gtsam/base/ConcurrentMap.h> 27 #include <boost/shared_ptr.hpp> 85 typedef std::map<Key, size_t>
Dims;
100 template<
class CONTAINER>
101 explicit VectorValues(
const CONTAINER& c) : values_(c.begin(), c.end()) {}
107 template<
typename ITERATOR>
124 size_t size()
const {
return values_.size(); }
127 size_t dim(
Key j)
const {
return at(j).rows(); }
139 throw std::out_of_range(
140 "Requested variable '" + DefaultKeyFormatter(j) +
"' is not in this VectorValues.");
152 throw std::out_of_range(
153 "Requested variable '" + DefaultKeyFormatter(j) +
"' is not in this VectorValues.");
175 iterator insert(
const std::pair<Key, Vector>& key_value);
181 iterator emplace(
Key j,
const Vector& value);
188 return insert(std::make_pair(j, value));
200 return values_.emplace(j, value);
205 if (values_.unsafe_erase(var) == 0)
206 throw std::invalid_argument(
"Requested variable '" +
207 DefaultKeyFormatter(var) +
208 "', is not in this VectorValues.");
232 void print(
const std::string& str =
"VectorValues: ",
233 const KeyFormatter& formatter = DefaultKeyFormatter)
const;
243 Vector vector()
const;
246 template <
typename CONTAINER>
247 Vector
vector(
const CONTAINER& keys)
const {
249 FastVector<const Vector*> items;
250 items.reserve(keys.end() - keys.begin());
251 for (
Key key : keys) {
252 const Vector* v = &at(key);
253 totalDim += v->size();
257 Vector result(totalDim);
259 for (
const Vector* v : items) {
260 result.segment(pos, v->size()) = *v;
268 Vector vector(
const Dims& dims)
const;
289 double squaredNorm()
const;
342 friend class boost::serialization::access;
343 template<
class ARCHIVE>
344 void serialize(ARCHIVE & ar,
const unsigned int ) {
345 ar & BOOST_SERIALIZATION_NVP(values_);
Values::value_type value_type
Typedef to pair<Key, Vector>
Definition: VectorValues.h:83
Values::const_iterator const_iterator
Const iterator over vector values.
Definition: VectorValues.h:81
VectorValues(const CONTAINER &c)
Create from another container holding pair<Key,Vector>.
Definition: VectorValues.h:101
double dot(const V1 &a, const V2 &b)
Dot product.
Definition: Vector.h:162
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:63
VectorValues()
Default constructor creates an empty VectorValues.
Definition: VectorValues.h:93
boost::transform_iterator< boost::function1< ConstKeyValuePair, const ConstKeyValuePtrPair & >, KeyValueMap::const_iterator > const_iterator
Const forward iterator, with value type ConstKeyValuePair.
Definition: Values.h:123
Maps global variable indices to slot indices.
A thin wrapper around std::vector that uses a custom allocator.
size_t dim(Key j) const
Return the dimension of variable j.
Definition: VectorValues.h:127
const_iterator end() const
Iterator over variables.
Definition: VectorValues.h:217
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:141
Values values_
Vectors making up this VectorValues.
Definition: VectorValues.h:77
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
ConcurrentMap< Key, Vector > Values
Collection of Vectors making up a VectorValues.
Definition: VectorValues.h:76
Values::iterator iterator
Iterator over vector values.
Definition: VectorValues.h:80
Template to create a binary predicate.
Definition: Testable.h:110
bool exists(Key j) const
Check whether a variable with key j exists.
Definition: VectorValues.h:130
Variable ordering for the elimination algorithm.
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:229
BinarySumExpression< T > operator-(const Expression< T > &e1, const Expression< T > &e2)
Construct an expression that subtracts one expression from another.
Definition: Expression.h:279
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:149
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
Included from all GTSAM files.
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:164
Vector vector(const CONTAINER &keys) const
Access a vector that is a subset of relevant keys.
Definition: VectorValues.h:247
iterator end()
Iterator over variables.
Definition: VectorValues.h:216
const_iterator begin() const
Iterator over variables.
Definition: VectorValues.h:215
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:33
boost::transform_iterator< boost::function1< KeyValuePair, const KeyValuePtrPair & >, KeyValueMap::iterator > iterator
Mutable forward iterator, with value type KeyValuePair.
Definition: Values.h:119
std::map< Key, size_t > Dims
Keyed vector dimensions.
Definition: VectorValues.h:85
This class represents a collection of vector-valued variables associated each with a unique integer i...
Definition: VectorValues.h:73
A key-value pair, which you get by dereferencing iterators.
Definition: Values.h:101
Scatter is an intermediate data structure used when building a HessianFactor incrementally,...
Definition: Scatter.h:51
value_type KeyValuePair
Typedef to pair<Key, Vector>
Definition: VectorValues.h:84
iterator insert(Key j, const Vector &value)
Insert a vector value with key j.
Definition: VectorValues.h:187
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
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:204
size_t size() const
Number of variables stored.
Definition: VectorValues.h:124
VectorValues(ITERATOR first, ITERATOR last)
Create from a pair of iterators over pair<Key,Vector>.
Definition: VectorValues.h:108
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
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:160
iterator begin()
Iterator over variables.
Definition: VectorValues.h:214
BinarySumExpression< T > operator+(const Expression< T > &e1, const Expression< T > &e2)
Construct an expression that sums two input expressions of the same type T The type T must be a vecto...
Definition: Expression.h:273
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: VectorValues.h:82
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:199
VectorValues(const VectorValues &c)
Implicit copy constructor to specialize the explicit constructor from any container.
Definition: VectorValues.h:104
typedef and functions to augment Eigen's VectorXd
iterator find(Key j)
Return the iterator corresponding to the requested key, or end() if no variable is present with this ...
Definition: VectorValues.h:223
Point2 operator *(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:170
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:136