Skip to content

Commit

Permalink
Cleanup cholmod_update error handling via assert->throw
Browse files Browse the repository at this point in the history
  • Loading branch information
parejkoj committed May 16, 2018
1 parent aaa1c56 commit 9a4dad6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 7 additions & 5 deletions include/lsst/jointcal/Eigenstuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#ifndef LSST_JOINTCAL_EIGENSTUFF_H
#define LSST_JOINTCAL_EIGENSTUFF_H

#include "Eigen/CholmodSupport" // to switch to cholmod
#include "lsst/pex/exceptions.h"

#include "Eigen/CholmodSupport" // to switch to cholmod
#include "Eigen/Core"

typedef Eigen::Matrix<double, Eigen::Dynamic, 2> MatrixX2d;
Expand Down Expand Up @@ -38,7 +39,7 @@ class CholmodSimplicialLDLT2
}

// this routine is the one we added
int update(SparseMatrixD const &H, bool UpOrDown) {
void update(SparseMatrixD const &H, bool UpOrDown) {
// check size
Index const size = Base::m_cholmodFactor->n;
EIGEN_UNUSED_VARIABLE(size);
Expand All @@ -51,10 +52,11 @@ class CholmodSimplicialLDLT2
cholmod_submatrix(&C_cs, (int *)Base::m_cholmodFactor->Perm, Base::m_cholmodFactor->n,
nullptr, -1, true, true, &this->cholmod());
assert(C_cs_perm);
int ret = cholmod_updown(UpOrDown, C_cs_perm, Base::m_cholmodFactor, &this->cholmod());
int isOk = cholmod_updown(UpOrDown, C_cs_perm, Base::m_cholmodFactor, &this->cholmod());
cholmod_free_sparse(&C_cs_perm, &this->cholmod());
assert(ret != 0);
return ret;
if (!isOk) {
throw(LSST_EXCEPT(lsst::pex::exceptions::RuntimeError, "cholmod_update failed!"));
}
}

protected:
Expand Down
3 changes: 1 addition & 2 deletions src/FitterBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ MinimizeResult FitterBase::minimize(std::string const &whatToFit, double nSigmaC
// convert triplet list to eigen internal format
SparseMatrixD H(_nParTot, outlierTriplets.getNextFreeIndex());
H.setFromTriplets(outlierTriplets.begin(), outlierTriplets.end());
int update_status = chol.update(H, false /* means downdate */);
LOGLS_DEBUG(_log, "cholmod update_status " << update_status);
chol.update(H, false /* means downdate */);
// The contribution of outliers to the gradient is the opposite
// of the contribution of all other terms, because they add up to 0
grad *= -1;
Expand Down

0 comments on commit 9a4dad6

Please sign in to comment.