Resolve review comments
parent
68e987ea62
commit
e5964736d1
|
@ -38,12 +38,8 @@ namespace gtsam {
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
VectorValues::VectorValues(const Vector& x, const Dims& dims) {
|
VectorValues::VectorValues(const Vector& x, const Dims& dims) {
|
||||||
using Pair = pair<const Key, size_t>;
|
|
||||||
size_t j = 0;
|
size_t j = 0;
|
||||||
for (const Pair& v : dims) {
|
for (const auto& [key,n] : dims) {
|
||||||
Key key;
|
|
||||||
size_t n;
|
|
||||||
std::tie(key, n) = v;
|
|
||||||
#ifdef TBB_GREATER_EQUAL_2020
|
#ifdef TBB_GREATER_EQUAL_2020
|
||||||
values_.emplace(key, x.segment(j, n));
|
values_.emplace(key, x.segment(j, n));
|
||||||
#else
|
#else
|
||||||
|
@ -70,11 +66,11 @@ namespace gtsam {
|
||||||
VectorValues VectorValues::Zero(const VectorValues& other)
|
VectorValues VectorValues::Zero(const VectorValues& other)
|
||||||
{
|
{
|
||||||
VectorValues result;
|
VectorValues result;
|
||||||
for(const KeyValuePair& v: other)
|
for(const auto& [key,value]: other)
|
||||||
#ifdef TBB_GREATER_EQUAL_2020
|
#ifdef TBB_GREATER_EQUAL_2020
|
||||||
result.values_.emplace(v.first, Vector::Zero(v.second.size()));
|
result.values_.emplace(key, Vector::Zero(value.size()));
|
||||||
#else
|
#else
|
||||||
result.values_.insert(std::make_pair(v.first, Vector::Zero(v.second.size())));
|
result.values_.insert(std::make_pair(key, Vector::Zero(value.size())));
|
||||||
#endif
|
#endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -92,18 +88,18 @@ namespace gtsam {
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
VectorValues& VectorValues::update(const VectorValues& values) {
|
VectorValues& VectorValues::update(const VectorValues& values) {
|
||||||
iterator hint = begin();
|
iterator hint = begin();
|
||||||
for (const KeyValuePair& key_value : values) {
|
for (const auto& [key,value] : values) {
|
||||||
// Use this trick to find the value using a hint, since we are inserting
|
// Use this trick to find the value using a hint, since we are inserting
|
||||||
// from another sorted map
|
// from another sorted map
|
||||||
size_t oldSize = values_.size();
|
size_t oldSize = values_.size();
|
||||||
hint = values_.insert(hint, key_value);
|
hint = values_.emplace_hint(hint, key, value);
|
||||||
if (values_.size() > oldSize) {
|
if (values_.size() > oldSize) {
|
||||||
values_.unsafe_erase(hint);
|
values_.unsafe_erase(hint);
|
||||||
throw out_of_range(
|
throw out_of_range(
|
||||||
"Requested to update a VectorValues with another VectorValues that "
|
"Requested to update a VectorValues with another VectorValues that "
|
||||||
"contains keys not present in the first.");
|
"contains keys not present in the first.");
|
||||||
} else {
|
} else {
|
||||||
hint->second = key_value.second;
|
hint->second = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -133,16 +129,15 @@ namespace gtsam {
|
||||||
// Change print depending on whether we are using TBB
|
// Change print depending on whether we are using TBB
|
||||||
#ifdef GTSAM_USE_TBB
|
#ifdef GTSAM_USE_TBB
|
||||||
map<Key, Vector> sorted;
|
map<Key, Vector> sorted;
|
||||||
for (const auto& key_value : v) {
|
for (const auto& [key,value] : v) {
|
||||||
sorted.emplace(key_value.first, key_value.second);
|
sorted.emplace(key, value);
|
||||||
}
|
}
|
||||||
for (const auto& key_value : sorted)
|
for (const auto& [key,value] : sorted)
|
||||||
#else
|
#else
|
||||||
for (const auto& key_value : v)
|
for (const auto& [key,value] : v)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
os << " " << StreamedKey(key_value.first) << ": " << key_value.second.transpose()
|
os << " " << StreamedKey(key) << ": " << value.transpose() << "\n";
|
||||||
<< "\n";
|
|
||||||
}
|
}
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,8 +45,7 @@ TEST(LinearEquality, constructors_and_accessors) {
|
||||||
// Test for using different numbers of terms
|
// Test for using different numbers of terms
|
||||||
{
|
{
|
||||||
// One term constructor
|
// One term constructor
|
||||||
LinearEquality expected(
|
LinearEquality expected(terms.begin(), terms.begin() + 1, b, 0);
|
||||||
std::vector(terms.begin(), terms.begin() + 1), b, 0);
|
|
||||||
LinearEquality actual(terms[0].first, terms[0].second, b, 0);
|
LinearEquality actual(terms[0].first, terms[0].second, b, 0);
|
||||||
EXPECT(assert_equal(expected, actual));
|
EXPECT(assert_equal(expected, actual));
|
||||||
LONGS_EQUAL((long)terms[0].first, (long)actual.keys().back());
|
LONGS_EQUAL((long)terms[0].first, (long)actual.keys().back());
|
||||||
|
@ -57,8 +56,7 @@ TEST(LinearEquality, constructors_and_accessors) {
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// Two term constructor
|
// Two term constructor
|
||||||
LinearEquality expected(
|
LinearEquality expected(terms.begin(), terms.begin() + 2, b, 0);
|
||||||
std::vector(terms.begin(), terms.begin() + 2), b, 0);
|
|
||||||
LinearEquality actual(terms[0].first, terms[0].second, terms[1].first,
|
LinearEquality actual(terms[0].first, terms[0].second, terms[1].first,
|
||||||
terms[1].second, b, 0);
|
terms[1].second, b, 0);
|
||||||
EXPECT(assert_equal(expected, actual));
|
EXPECT(assert_equal(expected, actual));
|
||||||
|
@ -70,8 +68,7 @@ TEST(LinearEquality, constructors_and_accessors) {
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// Three term constructor
|
// Three term constructor
|
||||||
LinearEquality expected(
|
LinearEquality expected(terms.begin(), terms.begin() + 3, b, 0);
|
||||||
std::vector(terms.begin(), terms.begin() + 3), b, 0);
|
|
||||||
LinearEquality actual(terms[0].first, terms[0].second, terms[1].first,
|
LinearEquality actual(terms[0].first, terms[0].second, terms[1].first,
|
||||||
terms[1].second, terms[2].first, terms[2].second, b,
|
terms[1].second, terms[2].first, terms[2].second, b,
|
||||||
0);
|
0);
|
||||||
|
|
Loading…
Reference in New Issue