fix issues according to pr comments

release/4.3a0
mxie32 2019-06-14 15:55:08 -04:00
parent 9ac72a017b
commit 5ba91939c7
3 changed files with 13 additions and 24 deletions

View File

@ -129,30 +129,22 @@ namespace gtsam {
}
/* ************************************************************************* */
bool compare(std::pair<Key, Vector>& lhs, std::pair<Key, Vector>& rhs) {
return lhs.first < rhs.first;
}
ostream& operator<<(ostream& ss, const VectorValues& v) {
ss << "VectorValues: "
ostream& operator<<(ostream& os, const VectorValues& v) {
os << "VectorValues"
<< ": " << v.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(v.size());
map<Key, Vector> sorted;
for (const auto& key_value : v) {
vec.push_back(std::make_pair(key_value.first, key_value.second));
sorted.insert(std::make_pair(key_value.first, key_value.second));
}
sort(vec.begin(), vec.end(), compare);
for (const auto& key_value : vec)
ss << " " << key_value.first << ": " << key_value.second.transpose()
<< "\n";
for (const auto& key_value : sorted)
#else
for (const auto& key_value : v)
ss << " " << key_value.first << ": " << key_value.second.transpose()
<< "\n";
#endif
return ss;
os << " " << key_value.first << ": " << key_value.second.transpose()
<< "\n";
return os;
}
/* ************************************************************************* */

View File

@ -29,7 +29,7 @@
#include <map>
#include <string>
#include <iostream>
#include <iosfwd>
namespace gtsam {
@ -229,13 +229,11 @@ namespace gtsam {
*/
const_iterator find(Key j) const { return values_.find(j); }
/**
* overload operator << to print to stringstream
*/
friend std::ostream& operator<<(std::ostream& ss, const VectorValues& v);
/// overload operator << to print to stringstream
friend std::ostream& operator<<(std::ostream&, const VectorValues&);
/** print required by Testable for unit testing */
void print(const std::string& str = "VectorValues: ",
void print(const std::string& str = "VectorValues",
const KeyFormatter& formatter = DefaultKeyFormatter) const;
/** equals required by Testable for unit testing */

View File

@ -241,10 +241,9 @@ TEST(VectorValues, print)
vv.insert(7, Vector2(8, 9));
string expected =
"VectorValues: : 5 elements\n 0: 1\n 1: 2 3\n 2: 4 5\n 5: 6 7\n 7: 8 9\n";
"VectorValues: 5 elements\n 0: 1\n 1: 2 3\n 2: 4 5\n 5: 6 7\n 7: 8 9\n";
stringstream actual;
actual << vv;
EXPECT(expected == actual.str());
}