@@ -64,6 +64,13 @@ namespace gtsam {
64
64
}
65
65
}
66
66
67
+ /* ************************************************************************ */
68
+ std::map<Key, Vector> VectorValues::sorted () const {
69
+ std::map<Key, Vector> ordered;
70
+ for (const auto & kv : *this ) ordered.emplace (kv);
71
+ return ordered;
72
+ }
73
+
67
74
/* ************************************************************************ */
68
75
VectorValues VectorValues::Zero (const VectorValues& other)
69
76
{
@@ -130,11 +137,7 @@ namespace gtsam {
130
137
GTSAM_EXPORT std::ostream& operator <<(std::ostream& os, const VectorValues& v) {
131
138
// Change print depending on whether we are using TBB
132
139
#ifdef GTSAM_USE_TBB
133
- std::map<Key, Vector> sorted;
134
- for (const auto & [key, value] : v) {
135
- sorted.emplace (key, value);
136
- }
137
- for (const auto & [key, value] : sorted)
140
+ for (const auto & [key, value] : v.sorted ())
138
141
#else
139
142
for (const auto & [key,value] : v)
140
143
#endif
@@ -176,7 +179,12 @@ namespace gtsam {
176
179
// Copy vectors
177
180
Vector result (totalDim);
178
181
DenseIndex pos = 0 ;
182
+ #ifdef GTSAM_USE_TBB
183
+ // TBB uses un-ordered map, so inefficiently order them:
184
+ for (const auto & [key, value] : sorted ()) {
185
+ #else
179
186
for (const auto & [key, value] : *this ) {
187
+ #endif
180
188
result.segment (pos, value.size ()) = value;
181
189
pos += value.size ();
182
190
}
@@ -392,9 +400,7 @@ namespace gtsam {
392
400
// Print out all rows.
393
401
#ifdef GTSAM_USE_TBB
394
402
// TBB uses un-ordered map, so inefficiently order them:
395
- std::map<Key, Vector> ordered;
396
- for (const auto & kv : *this ) ordered.emplace (kv);
397
- for (const auto & kv : ordered) {
403
+ for (const auto & kv : sorted ()) {
398
404
#else
399
405
for (const auto & kv : *this ) {
400
406
#endif
0 commit comments