Added detail to NegativeMatrixException

release/4.3a0
Richard Roberts 2011-09-14 19:46:20 +00:00
parent 91d727d4eb
commit 93c601d03c
2 changed files with 21 additions and 6 deletions

View File

@ -168,11 +168,10 @@ Eigen::LDLT<Matrix>::TranspositionType ldlPartial(Matrix& ABC, size_t nFrontal)
ldlt.compute(ABC.block(0,0,nFrontal,nFrontal).selfadjointView<Eigen::Upper>());
if(ldlt.vectorD().unaryExpr(boost::bind(less<double>(), _1, 0.0)).any()) {
if(debug) {
gtsam::print(Matrix(ldlt.matrixU()), "U: ");
gtsam::print(Vector(ldlt.vectorD()), "D: ");
}
throw NegativeMatrixException();
if(ISDEBUG("detailed_exceptions"))
throw NegativeMatrixException(NegativeMatrixException::Detail(ABC, ldlt.matrixU(), ldlt.vectorD()));
else
throw NegativeMatrixException();
}
Vector sqrtD = ldlt.vectorD().cwiseSqrt();

View File

@ -18,13 +18,29 @@
#pragma once
#include <gtsam/base/Matrix.h>
#include <boost/shared_ptr.hpp>
namespace gtsam {
/**
* An exception indicating an attempt to factor a negative or indefinite matrix.
* If detailed exceptions are enabled
* \todo fill this in
*/
class NegativeMatrixException : public std::exception { };
struct NegativeMatrixException : public std::exception {
/// Detail for NegativeMatrixException
struct Detail {
Matrix A; ///< The original matrix attempted to factor
Matrix U; ///< The produced upper-triangular factor
Matrix D; ///< The produced diagonal factor
Detail(const Matrix& _A, const Matrix& _U, const Matrix& _D) /**< Detail constructor */ : A(_A), U(_A), D(_D) {}
};
const boost::shared_ptr<const Detail> detail; ///< Detail
NegativeMatrixException() /**< Constructor with no detail */ {}
NegativeMatrixException(const Detail& _detail) /**< Constructor with detail */ : detail(new Detail(_detail)) {}
NegativeMatrixException(const boost::shared_ptr<Detail>& _detail) /**< Constructor with detail */ : detail(_detail) {}
virtual ~NegativeMatrixException() throw() {}
};
/**
* "Careful" Cholesky computes the positive square-root of a positive symmetric