Skip to content

Commit

Permalink
print key_values in order
Browse files Browse the repository at this point in the history
  • Loading branch information
mxie32 committed Jun 14, 2019
1 parent 2823595 commit 7b41007
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions gtsam/linear/VectorValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,32 @@ namespace gtsam {
v.setZero();
}

/* ************************************************************************* */
void VectorValues::print(const string& str, const KeyFormatter& formatter) const {
cout << str << ": " << size() << " elements\n";
for(const value_type& key_value: *this)
cout << " " << formatter(key_value.first) << ": " << key_value.second.transpose() << "\n";
cout.flush();
/* ************************************************************************* */
bool compare(std::pair<Key, Vector>& lhs, std::pair<Key, Vector>& rhs) {
return lhs.first < rhs.first;
}

void VectorValues::print(const string& str,
const KeyFormatter& formatter) const {
cout << str << ": " << size() << " elements\n";
// Change print depending on whether we are using TBB
#ifdef GTSAM_USE_TBB
std::vector<std::pair<Key, Vector>> vec;
vec.reserve(size());
for (const value_type& key_value : *this) {
vec.push_back(std::make_pair(key_value.first, key_value.second));
}
sort(vec.begin(), vec.end(), compare);
for (const auto& key_value : vec)
cout << " " << formatter(key_value.first) << ": "
<< key_value.second.transpose() << "\n";
#else
for (const value_type& key_value : *this)
cout << " " << formatter(key_value.first) << ": "
<< key_value.second.transpose() << "\n";
#endif
cout.flush();
}

/* ************************************************************************* */
bool VectorValues::equals(const VectorValues& x, double tol) const {
Expand Down

0 comments on commit 7b41007

Please sign in to comment.