Go to the documentation of this file.
25 #pragma clang diagnostic push
26 #pragma clang diagnostic ignored "-Wextra-semi-stmt"
34 merge(first.begin(), first.end(), second.begin(), second.end(), inserter(
values_,
values_.end()),
35 std::bind(&std::less<Key>::operator(), std::less<Key>(), std::bind(&
KeyValuePair::first, std::placeholders::_1),
37 if(
size() != first.size() + second.size())
38 throw std::invalid_argument(
"Requested to merge two VectorValues that have one or more variables in common.");
44 for (
const auto& [
key,
n] : dims) {
45 #ifdef TBB_GREATER_EQUAL_2020
58 #ifdef TBB_GREATER_EQUAL_2020
69 std::map<Key, Vector> ordered;
70 for (
const auto& kv : *
this) ordered.emplace(kv);
79 #ifdef TBB_GREATER_EQUAL_2020
89 const std::pair<iterator, bool>
result =
values_.insert(key_value);
91 throw std::invalid_argument(
93 +
"' already in this VectorValues.");
103 size_t oldSize =
values_.size();
105 if (
values_.size() > oldSize) {
107 throw std::out_of_range(
108 "Requested to update a VectorValues with another VectorValues that "
109 "contains keys not present in the first.");
111 hint->second =
value;
119 size_t originalSize =
size();
122 throw std::invalid_argument(
123 "Requested to insert a VectorValues into another VectorValues that "
124 "already contains one or more of its keys.");
140 for (
const auto& [
key,
value] :
v.sorted())
153 std::cout <<
str <<
": " <<
size() <<
" elements\n";
162 auto this_it = this->begin();
163 auto x_it =
x.begin();
164 for(; this_it != this->
end(); ++this_it, ++x_it) {
165 if(this_it->first != x_it->first ||
176 for (
const auto& [
key,
value] : *
this)
177 totalDim +=
value.size();
186 for (
const auto& [
key,
value] : *
this) {
204 for(
const Dims::value_type& it:
keys) {
205 result.segment(
j,it.second) =
at(it.first);
221 return a.first ==
b.first &&
a.second.size() ==
b.second.size();
238 throw std::invalid_argument(
"VectorValues::dot called with a VectorValues of different structure");
240 auto this_it = this->begin();
241 auto v_it =
v.begin();
242 for(; this_it != this->
end(); ++this_it, ++v_it) {
244 std::invalid_argument(
"VectorValues::dot called with a VectorValues of different structure"));
245 assert_throw(this_it->second.size() == v_it->second.size(),
246 std::invalid_argument(
"VectorValues::dot called with a VectorValues of different structure"));
247 result += this_it->second.dot(v_it->second);
259 double sumSquares = 0.0;
260 for(
const auto& [
key,
value]: *
this) {
261 sumSquares +=
value.squaredNorm();
270 throw std::invalid_argument(
"VectorValues::operator+ called with different vector sizes");
272 std::invalid_argument(
"VectorValues::operator+ called with different vector sizes"));
277 #ifdef TBB_GREATER_EQUAL_2020
278 result.values_.emplace(
j1->first,
j1->second + j2->second);
280 result.values_.insert({
j1->first,
j1->second + j2->second});
296 throw std::invalid_argument(
"VectorValues::operator+= called with different vector sizes");
298 std::invalid_argument(
"VectorValues::operator+= called with different vector sizes"));
304 j1->second += j2->second;
321 it->second = j2->second;
323 it->second += j2->second;
332 throw std::invalid_argument(
"VectorValues::operator- called with different vector sizes");
334 std::invalid_argument(
"VectorValues::operator- called with different vector sizes"));
339 #ifdef TBB_GREATER_EQUAL_2020
340 result.values_.emplace(
j1->first,
j1->second - j2->second);
342 result.values_.insert({
j1->first,
j1->second - j2->second});
358 #ifdef TBB_GREATER_EQUAL_2020
384 return *
this *=
alpha;
389 std::stringstream
ss;
392 ss <<
"<div>\n<table class='VectorValues'>\n <thead>\n";
395 ss <<
" <tr><th>Variable</th><th>value</th></tr>\n";
398 ss <<
" </thead>\n <tbody>\n";
403 for (
const auto& kv :
sorted()) {
405 for (
const auto& kv : *
this) {
408 ss <<
"<th>" << keyFormatter(kv.first) <<
"</th><td>"
409 << kv.second.transpose() <<
"</td>";
412 ss <<
" </tbody>\n</table>\n</div>";
420 #pragma clang diagnostic pop
void print(const std::string &str="VectorValues", const KeyFormatter &formatter=DefaultKeyFormatter) const
VectorValues & scaleInPlace(double alpha)
std::map< Key, size_t > Dims
Keyed vector dimensions.
#define assert_throw(CONDITION, EXCEPTION)
std::ostream & operator<<(std::ostream &os, const Dih6 &m)
iterator insert(const std::pair< Key, Vector > &key_value)
std::string html(const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Output as a html table.
Values::iterator iterator
Iterator over vector values.
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Values values_
Vectors making up this VectorValues.
bool hasSameStructure(const VectorValues other) const
VectorValues & operator+=(const VectorValues &c)
const KeyFormatter & formatter
bool equal_with_abs_tol(const Eigen::DenseBase< MATRIX > &A, const Eigen::DenseBase< MATRIX > &B, double tol=1e-9)
double dot(const VectorValues &v) const
ofstream os("timeSchurFactors.csv")
friend GTSAM_EXPORT VectorValues operator*(const double a, const VectorValues &v)
VectorValues()
Default constructor creates an empty VectorValues.
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
VectorValues & addInPlace(const VectorValues &c)
static std::stringstream ss
std::map< Key, Vector > sorted() const
Values::const_iterator const_iterator
Const iterator over vector values.
VectorValues & addInPlace_(const VectorValues &c)
VectorValues subtract(const VectorValues &c) const
deref_iterator end() const
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
VectorValues & update(const VectorValues &values)
VectorValues scale(const double a) const
double squaredNorm() const
EIGEN_CONSTEXPR Index first(const T &x) EIGEN_NOEXCEPT
static VectorValues Zero(const VectorValues &other)
std::pair< iterator, bool > tryInsert(Key j, const Vector &value)
void unsafe_erase(typename Base::iterator position)
VectorValues operator+(const VectorValues &c) const
bool structureCompareOp(const VectorValues::value_type &a, const VectorValues::value_type &b)
VectorValues operator-(const VectorValues &c) const
const gtsam::Symbol key('X', 0)
deref_iterator begin() const
To use the key_formatter on Keys, they must be wrapped in a StreamedKey.
bool equals(const VectorValues &x, double tol=1e-9) const
ptrdiff_t DenseIndex
The index type for Eigen objects.
Array< int, Dynamic, 1 > v
VectorValues & operator*=(double alpha)
static const EIGEN_DEPRECATED end_t end
One SlotEntry stores the slot index for a variable, as well its dim.
VectorValues add(const VectorValues &c) const
void swap(VectorValues &other)
bool equal(const T &obj1, const T &obj2, double tol)
Jet< T, N > sqrt(const Jet< T, N > &f)
Values::value_type value_type
Typedef to pair<Key, Vector>
gtsam
Author(s):
autogenerated on Thu Jun 13 2024 03:11:31