Go to the documentation of this file.
25 #if defined(__clang__)
26 #pragma clang diagnostic push
27 #pragma clang diagnostic ignored "-Wextra-semi-stmt"
36 merge(first.begin(), first.end(), second.begin(), second.end(), inserter(
values_,
values_.end()),
37 std::bind(&std::less<Key>::operator(), std::less<Key>(), std::bind(&
KeyValuePair::first, std::placeholders::_1),
39 if(
size() != first.size() + second.size())
40 throw std::invalid_argument(
"Requested to merge two VectorValues that have one or more variables in common.");
46 for (
const auto& [
key,
n] : dims) {
47 #ifdef TBB_GREATER_EQUAL_2020
60 #ifdef TBB_GREATER_EQUAL_2020
71 std::map<Key, Vector> ordered;
72 for (
const auto& kv : *
this) ordered.emplace(kv);
81 #ifdef TBB_GREATER_EQUAL_2020
91 const std::pair<iterator, bool>
result =
values_.insert(key_value);
93 throw std::invalid_argument(
95 +
"' already in this VectorValues.");
105 size_t oldSize =
values_.size();
107 if (
values_.size() > oldSize) {
109 throw std::out_of_range(
110 "Requested to update a VectorValues with another VectorValues that "
111 "contains keys not present in the first.");
113 hint->second =
value;
121 size_t originalSize =
size();
124 throw std::invalid_argument(
125 "Requested to insert a VectorValues into another VectorValues that "
126 "already contains one or more of its keys.");
142 for (
const auto& [
key,
value] :
v.sorted())
155 std::cout <<
str <<
": " <<
size() <<
" elements\n";
164 auto this_it = this->begin();
165 auto x_it =
x.begin();
166 for(; this_it != this->
end(); ++this_it, ++x_it) {
167 if(this_it->first != x_it->first ||
178 for (
const auto& [
key,
value] : *
this)
179 totalDim +=
value.size();
188 for (
const auto& [
key,
value] : *
this) {
206 for(
const Dims::value_type& it:
keys) {
207 result.segment(
j,it.second) =
at(it.first);
223 return a.first ==
b.first &&
a.second.size() ==
b.second.size();
240 throw std::invalid_argument(
"VectorValues::dot called with a VectorValues of different structure");
242 auto this_it = this->begin();
243 auto v_it =
v.begin();
244 for(; this_it != this->
end(); ++this_it, ++v_it) {
246 std::invalid_argument(
"VectorValues::dot called with a VectorValues of different structure"));
247 assert_throw(this_it->second.size() == v_it->second.size(),
248 std::invalid_argument(
"VectorValues::dot called with a VectorValues of different structure"));
249 result += this_it->second.dot(v_it->second);
261 double sumSquares = 0.0;
262 for(
const auto& [
key,
value]: *
this) {
263 sumSquares +=
value.squaredNorm();
272 throw std::invalid_argument(
"VectorValues::operator+ called with different vector sizes");
274 std::invalid_argument(
"VectorValues::operator+ called with different vector sizes"));
279 #ifdef TBB_GREATER_EQUAL_2020
280 result.values_.emplace(
j1->first,
j1->second + j2->second);
282 result.values_.insert({
j1->first,
j1->second + j2->second});
298 throw std::invalid_argument(
"VectorValues::operator+= called with different vector sizes");
300 std::invalid_argument(
"VectorValues::operator+= called with different vector sizes"));
306 j1->second += j2->second;
323 it->second = j2->second;
325 it->second += j2->second;
334 throw std::invalid_argument(
"VectorValues::operator- called with different vector sizes");
336 std::invalid_argument(
"VectorValues::operator- called with different vector sizes"));
341 #ifdef TBB_GREATER_EQUAL_2020
342 result.values_.emplace(
j1->first,
j1->second - j2->second);
344 result.values_.insert({
j1->first,
j1->second - j2->second});
360 #ifdef TBB_GREATER_EQUAL_2020
386 return *
this *=
alpha;
391 std::stringstream
ss;
394 ss <<
"<div>\n<table class='VectorValues'>\n <thead>\n";
397 ss <<
" <tr><th>Variable</th><th>value</th></tr>\n";
400 ss <<
" </thead>\n <tbody>\n";
405 for (
const auto& kv :
sorted()) {
407 for (
const auto& kv : *
this) {
410 ss <<
"<th>" << keyFormatter(kv.first) <<
"</th><td>"
411 << kv.second.transpose() <<
"</td>";
414 ss <<
" </tbody>\n</table>\n</div>";
422 #if defined(__clang__)
423 #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
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)
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 Sun Dec 22 2024 04:18:23