23#include <gtsam/base/ConcurrentMap.h>
27#include <boost/shared_ptr.hpp>
86 typedef std::map<Key, size_t>
Dims;
101 template<
class CONTAINER>
102 explicit VectorValues(
const CONTAINER& c) : values_(c.begin(), c.end()) {}
108 template<
typename ITERATOR>
125 size_t size()
const {
return values_.size(); }
128 size_t dim(
Key j)
const {
return at(j).rows(); }
140 throw std::out_of_range(
141 "Requested variable '" + DefaultKeyFormatter(j) +
"' is not in this VectorValues.");
153 throw std::out_of_range(
154 "Requested variable '" + DefaultKeyFormatter(j) +
"' is not in this VectorValues.");
176 iterator insert(
const std::pair<Key, Vector>& key_value);
182 template<
class... Args>
183 inline std::pair<VectorValues::iterator, bool>
emplace(
Key j, Args&&... args) {
184#if ! defined(GTSAM_USE_TBB) || defined (TBB_GREATER_EQUAL_2020)
185 return values_.emplace(std::piecewise_construct, std::forward_as_tuple(j), std::forward_as_tuple(args...));
187 return values_.insert(std::make_pair(j, Vector(std::forward<Args>(args)...)));
196 return insert(std::make_pair(j, value));
207 inline std::pair<iterator, bool>
tryInsert(
Key j,
const Vector& value) {
208#ifdef TBB_GREATER_EQUAL_2020
209 return values_.emplace(j, value);
211 return values_.insert(std::make_pair(j, value));
217 if (values_.unsafe_erase(var) == 0)
218 throw std::invalid_argument(
"Requested variable '" +
219 DefaultKeyFormatter(var) +
220 "', is not in this VectorValues.");
244 GTSAM_EXPORT
friend std::ostream& operator<<(std::ostream&,
const VectorValues&);
247 void print(
const std::string& str =
"VectorValues",
248 const KeyFormatter& formatter = DefaultKeyFormatter)
const;
258 Vector vector()
const;
261 template <
typename CONTAINER>
262 Vector
vector(
const CONTAINER& keys)
const {
264 FastVector<const Vector*> items;
265 items.reserve(keys.end() - keys.begin());
266 for (
Key key : keys) {
267 const Vector* v = &at(key);
268 totalDim += v->size();
272 Vector result(totalDim);
274 for (
const Vector* v : items) {
275 result.segment(pos, v->size()) = *v;
283 Vector vector(
const Dims& dims)
const;
304 double squaredNorm()
const;
357 friend class boost::serialization::access;
358 template<
class ARCHIVE>
359 void serialize(ARCHIVE & ar,
const unsigned int ) {
360 ar & BOOST_SERIALIZATION_NVP(values_);
A thin wrapper around std::vector that uses a custom allocator.
typedef and functions to augment Eigen's VectorXd
Variable ordering for the elimination algorithm.
Maps global variable indices to slot indices.
Included from all GTSAM files.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:75
std::string serialize(const T &input)
serializes to a string
Definition: serialization.h:112
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:155
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:272
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:47
BinarySumExpression< T > operator-(const Expression< T > &e1, const Expression< T > &e2)
Construct an expression that subtracts one expression from another.
Definition: Expression.h:278
double dot(const V1 &a, const V2 &b)
Dot product.
Definition: Vector.h:194
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
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
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
This class represents a collection of vector-valued variables associated each with a unique integer i...
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:229
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:228
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:195
VectorValues(const CONTAINER &c)
Create from another container holding pair<Key,Vector>.
Definition: VectorValues.h:102
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:161
std::pair< VectorValues::iterator, bool > emplace(Key j, Args &&... args)
Emplace a vector value with key j.
Definition: VectorValues.h:183
iterator find(Key j)
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:128
size_t size() const
Number of variables stored.
Definition: VectorValues.h:125
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:165
bool exists(Key j) const
Check whether a variable with key j exists.
Definition: VectorValues.h:131
VectorValues()
Default constructor creates an empty VectorValues.
Definition: VectorValues.h:94
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:241
VectorValues(ITERATOR first, ITERATOR last)
Create from a pair of iterators over pair<Key,Vector>.
Definition: VectorValues.h:109
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:150
Vector vector(const CONTAINER &keys) const
Access a vector that is a subset of relevant keys.
Definition: VectorValues.h:262
const_iterator begin() const
Iterator over variables.
Definition: VectorValues.h:227
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:137
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:216
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:207
VectorValues(const VectorValues &c)
Implicit copy constructor to specialize the explicit constructor from any container.
Definition: VectorValues.h:105
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: VectorValues.h:83
iterator begin()
Iterator over variables.
Definition: VectorValues.h:226
boost::transform_iterator< std::function< ConstKeyValuePair(const ConstKeyValuePtrPair &)>, KeyValueMap::const_iterator > const_iterator
Const forward iterator, with value type ConstKeyValuePair.
Definition: Values.h:117
boost::transform_iterator< std::function< KeyValuePair(const KeyValuePtrPair &)>, KeyValueMap::iterator > iterator
Mutable forward iterator, with value type KeyValuePair.
Definition: Values.h:113
A key-value pair, which you get by dereferencing iterators.
Definition: Values.h:95