25 #pragma clang diagnostic push 26 #pragma clang diagnostic ignored "-Wextra-semi-stmt" 35 std::bind(&std::less<Key>::operator(), std::less<Key>(), std::bind(&
KeyValuePair::first, std::placeholders::_1),
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 59 values_.emplace(
v.key, x.segment(j,
v.dimension));
61 values_.insert({
v.key, x.segment(j,
v.dimension)});
71 for (
const auto& [
key,
value] : other)
72 #ifdef TBB_GREATER_EQUAL_2020 82 const std::pair<iterator, bool>
result =
values_.insert(key_value);
84 throw std::invalid_argument(
86 +
"' already in this VectorValues.");
93 for (
const auto& [
key,
value] : values) {
96 size_t oldSize =
values_.size();
100 throw std::out_of_range(
101 "Requested to update a VectorValues with another VectorValues that " 102 "contains keys not present in the first.");
104 hint->second =
value;
112 size_t originalSize =
size();
114 if (
size() != originalSize + values.
size())
115 throw std::invalid_argument(
116 "Requested to insert a VectorValues into another VectorValues that " 117 "already contains one or more of its keys.");
133 std::map<Key, Vector> sorted;
134 for (
const auto& [
key,
value] : v) {
137 for (
const auto& [
key,
value] : sorted)
150 std::cout << str <<
": " <<
size() <<
" elements\n";
159 auto this_it = this->
begin();
160 auto x_it = x.
begin();
161 for(; this_it != this->
end(); ++this_it, ++x_it) {
162 if(this_it->first != x_it->first ||
173 for (
const auto& [
key,
value] : *
this)
174 totalDim +=
value.size();
179 for (
const auto& [
key,
value] : *
this) {
192 for (
const auto& [
key,
dim] : keys)
196 for(
const Dims::value_type& it: keys) {
197 result.segment(j,it.second) =
at(it.first);
213 return a.first == b.first && a.second.size() == b.second.size();
230 throw std::invalid_argument(
"VectorValues::dot called with a VectorValues of different structure");
232 auto this_it = this->
begin();
233 auto v_it = v.
begin();
234 for(; this_it != this->
end(); ++this_it, ++v_it) {
236 std::invalid_argument(
"VectorValues::dot called with a VectorValues of different structure"));
237 assert_throw(this_it->second.size() == v_it->second.size(),
238 std::invalid_argument(
"VectorValues::dot called with a VectorValues of different structure"));
239 result += this_it->second.dot(v_it->second);
251 double sumSquares = 0.0;
252 for(
const auto& [
key,
value]: *
this) {
253 sumSquares +=
value.squaredNorm();
262 throw std::invalid_argument(
"VectorValues::operator+ called with different vector sizes");
264 std::invalid_argument(
"VectorValues::operator+ called with different vector sizes"));
269 #ifdef TBB_GREATER_EQUAL_2020
270 result.
values_.emplace(j1->first, j1->second + j2->second);
272 result.
values_.insert({j1->first, j1->second + j2->second});
288 throw std::invalid_argument(
"VectorValues::operator+= called with different vector sizes");
290 std::invalid_argument(
"VectorValues::operator+= called with different vector sizes"));
295 for(; j1 !=
end(); ++j1, ++j2)
296 j1->second += j2->second;
313 it->second = j2->second;
315 it->second += j2->second;
324 throw std::invalid_argument(
"VectorValues::operator- called with different vector sizes");
326 std::invalid_argument(
"VectorValues::operator- called with different vector sizes"));
331 #ifdef TBB_GREATER_EQUAL_2020
332 result.
values_.emplace(j1->first, j1->second - j2->second);
334 result.
values_.insert({j1->first, j1->second - j2->second});
350 #ifdef TBB_GREATER_EQUAL_2020 376 return *
this *=
alpha;
381 std::stringstream
ss;
384 ss <<
"<div>\n<table class='VectorValues'>\n <thead>\n";
387 ss <<
" <tr><th>Variable</th><th>value</th></tr>\n";
390 ss <<
" </thead>\n <tbody>\n";
395 std::map<Key, Vector> ordered;
396 for (
const auto& kv : *
this) ordered.emplace(kv);
397 for (
const auto& kv : ordered) {
399 for (
const auto& kv : *
this) {
402 ss <<
"<th>" << keyFormatter(kv.first) <<
"</th><td>" 403 << kv.second.transpose() <<
"</td>";
406 ss <<
" </tbody>\n</table>\n</div>";
414 #pragma clang diagnostic pop const gtsam::Symbol key('X', 0)
One SlotEntry stores the slot index for a variable, as well its dim.
bool hasSameStructure(const VectorValues other) const
Values::iterator iterator
Iterator over vector values.
GTSAM_EXPORT friend std::ostream & operator<<(std::ostream &, const VectorValues &)
overload operator << to print to stringstream
VectorValues operator-(const VectorValues &c) const
void print(const std::string &str="VectorValues", const KeyFormatter &formatter=DefaultKeyFormatter) const
VectorValues & operator+=(const VectorValues &c)
VectorValues & addInPlace(const VectorValues &c)
Values::value_type value_type
Typedef to pair<Key, Vector>
iterator insert(const std::pair< Key, Vector > &key_value)
iterator end()
Iterator over variables.
bool structureCompareOp(const VectorValues::value_type &a, const VectorValues::value_type &b)
VectorValues & addInPlace_(const VectorValues &c)
std::map< Key, size_t > Dims
Keyed vector dimensions.
EIGEN_CONSTEXPR Index first(const T &x) EIGEN_NOEXCEPT
static const KeyFormatter DefaultKeyFormatter
ptrdiff_t DenseIndex
The index type for Eigen objects.
const KeyFormatter & formatter
std::pair< iterator, bool > tryInsert(Key j, const Vector &value)
VectorValues scale(const double a) const
bool equals(const VectorValues &x, double tol=1e-9) const
VectorValues()
Default constructor creates an empty VectorValues.
VectorValues subtract(const VectorValues &c) const
static VectorValues Zero(const VectorValues &other)
Array< int, Dynamic, 1 > v
Values values_
Vectors making up this VectorValues.
To use the key_formatter on Keys, they must be wrapped in a StreamedKey.
VectorValues add(const VectorValues &c) const
VectorValues & scaleInPlace(double alpha)
Values::const_iterator const_iterator
Const iterator over vector values.
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
static std::stringstream ss
bool equal_with_abs_tol(const Eigen::DenseBase< MATRIX > &A, const Eigen::DenseBase< MATRIX > &B, double tol=1e-9)
double squaredNorm() const
void swap(VectorValues &other)
void unsafe_erase(typename Base::iterator position)
double dot(const VectorValues &v) const
ofstream os("timeSchurFactors.csv")
VectorValues & operator*=(double alpha)
VectorValues operator+(const VectorValues &c) const
std::string html(const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Output as a html table.
friend GTSAM_EXPORT VectorValues operator*(const double a, const VectorValues &v)
VectorValues & update(const VectorValues &values)
Jet< T, N > sqrt(const Jet< T, N > &f)
#define assert_throw(CONDITION, EXCEPTION)
bool equal(const T &obj1, const T &obj2, double tol)
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
iterator begin()
Iterator over variables.