10 #ifndef EIGEN_NO_ASSERTION_CHECKING 11 #define EIGEN_NO_ASSERTION_CHECKING 14 #define TEST_ENABLE_TEMPORARY_TRACKING 17 #include <Eigen/Cholesky> 20 template<
typename MatrixType,
int UpLo>
24 return symm.cwiseAbs().colwise().sum().maxCoeff();
34 MatrixType symmUp = symm.template triangularView<Upper>();
37 CholType<MatrixType,Lower> chollo(symmLo);
38 CholType<MatrixType,Upper> cholup(symmUp);
40 for (
int k=0; k<10; ++k)
42 VectorType vec = VectorType::Random(symm.rows());
43 RealScalar
sigma = internal::random<RealScalar>();
44 symmCpy += sigma * vec * vec.adjoint();
47 CholType<MatrixType,Lower> chol(symmCpy);
51 chollo.rankUpdate(vec, sigma);
54 cholup.rankUpdate(vec, sigma);
73 VectorType vecB = VectorType::Random(rows), vecX(rows);
75 SquareMatrixType
symm = a0 * a0.adjoint();
77 for (
int k=0; k<3; ++k)
80 symm += a1 * a1.adjoint();
84 SquareMatrixType symmUp = symm.template triangularView<Upper>();
89 vecX = chollo.solve(vecB);
91 matX = chollo.solve(matB);
94 const MatrixType symmLo_inverse = chollo.solve(MatrixType::Identity(rows,cols));
95 RealScalar rcond = (
RealScalar(1) / matrix_l1_norm<MatrixType, Lower>(symmLo)) /
96 matrix_l1_norm<MatrixType, Lower>(symmLo_inverse);
97 RealScalar rcond_est = chollo.rcond();
100 VERIFY(rcond_est >= rcond / 10 && rcond_est <= rcond * 10);
105 vecX = cholup.
solve(vecB);
107 matX = cholup.
solve(matB);
112 const MatrixType symmUp_inverse = cholup.
solve(MatrixType::Identity(rows,cols));
113 rcond = (
RealScalar(1) / matrix_l1_norm<MatrixType, Upper>(symmUp)) /
114 matrix_l1_norm<MatrixType, Upper>(symmUp_inverse);
115 rcond_est = cholup.
rcond();
116 VERIFY(rcond_est >= rcond / 10 && rcond_est <= rcond * 10);
131 m2 += symmLo.template selfadjointView<Lower>().llt().solve(matB);
132 VERIFY_IS_APPROX(
m2, m1 + symmLo.template selfadjointView<Lower>().llt().solve(matB));
134 m2 -= symmLo.template selfadjointView<Lower>().llt().solve(matB);
135 VERIFY_IS_APPROX(m2, m1 - symmLo.template selfadjointView<Lower>().llt().solve(matB));
137 m2.noalias() += symmLo.template selfadjointView<Lower>().llt().solve(matB);
138 VERIFY_IS_APPROX(m2, m1 + symmLo.template selfadjointView<Lower>().llt().solve(matB));
140 m2.noalias() -= symmLo.template selfadjointView<Lower>().llt().solve(matB);
141 VERIFY_IS_APPROX(m2, m1 - symmLo.template selfadjointView<Lower>().llt().solve(matB));
146 int sign = internal::random<int>()%2 ? 1 : -1;
153 SquareMatrixType symmUp = symm.template triangularView<Upper>();
159 vecX = ldltlo.solve(vecB);
161 matX = ldltlo.solve(matB);
164 const MatrixType symmLo_inverse = ldltlo.solve(MatrixType::Identity(rows,cols));
165 RealScalar rcond = (
RealScalar(1) / matrix_l1_norm<MatrixType, Lower>(symmLo)) /
166 matrix_l1_norm<MatrixType, Lower>(symmLo_inverse);
167 RealScalar rcond_est = ldltlo.rcond();
170 VERIFY(rcond_est >= rcond / 10 && rcond_est <= rcond * 10);
176 vecX = ldltup.
solve(vecB);
178 matX = ldltup.
solve(matB);
183 const MatrixType symmUp_inverse = ldltup.
solve(MatrixType::Identity(rows,cols));
184 rcond = (
RealScalar(1) / matrix_l1_norm<MatrixType, Upper>(symmUp)) /
185 matrix_l1_norm<MatrixType, Upper>(symmUp_inverse);
186 rcond_est = ldltup.
rcond();
187 VERIFY(rcond_est >= rcond / 10 && rcond_est <= rcond * 10);
194 if(MatrixType::RowsAtCompileTime==
Dynamic)
216 SquareMatrixType
A =
symm;
217 Index c = internal::random<Index>(0,rows-2);
218 A.bottomRightCorner(c,c).setZero();
225 vecX = ldltlo.solve(vecB);
232 Index r = internal::random<Index>(1,rows-1);
234 SquareMatrixType
A = a * a.adjoint();
241 vecX = ldltlo.solve(vecB);
250 RealScalar
s = (
std::min)(16,std::numeric_limits<RealScalar>::max_exponent10/8);
255 SquareMatrixType
A = a * d.asDiagonal() * a.adjoint();
262 vecX = ldltlo.solve(vecB);
264 if(ldltlo.vectorD().real().cwiseAbs().minCoeff()>
RealScalar(0))
270 RealScalar large_tol =
sqrt(test_precision<RealScalar>());
281 CALL_SUBTEST(( test_chol_update<SquareMatrixType,LLT>(symm) ));
282 CALL_SUBTEST(( test_chol_update<SquareMatrixType,LDLT>(symm) ));
300 RealMatrixType a0 = RealMatrixType::Random(rows,cols);
301 VectorType vecB = VectorType::Random(rows), vecX(rows);
303 RealMatrixType
symm = a0 * a0.adjoint();
305 for (
int k=0; k<3; ++k)
307 RealMatrixType a1 = RealMatrixType::Random(rows,cols);
308 symm += a1 * a1.adjoint();
316 vecX = chollo.solve(vecB);
324 int sign = internal::random<int>()%2 ? 1 : -1;
336 vecX = ldltlo.solve(vecB);
355 VectorType vecX = matA.ldlt().solve(vecB);
423 #if (!EIGEN_ARCH_i386) || defined(EIGEN_VECTORIZE_SSE2) 427 -3, -8.9999999999999999999, 1,
446 mat << 0.1, 0, -0.1, 0, 0, 0, 1, 0,
447 0, 4.24667, 0, 2.00333, 0, 0, 0, 0,
448 -0.1, 0, 0.2, 0, -0.1, 0, 0, 0,
449 0, 2.00333, 0, 8.49333, 0, 2.00333, 0, 0,
450 0, 0, -0.1, 0, 0.1, 0, 0, 1,
451 0, 0, 0, 2.00333, 0, 4.24667, 0, 0,
452 1, 0, 0, 0, 0, 0, 0, 0,
453 0, 0, 0, 0, 1, 0, 0, 0;
497 CALL_SUBTEST_3(
cholesky(Matrix2d()) );
500 CALL_SUBTEST_4(
cholesky(Matrix3f()) );
501 CALL_SUBTEST_5(
cholesky(Matrix4d()) );
504 CALL_SUBTEST_2(
cholesky(MatrixXd(s,s)) );
512 CALL_SUBTEST_2(
cholesky(MatrixXd(0,0)) );
517 CALL_SUBTEST_4( cholesky_verify_assert<Matrix3f>() );
518 CALL_SUBTEST_7( cholesky_verify_assert<Matrix3d>() );
519 CALL_SUBTEST_8( cholesky_verify_assert<MatrixXf>() );
520 CALL_SUBTEST_2( cholesky_verify_assert<MatrixXd>() );
526 CALL_SUBTEST_2( cholesky_faillure_cases<void>() );
Robust Cholesky decomposition of a matrix with pivoting.
MatrixType::RealScalar matrix_l1_norm(const MatrixType &m)
#define VERIFY_RAISES_ASSERT(a)
MatrixType reconstructedMatrix() const
LDLT & compute(const EigenBase< InputType > &matrix)
Traits::MatrixU matrixU() const
static const double sigma
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
void cholesky_faillure_cases()
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
const Solve< LLT, Rhs > solve(const MatrixBase< Rhs > &b) const
static long int nb_temporaries
void cholesky_definiteness(const MatrixType &m)
#define VERIFY_EVALUATION_COUNT(XPR, N)
internal::enable_if< !(internal::is_same< typename Derived::Scalar, ScalarExponent >::value)&&EIGEN_SCALAR_BINARY_SUPPORTED(pow, typename Derived::Scalar, ScalarExponent), const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived, ScalarExponent, pow) >::type pow(const Eigen::ArrayBase< Derived > &x, const ScalarExponent &exponent)
#define VERIFY_IS_APPROX(a, b)
EIGEN_DEVICE_FUNC const SignReturnType sign() 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.
bool isNegative(void) const
void solveInPlace(const MatrixBase< Derived > &bAndX) const
MatrixType reconstructedMatrix() const
NumTraits< Scalar >::Real RealScalar
void cholesky_bug241(const MatrixType &m)
void cholesky_verify_assert()
Traits::MatrixU matrixU() const
void test_chol_update(const MatrixType &symm)
const Solve< LDLT, Rhs > solve(const MatrixBase< Rhs > &b) const
#define TEST_SET_BUT_UNUSED_VARIABLE(X)
void cholesky(const MatrixType &m)
ComputationInfo info() const
Reports whether previous computation was successful.
#define CALL_SUBTEST(FUNC)
#define EIGEN_TEST_MAX_SIZE
A triangularView< Lower >().adjoint().solveInPlace(B)
Traits::MatrixL matrixL() const
#define VERIFY_IS_NOT_APPROX(a, b)
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())
Traits::MatrixL matrixL() const
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)