10 #define TEST_ENABLE_TEMPORARY_TRACKING 13 #include <Eigen/Cholesky> 17 template<
typename MatrixType,
int UpLo>
21 return symm.cwiseAbs().colwise().sum().maxCoeff();
31 MatrixType symmUp = symm.template triangularView<Upper>();
34 CholType<MatrixType,Lower> chollo(symmLo);
35 CholType<MatrixType,Upper> cholup(symmUp);
37 for (
int k=0; k<10; ++k)
39 VectorType vec = VectorType::Random(symm.rows());
40 RealScalar
sigma = internal::random<RealScalar>();
41 symmCpy += sigma * vec * vec.adjoint();
44 CholType<MatrixType,Lower> chol(symmCpy);
48 chollo.rankUpdate(vec, sigma);
51 cholup.rankUpdate(vec, sigma);
70 VectorType vecB = VectorType::Random(rows), vecX(rows);
72 SquareMatrixType
symm = a0 * a0.adjoint();
74 for (
int k=0; k<3; ++k)
77 symm += a1 * a1.adjoint();
84 SquareMatrixType symmUp = symm.template triangularView<Upper>();
90 check_solverbase<VectorType, VectorType>(
symm, chollo,
rows,
rows, 1);
93 const MatrixType symmLo_inverse = chollo.solve(MatrixType::Identity(rows,cols));
94 RealScalar rcond = (
RealScalar(1) / matrix_l1_norm<MatrixType, Lower>(symmLo)) /
95 matrix_l1_norm<MatrixType, Lower>(symmLo_inverse);
96 RealScalar rcond_est = chollo.rcond();
99 VERIFY(rcond_est >= rcond / 10 && rcond_est <= rcond * 10);
104 vecX = cholup.
solve(vecB);
106 matX = cholup.
solve(matB);
111 const MatrixType symmUp_inverse = cholup.
solve(MatrixType::Identity(rows,cols));
112 rcond = (
RealScalar(1) / matrix_l1_norm<MatrixType, Upper>(symmUp)) /
113 matrix_l1_norm<MatrixType, Upper>(symmUp_inverse);
114 rcond_est = cholup.
rcond();
115 VERIFY(rcond_est >= rcond / 10 && rcond_est <= rcond * 10);
130 m2 += symmLo.template selfadjointView<Lower>().
llt().solve(matB);
131 VERIFY_IS_APPROX(
m2, m1 + symmLo.template selfadjointView<Lower>().llt().solve(matB));
133 m2 -= symmLo.template selfadjointView<Lower>().
llt().solve(matB);
134 VERIFY_IS_APPROX(m2, m1 - symmLo.template selfadjointView<Lower>().llt().solve(matB));
136 m2.noalias() += symmLo.template selfadjointView<Lower>().
llt().solve(matB);
137 VERIFY_IS_APPROX(m2, m1 + symmLo.template selfadjointView<Lower>().llt().solve(matB));
139 m2.noalias() -= symmLo.template selfadjointView<Lower>().
llt().solve(matB);
140 VERIFY_IS_APPROX(m2, m1 - symmLo.template selfadjointView<Lower>().llt().solve(matB));
148 int sign = internal::random<int>()%2 ? 1 : -1;
155 SquareMatrixType symmUp = symm.template triangularView<Upper>();
162 check_solverbase<VectorType, VectorType>(
symm, ldltlo,
rows,
rows, 1);
165 const MatrixType symmLo_inverse = ldltlo.solve(MatrixType::Identity(rows,cols));
166 RealScalar rcond = (
RealScalar(1) / matrix_l1_norm<MatrixType, Lower>(symmLo)) /
167 matrix_l1_norm<MatrixType, Lower>(symmLo_inverse);
168 RealScalar rcond_est = ldltlo.rcond();
171 VERIFY(rcond_est >= rcond / 10 && rcond_est <= rcond * 10);
177 vecX = ldltup.
solve(vecB);
179 matX = ldltup.
solve(matB);
184 const MatrixType symmUp_inverse = ldltup.
solve(MatrixType::Identity(rows,cols));
185 rcond = (
RealScalar(1) / matrix_l1_norm<MatrixType, Upper>(symmUp)) /
186 matrix_l1_norm<MatrixType, Upper>(symmUp_inverse);
187 rcond_est = ldltup.
rcond();
188 VERIFY(rcond_est >= rcond / 10 && rcond_est <= rcond * 10);
195 if(MatrixType::RowsAtCompileTime==
Dynamic)
217 SquareMatrixType
A =
symm;
218 Index c = internal::random<Index>(0,rows-2);
219 A.bottomRightCorner(c,c).setZero();
226 vecX = ldltlo.solve(vecB);
233 Index r = internal::random<Index>(1,rows-1);
235 SquareMatrixType
A = a * a.adjoint();
242 vecX = ldltlo.solve(vecB);
251 RealScalar
s = (
std::min)(16,std::numeric_limits<RealScalar>::max_exponent10/8);
256 SquareMatrixType
A = a * d.asDiagonal() * a.adjoint();
263 vecX = ldltlo.solve(vecB);
265 if(ldltlo.vectorD().real().cwiseAbs().minCoeff()>
RealScalar(0))
271 RealScalar large_tol =
sqrt(test_precision<RealScalar>());
282 CALL_SUBTEST(( test_chol_update<SquareMatrixType,LLT>(symm) ));
283 CALL_SUBTEST(( test_chol_update<SquareMatrixType,LDLT>(symm) ));
301 RealMatrixType a0 = RealMatrixType::Random(rows,cols);
302 VectorType vecB = VectorType::Random(rows), vecX(rows);
304 RealMatrixType
symm = a0 * a0.adjoint();
306 for (
int k=0; k<3; ++k)
308 RealMatrixType
a1 = RealMatrixType::Random(rows,cols);
309 symm += a1 * a1.adjoint();
318 check_solverbase<VectorType, VectorType>(
symm, chollo,
rows,
rows, 1);
324 int sign = internal::random<int>()%2 ? 1 : -1;
337 check_solverbase<VectorType, VectorType>(
symm, ldltlo,
rows,
rows, 1);
354 VectorType vecX = matA.ldlt().solve(vecB);
422 #if (!EIGEN_ARCH_i386) || defined(EIGEN_VECTORIZE_SSE2) 426 -3, -8.9999999999999999999, 1,
445 mat << 0.1, 0, -0.1, 0, 0, 0, 1, 0,
446 0, 4.24667, 0, 2.00333, 0, 0, 0, 0,
447 -0.1, 0, 0.2, 0, -0.1, 0, 0, 0,
448 0, 2.00333, 0, 8.49333, 0, 2.00333, 0, 0,
449 0, 0, -0.1, 0, 0.1, 0, 0, 1,
450 0, 0, 0, 2.00333, 0, 4.24667, 0, 0,
451 1, 0, 0, 0, 0, 0, 0, 0,
452 0, 0, 0, 0, 1, 0, 0, 0;
ComputationInfo info() const
Reports whether previous computation was successful.
Robust Cholesky decomposition of a matrix with pivoting.
MatrixType::RealScalar matrix_l1_norm(const MatrixType &m)
const Solve< LLT< _MatrixType, _UpLo >, Rhs > solve(const MatrixBase< Rhs > &b) const
#define VERIFY_RAISES_ASSERT(a)
#define CALL_SUBTEST_9(FUNC)
#define CALL_SUBTEST_6(FUNC)
#define CALL_SUBTEST_4(FUNC)
LDLT & compute(const EigenBase< InputType > &matrix)
Traits::MatrixU matrixU() const
MatrixType reconstructedMatrix() const
#define CALL_SUBTEST_3(FUNC)
#define CALL_SUBTEST_7(FUNC)
const LLT & adjoint() const EIGEN_NOEXCEPT
#define STATIC_CHECK(COND)
const Eigen::CwiseBinaryOp< Eigen::internal::scalar_pow_op< typename Derived::Scalar, typename ExponentDerived::Scalar >, const Derived, const ExponentDerived > pow(const Eigen::ArrayBase< Derived > &x, const Eigen::ArrayBase< ExponentDerived > &exponents)
void cholesky_faillure_cases()
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Traits::MatrixL matrixL() const
bool isNegative(void) const
static long int nb_temporaries
void cholesky_definiteness(const MatrixType &m)
#define VERIFY_EVALUATION_COUNT(XPR, N)
#define VERIFY_IS_APPROX(a, b)
EIGEN_DONT_INLINE void llt(const Mat &A, const Mat &B, Mat &C)
EIGEN_DECLARE_TEST(cholesky)
#define CALL_SUBTEST_1(FUNC)
ConstTransposeReturnType transpose() const
Standard Cholesky decomposition (LL^T) of a matrix and associated features.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
EIGEN_DEVICE_FUNC const SignReturnType sign() const
#define CALL_SUBTEST_8(FUNC)
NumTraits< Scalar >::Real RealScalar
void cholesky_bug241(const MatrixType &m)
void cholesky_verify_assert()
void test_chol_update(const MatrixType &symm)
Traits::MatrixL matrixL() const
#define TEST_SET_BUT_UNUSED_VARIABLE(X)
void cholesky(const MatrixType &m)
#define CALL_SUBTEST_5(FUNC)
#define CALL_SUBTEST(FUNC)
#define EIGEN_TEST_MAX_SIZE
A triangularView< Lower >().adjoint().solveInPlace(B)
Traits::MatrixU matrixU() const
MatrixType reconstructedMatrix() const
static const double sigma
#define VERIFY_IS_NOT_APPROX(a, b)
#define CALL_SUBTEST_2(FUNC)
Jet< T, N > sqrt(const Jet< T, N > &f)
Jet< T, N > pow(const Jet< T, N > &f, double g)
The matrix class, also used for vectors and row-vectors.
EIGEN_DEVICE_FUNC bool isApprox(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
int EIGEN_BLAS_FUNC() symm(const char *side, const char *uplo, const int *m, const int *n, const RealScalar *palpha, const RealScalar *pa, const int *lda, const RealScalar *pb, const int *ldb, const RealScalar *pbeta, RealScalar *pc, const int *ldc)
Derived & setRandom(Index size)
void cholesky_cplx(const MatrixType &m)
void solveInPlace(const MatrixBase< Derived > &bAndX) const