22#include <gtsam/base/ConcurrentMap.h>
85 typedef std::map<Key, size_t>
Dims;
102 template<
class CONTAINER>
109 template<
typename ITERATOR>
144 throw std::out_of_range(
157 throw std::out_of_range(
180 iterator insert(
const std::pair<Key, Vector>& key_value);
186 template<
class... Args>
187 inline std::pair<VectorValues::iterator, bool>
emplace(
Key j, Args&&... args) {
188#if ! defined(GTSAM_USE_TBB) || defined (TBB_GREATER_EQUAL_2020)
189 return values_.emplace(std::piecewise_construct, std::forward_as_tuple(j), std::forward_as_tuple(args...));
191 return values_.insert({j, Vector(std::forward<Args>(args)...)});
200 return insert({j, value});
222 inline std::pair<iterator, bool>
tryInsert(
Key j,
const Vector& value) {
223#ifdef TBB_GREATER_EQUAL_2020
224 return values_.emplace(j, value);
226 return values_.insert({j, value});
240 if (
values_.unsafe_erase(var) == 0)
241 throw std::invalid_argument(
"Requested variable '" +
243 "', is not in this VectorValues.");
267 GTSAM_EXPORT
friend std::ostream& operator<<(std::ostream&,
const VectorValues&);
270 void print(
const std::string& str =
"VectorValues",
281 Vector vector()
const;
284 template <
typename CONTAINER>
287 for (
Key key : keys) {
294 template <
typename CONTAINER,
typename Derived>
296 const Eigen::MatrixBase<Derived>& result)
const {
297 auto& writable =
const_cast<Eigen::MatrixBase<Derived>&
>(result);
299 for (
Key key : keys) {
300 const Vector& v =
at(key);
301 writable.segment(pos, v.size()) = v;
307 template <
typename CONTAINER>
308 Vector
vector(
const CONTAINER& keys)
const {
311 items.reserve(keys.size());
312 for (
Key key : keys) {
313 const Vector* v = &
at(key);
315 items.emplace_back(v);
320 for (
const Vector* v : items) {
321 result.segment(pos, v->size()) = *v;
329 Vector vector(
const Dims& dims)
const;
350 double squaredNorm()
const;
392 std::map<Key, const Vector&> sorted()
const;
410#if GTSAM_ENABLE_BOOST_SERIALIZATION
412 friend class boost::serialization::access;
413 template<
class ARCHIVE>
414 void serialize(ARCHIVE & ar,
const unsigned int ) {
415 ar & BOOST_SERIALIZATION_NVP(values_);
A thin wrapper around std::vector that uses a custom allocator.
typedef and functions to augment Eigen's VectorXd
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:33
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:160
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition types.h:49
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:91
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:143
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition Point2.h:52
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
double dot(const V1 &a, const V2 &b)
Dot product.
Definition Vector.h:191
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
Errors operator-(const Errors &a, const Errors &b)
Subtraction.
Definition Errors.cpp:74
FastMap is a thin wrapper around std::map that uses the boost fast_pool_allocator instead of the defa...
Definition ConcurrentMap.h:69
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
Template to create a binary predicate.
Definition Testable.h:112
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
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:73
iterator insert(const std::pair< Key, Vector > &key_value)
Insert a vector value with key j.
Definition VectorValues.cpp:90
value_type KeyValuePair
Typedef to pair<Key, Vector>.
Definition VectorValues.h:84
void fillVector(const CONTAINER &keys, const Eigen::MatrixBase< Derived > &result) const
Fill a preallocated Eigen vector expression with a subset of relevant keys.
Definition VectorValues.h:295
const_iterator end() const
Iterator over variables.
Definition VectorValues.h:252
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
iterator end()
Iterator over variables.
Definition VectorValues.h:251
DenseIndex totalDim(const CONTAINER &keys) const
Compute the total dimension of a subset of relevant keys.
Definition VectorValues.h:285
Values::iterator iterator
Iterator over vector values.
Definition VectorValues.h:80
iterator insert(Key j, const Vector &value)
Insert a vector value with key j.
Definition VectorValues.h:199
VectorValues(const CONTAINER &c)
Create from another container holding pair<Key,Vector>.
Definition VectorValues.h:103
Values values_
Vectors making up this VectorValues.
Definition VectorValues.h:77
std::map< Key, size_t > Dims
Keyed vector dimensions.
Definition VectorValues.h:85
ConcurrentMap< Key, Vector > Values
Collection of Vectors making up a VectorValues.
Definition VectorValues.h:76
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:165
std::pair< VectorValues::iterator, bool > emplace(Key j, Args &&... args)
Emplace a vector value with key j.
Definition VectorValues.h:187
iterator find(Key j)
Return the iterator corresponding to the requested key, or end() if no variable is present with this ...
Definition VectorValues.h:258
size_t dim(Key j) const
Return the dimension of variable j.
Definition VectorValues.h:132
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition VectorValues.h:82
size_t size() const
Number of variables stored.
Definition VectorValues.h:129
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:169
bool exists(Key j) const
Check whether a variable with key j exists.
Definition VectorValues.h:135
VectorValues()
Default constructor creates an empty VectorValues.
Definition VectorValues.h:91
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:264
VectorValues(ITERATOR first, ITERATOR last)
Create from a pair of iterators over pair<Key,Vector>.
Definition VectorValues.h:110
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:154
Vector vector(const CONTAINER &keys) const
Access a vector that is a subset of relevant keys.
Definition VectorValues.h:308
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:232
const_iterator begin() const
Iterator over variables.
Definition VectorValues.h:250
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:141
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:239
VectorValues(std::initializer_list< std::pair< Key, Vector > > init)
Construct from initializer list.
Definition VectorValues.h:94
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:222
VectorValues(const VectorValues &c)
Copy constructor to specialize the explicit constructor from any container.
Definition VectorValues.h:106
iterator begin()
Iterator over variables.
Definition VectorValues.h:249