diff --git a/gtsam/linear/HessianFactor.cpp b/gtsam/linear/HessianFactor.cpp index 970051faf..c631d8d14 100644 --- a/gtsam/linear/HessianFactor.cpp +++ b/gtsam/linear/HessianFactor.cpp @@ -392,10 +392,11 @@ void HessianFactor::updateATA(const HessianFactor& update, const Scatter& scatte // Apply updates to the upper triangle gttic(update); + size_t nrInfoBlocks = this->info_.nBlocks(); for(DenseIndex j2=0; j2info_.nBlocks()-1 : slots[j2]; + DenseIndex slot2 = (j2 == (DenseIndex)update.size()) ? nrInfoBlocks-1 : slots[j2]; for(DenseIndex j1=0; j1<=j2; ++j1) { - DenseIndex slot1 = (j1 == (DenseIndex)update.size()) ? this->info_.nBlocks()-1 : slots[j1]; + DenseIndex slot1 = (j1 == (DenseIndex)update.size()) ? nrInfoBlocks-1 : slots[j1]; if(slot2 > slot1) info_(slot1, slot2).noalias() += update.info_(j1, j2); else if(slot1 > slot2) @@ -450,10 +451,13 @@ void HessianFactor::updateATA(const JacobianFactor& update, const Scatter& scatt // Apply updates to the upper triangle gttic(update); - for(DenseIndex j2=0; j2info_.nBlocks()-1 : slots[j2]; + size_t nrInfoBlocks = this->info_.nBlocks(), nrUpdateBlocks = updateBlocks.nBlocks(); + for(DenseIndex j2=0; j2=0 && slot2<=nrInfoBlocks); for(DenseIndex j1=0; j1<=j2; ++j1) { // Vertical block of Hessian - DenseIndex slot1 = (j1 == update.size()) ? this->info_.nBlocks()-1 : slots[j1]; + DenseIndex slot1 = (j1 == update.size()) ? nrInfoBlocks-1 : slots[j1]; + assert(slot1>=0 && slot1 slot1) info_(slot1, slot2).noalias() += updateBlocks(j1).transpose() * updateBlocks(j2);