Public Types | Protected Types | Protected Member Functions | Protected Attributes | List of all members
gtsam::VectorValues Class Reference

#include <VectorValues.h>

Public Types

typedef Values::const_iterator const_iterator
 Const iterator over vector values. More...
 
typedef std::map< Key, size_tDims
 Keyed vector dimensions. More...
 
typedef Values::iterator iterator
 Iterator over vector values. More...
 
typedef value_type KeyValuePair
 Typedef to pair<Key, Vector> More...
 
typedef std::shared_ptr< Thisshared_ptr
 shared_ptr to this class More...
 
typedef Values::value_type value_type
 Typedef to pair<Key, Vector> More...
 

Public Member Functions

Advanced Interface
Vector vector () const
 
template<typename CONTAINER >
Vector vector (const CONTAINER &keys) const
 
Vector vector (const Dims &dims) const
 
void swap (VectorValues &other)
 
bool hasSameStructure (const VectorValues other) const
 
Wrapper support
std::string html (const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
 Output as a html table. More...
 

Protected Types

typedef VectorValues This
 
typedef ConcurrentMap< Key, VectorValues
 Collection of Vectors making up a VectorValues. More...
 

Protected Member Functions

std::map< Key, Vectorsorted () const
 

Protected Attributes

Values values_
 Vectors making up this VectorValues. More...
 

Standard Constructors

 VectorValues ()
 Default constructor creates an empty VectorValues. More...
 
 VectorValues (std::initializer_list< std::pair< Key, Vector >> init)
 Construct from initializer list. More...
 
 VectorValues (const VectorValues &first, const VectorValues &second)
 
template<class CONTAINER >
 VectorValues (const CONTAINER &c)
 
 VectorValues (const VectorValues &c)
 
template<typename ITERATOR >
 VectorValues (ITERATOR first, ITERATOR last)
 
 VectorValues (const Vector &c, const Dims &dims)
 Constructor from Vector, with Dims. More...
 
 VectorValues (const Vector &c, const Scatter &scatter)
 Constructor from Vector, with Scatter. More...
 
static VectorValues Zero (const VectorValues &other)
 

Standard Interface

size_t size () const
 
size_t dim (Key j) const
 
bool exists (Key j) const
 
Vectorat (Key j)
 
const Vectorat (Key j) const
 
Vectoroperator[] (Key j)
 
const Vectoroperator[] (Key j) const
 
VectorValuesupdate (const VectorValues &values)
 
iterator insert (const std::pair< Key, Vector > &key_value)
 
template<class... Args>
std::pair< VectorValues::iterator, bool > emplace (Key j, Args &&... args)
 
iterator insert (Key j, const Vector &value)
 
VectorValuesinsert (const VectorValues &values)
 
std::pair< iterator, bool > tryInsert (Key j, const Vector &value)
 
void insert_or_assign (Key j, const Vector &value)
 
void erase (Key var)
 
void setZero ()
 
iterator find (Key j)
 
const_iterator find (Key j) const
 
void print (const std::string &str="VectorValues", const KeyFormatter &formatter=DefaultKeyFormatter) const
 
bool equals (const VectorValues &x, double tol=1e-9) const
 
GTSAM_EXPORT friend std::ostream & operator<< (std::ostream &, const VectorValues &)
 overload operator << to print to stringstream More...
 

Linear algebra operations

double dot (const VectorValues &v) const
 
double norm () const
 
double squaredNorm () const
 
VectorValues operator+ (const VectorValues &c) const
 
VectorValues add (const VectorValues &c) const
 
VectorValuesoperator+= (const VectorValues &c)
 
VectorValuesaddInPlace (const VectorValues &c)
 
VectorValuesaddInPlace_ (const VectorValues &c)
 
VectorValues operator- (const VectorValues &c) const
 
VectorValues subtract (const VectorValues &c) const
 
VectorValues scale (const double a) const
 
VectorValuesoperator*= (double alpha)
 
VectorValuesscaleInPlace (double alpha)
 
GTSAM_EXPORT VectorValues operator* (const double a, const VectorValues &v)
 

Detailed Description

VectorValues represents a collection of vector-valued variables associated each with a unique integer index. It is typically used to store the variables of a GaussianFactorGraph. Optimizing a GaussianFactorGraph or GaussianBayesNet returns this class.

For basic usage, such as receiving a linear solution from gtsam solving functions, or creating this class in unit tests and examples where speed is not important, you can use a simple interface:

Example:

values.emplace(3, Vector3(1.0, 2.0, 3.0));
values.emplace(4, Vector2(4.0, 5.0));
values.emplace(0, (Vector(4) << 6.0, 7.0, 8.0, 9.0).finished());
// Prints [ 3.0 4.0 ]
// Prints [ 8.0 9.0 ]
values[1] = Vector2(8.0, 9.0);

Advanced Interface and Performance Information

Access is through the variable Key j, and returns a SubVector, which is a view on the underlying data structure.

This class is additionally used in gradient descent and dog leg to store the gradient.

Definition at line 74 of file VectorValues.h.

Member Typedef Documentation

◆ const_iterator

typedef Values::const_iterator gtsam::VectorValues::const_iterator

Const iterator over vector values.

Definition at line 85 of file VectorValues.h.

◆ Dims

typedef std::map<Key, size_t> gtsam::VectorValues::Dims

Keyed vector dimensions.

Definition at line 89 of file VectorValues.h.

◆ iterator

typedef Values::iterator gtsam::VectorValues::iterator

Iterator over vector values.

Definition at line 84 of file VectorValues.h.

◆ KeyValuePair

Typedef to pair<Key, Vector>

Definition at line 88 of file VectorValues.h.

◆ shared_ptr

typedef std::shared_ptr<This> gtsam::VectorValues::shared_ptr

shared_ptr to this class

Definition at line 86 of file VectorValues.h.

◆ This

Definition at line 76 of file VectorValues.h.

◆ value_type

typedef Values::value_type gtsam::VectorValues::value_type

Typedef to pair<Key, Vector>

Definition at line 87 of file VectorValues.h.

◆ Values

Collection of Vectors making up a VectorValues.

Definition at line 77 of file VectorValues.h.

Constructor & Destructor Documentation

◆ VectorValues() [1/8]

gtsam::VectorValues::VectorValues ( )
inline

Default constructor creates an empty VectorValues.

Definition at line 95 of file VectorValues.h.

◆ VectorValues() [2/8]

gtsam::VectorValues::VectorValues ( std::initializer_list< std::pair< Key, Vector >>  init)
inline

Construct from initializer list.

Definition at line 98 of file VectorValues.h.

◆ VectorValues() [3/8]

VectorValues::VectorValues ( const VectorValues first,
const VectorValues second 
)

Merge two VectorValues into one, this is more efficient than inserting elements one by one.

Definition at line 33 of file VectorValues.cpp.

◆ VectorValues() [4/8]

template<class CONTAINER >
gtsam::VectorValues::VectorValues ( const CONTAINER &  c)
inlineexplicit

Create from another container holding pair<Key,Vector>.

Definition at line 107 of file VectorValues.h.

◆ VectorValues() [5/8]

gtsam::VectorValues::VectorValues ( const VectorValues c)
inline

Implicit copy constructor to specialize the explicit constructor from any container.

Definition at line 110 of file VectorValues.h.

◆ VectorValues() [6/8]

template<typename ITERATOR >
gtsam::VectorValues::VectorValues ( ITERATOR  first,
ITERATOR  last 
)
inline

Create from a pair of iterators over pair<Key,Vector>.

Definition at line 114 of file VectorValues.h.

◆ VectorValues() [7/8]

VectorValues::VectorValues ( const Vector c,
const Dims dims 
)

Constructor from Vector, with Dims.

Definition at line 44 of file VectorValues.cpp.

◆ VectorValues() [8/8]

VectorValues::VectorValues ( const Vector c,
const Scatter scatter 
)

Constructor from Vector, with Scatter.

Definition at line 57 of file VectorValues.cpp.

Member Function Documentation

◆ add()

VectorValues VectorValues::add ( const VectorValues c) const

Element-wise addition, synonym for operator+(). Both VectorValues must have the same structure (checked when NDEBUG is not defined).

Definition at line 289 of file VectorValues.cpp.

◆ addInPlace()

VectorValues & VectorValues::addInPlace ( const VectorValues c)

Element-wise addition in-place, synonym for operator+=(). Both VectorValues must have the same structure (checked when NDEBUG is not defined).

Definition at line 312 of file VectorValues.cpp.

◆ addInPlace_()

VectorValues & VectorValues::addInPlace_ ( const VectorValues c)

Element-wise addition in-place, but allows for empty slots in *this. Slower

Definition at line 318 of file VectorValues.cpp.

◆ at() [1/2]

Vector& gtsam::VectorValues::at ( Key  j)
inline

Read/write access to the vector value with key j, throws std::out_of_range if j does not exist, identical to operator[](Key).

Definition at line 142 of file VectorValues.h.

◆ at() [2/2]

const Vector& gtsam::VectorValues::at ( Key  j) const
inline

Access the vector value with key j (const version), throws std::out_of_range if j does not exist, identical to operator[](Key).

Definition at line 155 of file VectorValues.h.

◆ dim()

size_t gtsam::VectorValues::dim ( Key  j) const
inline

Return the dimension of variable j.

Definition at line 133 of file VectorValues.h.

◆ dot()

double VectorValues::dot ( const VectorValues v) const

Dot product with another VectorValues, interpreting both as vectors of their concatenated values. Both VectorValues must have the same structure (checked when NDEBUG is not defined).

Definition at line 237 of file VectorValues.cpp.

◆ emplace()

template<class... Args>
std::pair<VectorValues::iterator, bool> gtsam::VectorValues::emplace ( Key  j,
Args &&...  args 
)
inline

Emplace a vector value with key j. Throws an invalid_argument exception if the key j is already used.

Parameters
valueThe vector to be inserted.
jThe index with which the value will be associated.

Definition at line 188 of file VectorValues.h.

◆ equals()

bool VectorValues::equals ( const VectorValues x,
double  tol = 1e-9 
) const

equals required by Testable for unit testing

Definition at line 161 of file VectorValues.cpp.

◆ erase()

void gtsam::VectorValues::erase ( Key  var)
inline

Erase the vector with the given key, or throw std::out_of_range if it does not exist

Definition at line 229 of file VectorValues.h.

◆ exists()

bool gtsam::VectorValues::exists ( Key  j) const
inline

Check whether a variable with key j exists.

Definition at line 136 of file VectorValues.h.

◆ find() [1/2]

iterator gtsam::VectorValues::find ( Key  j)
inline

Return the iterator corresponding to the requested key, or end() if no variable is present with this key.

Definition at line 248 of file VectorValues.h.

◆ find() [2/2]

const_iterator gtsam::VectorValues::find ( Key  j) const
inline

Return the iterator corresponding to the requested key, or end() if no variable is present with this key.

Definition at line 254 of file VectorValues.h.

◆ hasSameStructure()

bool VectorValues::hasSameStructure ( const VectorValues  other) const

Check if this VectorValues has the same structure (keys and dimensions) as another

Definition at line 228 of file VectorValues.cpp.

◆ html()

std::string VectorValues::html ( const KeyFormatter keyFormatter = DefaultKeyFormatter) const

Output as a html table.

Parameters
keyFormatterfunction that formats keys.

Definition at line 390 of file VectorValues.cpp.

◆ insert() [1/3]

VectorValues::iterator VectorValues::insert ( const std::pair< Key, Vector > &  key_value)

Insert a vector value with key j. Throws an invalid_argument exception if the key j is already used.

Parameters
valueThe vector to be inserted.
jThe index with which the value will be associated.

Definition at line 90 of file VectorValues.cpp.

◆ insert() [2/3]

VectorValues & VectorValues::insert ( const VectorValues values)

Insert all values from values. Throws an invalid_argument exception if any keys to be inserted are already used.

Definition at line 120 of file VectorValues.cpp.

◆ insert() [3/3]

iterator gtsam::VectorValues::insert ( Key  j,
const Vector value 
)
inline

Insert a vector value with key j. Throws an invalid_argument exception if the key j is already used.

Parameters
valueThe vector to be inserted.
jThe index with which the value will be associated.

Definition at line 200 of file VectorValues.h.

◆ insert_or_assign()

void gtsam::VectorValues::insert_or_assign ( Key  j,
const Vector value 
)
inline

insert_or_assign that mimics the STL map insert_or_assign - if the value already exists, the map is updated, otherwise a new value is inserted at j.

Definition at line 222 of file VectorValues.h.

◆ norm()

double VectorValues::norm ( ) const

Vector L2 norm

Definition at line 255 of file VectorValues.cpp.

◆ operator*=()

VectorValues & VectorValues::operator*= ( double  alpha)

Element-wise scaling by a constant in-place.

Definition at line 375 of file VectorValues.cpp.

◆ operator+()

VectorValues VectorValues::operator+ ( const VectorValues c) const

Element-wise addition, synonym for add(). Both VectorValues must have the same structure (checked when NDEBUG is not defined).

Definition at line 269 of file VectorValues.cpp.

◆ operator+=()

VectorValues & VectorValues::operator+= ( const VectorValues c)

Element-wise addition in-place, synonym for operator+=(). Both VectorValues must have the same structure (checked when NDEBUG is not defined).

Definition at line 295 of file VectorValues.cpp.

◆ operator-()

VectorValues VectorValues::operator- ( const VectorValues c) const

Element-wise subtraction, synonym for subtract(). Both VectorValues must have the same structure (checked when NDEBUG is not defined).

Definition at line 331 of file VectorValues.cpp.

◆ operator[]() [1/2]

Vector& gtsam::VectorValues::operator[] ( Key  j)
inline

Read/write access to the vector value with key j, throws std::out_of_range if j does not exist, identical to at(Key).

Definition at line 166 of file VectorValues.h.

◆ operator[]() [2/2]

const Vector& gtsam::VectorValues::operator[] ( Key  j) const
inline

Access the vector value with key j (const version), throws std::out_of_range if j does not exist, identical to at(Key).

Definition at line 170 of file VectorValues.h.

◆ print()

void VectorValues::print ( const std::string &  str = "VectorValues",
const KeyFormatter formatter = DefaultKeyFormatter 
) const

print required by Testable for unit testing

Definition at line 153 of file VectorValues.cpp.

◆ scale()

VectorValues VectorValues::scale ( const double  a) const

Element-wise scaling by a constant.

Definition at line 369 of file VectorValues.cpp.

◆ scaleInPlace()

VectorValues & VectorValues::scaleInPlace ( double  alpha)

Element-wise scaling by a constant in-place.

Definition at line 384 of file VectorValues.cpp.

◆ setZero()

void VectorValues::setZero ( )

Set all values to zero vectors.

Definition at line 131 of file VectorValues.cpp.

◆ size()

size_t gtsam::VectorValues::size ( ) const
inline

Number of variables stored.

Definition at line 130 of file VectorValues.h.

◆ sorted()

std::map< Key, Vector > VectorValues::sorted ( ) const
protected

Sort by key (primarily for use with TBB, which uses an unordered map)

Definition at line 70 of file VectorValues.cpp.

◆ squaredNorm()

double VectorValues::squaredNorm ( ) const

Squared vector L2 norm

Definition at line 260 of file VectorValues.cpp.

◆ subtract()

VectorValues VectorValues::subtract ( const VectorValues c) const

Element-wise subtraction, synonym for operator-(). Both VectorValues must have the same structure (checked when NDEBUG is not defined).

Definition at line 351 of file VectorValues.cpp.

◆ swap()

void VectorValues::swap ( VectorValues other)

Swap the data in this VectorValues with another.

Definition at line 214 of file VectorValues.cpp.

◆ tryInsert()

std::pair<iterator, bool> gtsam::VectorValues::tryInsert ( Key  j,
const Vector value 
)
inline

insert that mimics the STL map insert - if the value already exists, the map is not modified and an iterator to the existing value is returned, along with 'false'. If the value did not exist, it is inserted and an iterator pointing to the new element, along with 'true', is returned.

Definition at line 212 of file VectorValues.h.

◆ update()

VectorValues & VectorValues::update ( const VectorValues values)

For all key/value pairs in values, replace values with corresponding keys in this class with those in values. Throws std::out_of_range if any keys in values are not present in this class.

Definition at line 100 of file VectorValues.cpp.

◆ vector() [1/3]

Vector VectorValues::vector ( ) const

Retrieve the entire solution as a single vector

Definition at line 175 of file VectorValues.cpp.

◆ vector() [2/3]

template<typename CONTAINER >
Vector gtsam::VectorValues::vector ( const CONTAINER &  keys) const
inline

Access a vector that is a subset of relevant keys.

Definition at line 275 of file VectorValues.h.

◆ vector() [3/3]

Vector VectorValues::vector ( const Dims dims) const

Access a vector that is a subset of relevant keys, dims version.

Definition at line 198 of file VectorValues.cpp.

◆ Zero()

VectorValues VectorValues::Zero ( const VectorValues other)
static

Create a VectorValues with the same structure as other, but filled with zeros.

Definition at line 77 of file VectorValues.cpp.

Friends And Related Function Documentation

◆ operator*

GTSAM_EXPORT VectorValues operator* ( const double  a,
const VectorValues v 
)
friend

Element-wise scaling by a constant.

Definition at line 357 of file VectorValues.cpp.

◆ operator<<

GTSAM_EXPORT friend std::ostream& operator<< ( std::ostream &  os,
const VectorValues v 
)
friend

overload operator << to print to stringstream

Definition at line 139 of file VectorValues.cpp.

Member Data Documentation

◆ values_

Values gtsam::VectorValues::values_
protected

Vectors making up this VectorValues.

Definition at line 78 of file VectorValues.h.


The documentation for this class was generated from the following files:
VectorValues
gtsam::Vector2
Eigen::Vector2d Vector2
Definition: Vector.h:42
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
gtsam::Vector3
Eigen::Vector3d Vector3
Definition: Vector.h:43
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:38
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:16:35