use emplace where possible

release/4.3a0
Frank Dellaert 2019-04-08 16:54:20 -04:00
parent 9ec714063a
commit 35d8ebca22
4 changed files with 10 additions and 10 deletions

View File

@ -134,7 +134,7 @@ namespace gtsam {
VectorValues result; VectorValues result;
DenseIndex vectorPosition = 0; DenseIndex vectorPosition = 0;
for (const_iterator frontal = beginFrontals(); frontal != endFrontals(); ++frontal) { for (const_iterator frontal = beginFrontals(); frontal != endFrontals(); ++frontal) {
result.insert(*frontal, solution.segment(vectorPosition, getDim(frontal))); result.emplace(*frontal, solution.segment(vectorPosition, getDim(frontal)));
vectorPosition += getDim(frontal); vectorPosition += getDim(frontal);
} }
@ -162,7 +162,7 @@ namespace gtsam {
VectorValues result; VectorValues result;
DenseIndex vectorPosition = 0; DenseIndex vectorPosition = 0;
for (const_iterator frontal = beginFrontals(); frontal != endFrontals(); ++frontal) { for (const_iterator frontal = beginFrontals(); frontal != endFrontals(); ++frontal) {
result.insert(*frontal, soln.segment(vectorPosition, getDim(frontal))); result.emplace(*frontal, soln.segment(vectorPosition, getDim(frontal)));
vectorPosition += getDim(frontal); vectorPosition += getDim(frontal);
} }

View File

@ -61,7 +61,7 @@ namespace gtsam {
for (GaussianFactor::const_iterator it = gf->begin(); it != gf->end(); it++) { for (GaussianFactor::const_iterator it = gf->begin(); it != gf->end(); it++) {
map<Key,size_t>::iterator it2 = spec.find(*it); map<Key,size_t>::iterator it2 = spec.find(*it);
if ( it2 == spec.end() ) { if ( it2 == spec.end() ) {
spec.insert(make_pair(*it, gf->getDim(it))); spec.emplace(*it, gf->getDim(it));
} }
} }
} }
@ -246,7 +246,7 @@ namespace gtsam {
if (blocks.count(j)) if (blocks.count(j))
blocks[j] += Bj; blocks[j] += Bj;
else else
blocks.insert(make_pair(j,Bj)); blocks.emplace(j,Bj);
} }
} }
return blocks; return blocks;

View File

@ -305,7 +305,7 @@ Matrix HessianFactor::information() const {
VectorValues HessianFactor::hessianDiagonal() const { VectorValues HessianFactor::hessianDiagonal() const {
VectorValues d; VectorValues d;
for (DenseIndex j = 0; j < (DenseIndex)size(); ++j) { for (DenseIndex j = 0; j < (DenseIndex)size(); ++j) {
d.insert(keys_[j], info_.diagonal(j)); d.emplace(keys_[j], info_.diagonal(j));
} }
return d; return d;
} }
@ -436,7 +436,7 @@ VectorValues HessianFactor::gradientAtZero() const {
VectorValues g; VectorValues g;
size_t n = size(); size_t n = size();
for (size_t j = 0; j < n; ++j) for (size_t j = 0; j < n; ++j)
g.insert(keys_[j], -info_.aboveDiagonalBlock(j, n)); g.emplace(keys_[j], -info_.aboveDiagonalBlock(j, n));
return g; return g;
} }
@ -513,7 +513,7 @@ VectorValues HessianFactor::solve() {
std::size_t offset = 0; std::size_t offset = 0;
for (DenseIndex j = 0; j < (DenseIndex)n; ++j) { for (DenseIndex j = 0; j < (DenseIndex)n; ++j) {
const DenseIndex dim = info_.getDim(j); const DenseIndex dim = info_.getDim(j);
delta.insert(keys_[j], solution.segment(offset, dim)); delta.emplace(keys_[j], solution.segment(offset, dim));
offset += dim; offset += dim;
} }

View File

@ -56,7 +56,7 @@ namespace gtsam
myData.parentData = parentData; myData.parentData = parentData;
// Take any ancestor results we'll need // Take any ancestor results we'll need
for(Key parent: clique->conditional_->parents()) for(Key parent: clique->conditional_->parents())
myData.cliqueResults.insert(std::make_pair(parent, myData.parentData->cliqueResults.at(parent))); myData.cliqueResults.emplace(parent, myData.parentData->cliqueResults.at(parent));
// Solve and store in our results // Solve and store in our results
{ {
@ -99,8 +99,8 @@ namespace gtsam
DenseIndex vectorPosition = 0; DenseIndex vectorPosition = 0;
for(GaussianConditional::const_iterator frontal = c.beginFrontals(); frontal != c.endFrontals(); ++frontal) { for(GaussianConditional::const_iterator frontal = c.beginFrontals(); frontal != c.endFrontals(); ++frontal) {
VectorValues::const_iterator r = VectorValues::const_iterator r =
collectedResult.insert(*frontal, solution.segment(vectorPosition, c.getDim(frontal))); collectedResult.emplace(*frontal, solution.segment(vectorPosition, c.getDim(frontal)));
myData.cliqueResults.insert(make_pair(r->first, r)); myData.cliqueResults.emplace(r->first, r);
vectorPosition += c.getDim(frontal); vectorPosition += c.getDim(frontal);
} }
} }