cholesky.cpp File Reference
#include "main.h"
#include <Eigen/Cholesky>
#include <Eigen/QR>
#include "solverbase.h"

Macros

#define TEST_ENABLE_TEMPORARY_TRACKING
 

Functions

template<typename MatrixType , int UpLo>
MatrixType::RealScalar matrix_l1_norm (const MatrixType &m)
 
template<typename MatrixType , template< typename, int > class CholType>
void test_chol_update (const MatrixType &symm)
 
template<typename MatrixType >
void cholesky (const MatrixType &m)
 
template<typename MatrixType >
void cholesky_cplx (const MatrixType &m)
 
template<typename MatrixType >
void cholesky_bug241 (const MatrixType &m)
 
template<typename MatrixType >
void cholesky_definiteness (const MatrixType &m)
 
template<typename >
void cholesky_faillure_cases ()
 
template<typename MatrixType >
void cholesky_verify_assert ()
 
 EIGEN_DECLARE_TEST (cholesky)
 

Macro Definition Documentation

◆ TEST_ENABLE_TEMPORARY_TRACKING

#define TEST_ENABLE_TEMPORARY_TRACKING

Function Documentation

◆ cholesky()

template<typename MatrixType >
void cholesky ( const MatrixType m)
55  {
56  /* this test covers the following files:
57  LLT.h LDLT.h
58  */
59  Index rows = m.rows();
60  Index cols = m.cols();
61 
62  typedef typename MatrixType::Scalar Scalar;
63  typedef typename NumTraits<Scalar>::Real RealScalar;
66 
67  MatrixType a0 = MatrixType::Random(rows, cols);
68  VectorType vecB = VectorType::Random(rows), vecX(rows);
69  MatrixType matB = MatrixType::Random(rows, cols), matX(rows, cols);
70  SquareMatrixType symm = a0 * a0.adjoint();
71  // let's make sure the matrix is not singular or near singular
72  for (int k = 0; k < 3; ++k) {
73  MatrixType a1 = MatrixType::Random(rows, cols);
74  symm += a1 * a1.adjoint();
75  }
76 
77  {
78  STATIC_CHECK((internal::is_same<typename LLT<MatrixType, Lower>::StorageIndex, int>::value));
79  STATIC_CHECK((internal::is_same<typename LLT<MatrixType, Upper>::StorageIndex, int>::value));
80 
81  SquareMatrixType symmUp = symm.template triangularView<Upper>();
82  SquareMatrixType symmLo = symm.template triangularView<Lower>();
83 
84  LLT<SquareMatrixType, Lower> chollo(symmLo);
85  VERIFY_IS_APPROX(symm, chollo.reconstructedMatrix());
86 
87  check_solverbase<VectorType, VectorType>(symm, chollo, rows, rows, 1);
88  check_solverbase<MatrixType, MatrixType>(symm, chollo, rows, cols, rows);
89 
90  const MatrixType symmLo_inverse = chollo.solve(MatrixType::Identity(rows, cols));
91  RealScalar rcond =
92  (RealScalar(1) / matrix_l1_norm<MatrixType, Lower>(symmLo)) / matrix_l1_norm<MatrixType, Lower>(symmLo_inverse);
93  RealScalar rcond_est = chollo.rcond();
94  // Verify that the estimated condition number is within a factor of 10 of the
95  // truth.
96  VERIFY(rcond_est >= rcond / 10 && rcond_est <= rcond * 10);
97 
98  // test the upper mode
99  LLT<SquareMatrixType, Upper> cholup(symmUp);
100  VERIFY_IS_APPROX(symm, cholup.reconstructedMatrix());
101  vecX = cholup.solve(vecB);
102  VERIFY_IS_APPROX(symm * vecX, vecB);
103  matX = cholup.solve(matB);
104  VERIFY_IS_APPROX(symm * matX, matB);
105 
106  // Verify that the estimated condition number is within a factor of 10 of the
107  // truth.
108  const MatrixType symmUp_inverse = cholup.solve(MatrixType::Identity(rows, cols));
109  rcond =
110  (RealScalar(1) / matrix_l1_norm<MatrixType, Upper>(symmUp)) / matrix_l1_norm<MatrixType, Upper>(symmUp_inverse);
111  rcond_est = cholup.rcond();
112  VERIFY(rcond_est >= rcond / 10 && rcond_est <= rcond * 10);
113 
114  MatrixType neg = -symmLo;
115  chollo.compute(neg);
116  VERIFY(neg.size() == 0 || chollo.info() == NumericalIssue);
117 
118  VERIFY_IS_APPROX(MatrixType(chollo.matrixL().transpose().conjugate()), MatrixType(chollo.matrixU()));
119  VERIFY_IS_APPROX(MatrixType(chollo.matrixU().transpose().conjugate()), MatrixType(chollo.matrixL()));
120  VERIFY_IS_APPROX(MatrixType(cholup.matrixL().transpose().conjugate()), MatrixType(cholup.matrixU()));
121  VERIFY_IS_APPROX(MatrixType(cholup.matrixU().transpose().conjugate()), MatrixType(cholup.matrixL()));
122 
123  // test some special use cases of SelfCwiseBinaryOp:
124  MatrixType m1 = MatrixType::Random(rows, cols), m2(rows, cols);
125  m2 = m1;
126  m2 += symmLo.template selfadjointView<Lower>().llt().solve(matB);
127  VERIFY_IS_APPROX(m2, m1 + symmLo.template selfadjointView<Lower>().llt().solve(matB));
128  m2 = m1;
129  m2 -= symmLo.template selfadjointView<Lower>().llt().solve(matB);
130  VERIFY_IS_APPROX(m2, m1 - symmLo.template selfadjointView<Lower>().llt().solve(matB));
131  m2 = m1;
132  m2.noalias() += symmLo.template selfadjointView<Lower>().llt().solve(matB);
133  VERIFY_IS_APPROX(m2, m1 + symmLo.template selfadjointView<Lower>().llt().solve(matB));
134  m2 = m1;
135  m2.noalias() -= symmLo.template selfadjointView<Lower>().llt().solve(matB);
136  VERIFY_IS_APPROX(m2, m1 - symmLo.template selfadjointView<Lower>().llt().solve(matB));
137  }
138 
139  // LDLT
140  {
141  STATIC_CHECK((internal::is_same<typename LDLT<MatrixType, Lower>::StorageIndex, int>::value));
142  STATIC_CHECK((internal::is_same<typename LDLT<MatrixType, Upper>::StorageIndex, int>::value));
143 
144  int sign = internal::random<int>() % 2 ? 1 : -1;
145 
146  if (sign == -1) {
147  symm = -symm; // test a negative matrix
148  }
149 
150  SquareMatrixType symmUp = symm.template triangularView<Upper>();
151  SquareMatrixType symmLo = symm.template triangularView<Lower>();
152 
153  LDLT<SquareMatrixType, Lower> ldltlo(symmLo);
154  VERIFY(ldltlo.info() == Success);
155  VERIFY_IS_APPROX(symm, ldltlo.reconstructedMatrix());
156 
157  check_solverbase<VectorType, VectorType>(symm, ldltlo, rows, rows, 1);
158  check_solverbase<MatrixType, MatrixType>(symm, ldltlo, rows, cols, rows);
159 
160  const MatrixType symmLo_inverse = ldltlo.solve(MatrixType::Identity(rows, cols));
161  RealScalar rcond =
162  (RealScalar(1) / matrix_l1_norm<MatrixType, Lower>(symmLo)) / matrix_l1_norm<MatrixType, Lower>(symmLo_inverse);
163  RealScalar rcond_est = ldltlo.rcond();
164  // Verify that the estimated condition number is within a factor of 10 of the
165  // truth.
166  VERIFY(rcond_est >= rcond / 10 && rcond_est <= rcond * 10);
167 
168  LDLT<SquareMatrixType, Upper> ldltup(symmUp);
169  VERIFY(ldltup.info() == Success);
170  VERIFY_IS_APPROX(symm, ldltup.reconstructedMatrix());
171  vecX = ldltup.solve(vecB);
172  VERIFY_IS_APPROX(symm * vecX, vecB);
173  matX = ldltup.solve(matB);
174  VERIFY_IS_APPROX(symm * matX, matB);
175 
176  // Verify that the estimated condition number is within a factor of 10 of the
177  // truth.
178  const MatrixType symmUp_inverse = ldltup.solve(MatrixType::Identity(rows, cols));
179  rcond =
180  (RealScalar(1) / matrix_l1_norm<MatrixType, Upper>(symmUp)) / matrix_l1_norm<MatrixType, Upper>(symmUp_inverse);
181  rcond_est = ldltup.rcond();
182  VERIFY(rcond_est >= rcond / 10 && rcond_est <= rcond * 10);
183 
184  VERIFY_IS_APPROX(MatrixType(ldltlo.matrixL().transpose().conjugate()), MatrixType(ldltlo.matrixU()));
185  VERIFY_IS_APPROX(MatrixType(ldltlo.matrixU().transpose().conjugate()), MatrixType(ldltlo.matrixL()));
186  VERIFY_IS_APPROX(MatrixType(ldltup.matrixL().transpose().conjugate()), MatrixType(ldltup.matrixU()));
187  VERIFY_IS_APPROX(MatrixType(ldltup.matrixU().transpose().conjugate()), MatrixType(ldltup.matrixL()));
188 
189  if (MatrixType::RowsAtCompileTime == Dynamic) {
190  // note : each inplace permutation requires a small temporary vector (mask)
191 
192  // check inplace solve
193  matX = matB;
194  VERIFY_EVALUATION_COUNT(matX = ldltlo.solve(matX), 0);
195  VERIFY_IS_APPROX(matX, ldltlo.solve(matB).eval());
196 
197  matX = matB;
198  VERIFY_EVALUATION_COUNT(matX = ldltup.solve(matX), 0);
199  VERIFY_IS_APPROX(matX, ldltup.solve(matB).eval());
200  }
201 
202  // restore
203  if (sign == -1) symm = -symm;
204 
205  // check matrices coming from linear constraints with Lagrange multipliers
206  if (rows >= 3) {
207  SquareMatrixType A = symm;
208  Index c = internal::random<Index>(0, rows - 2);
209  A.bottomRightCorner(c, c).setZero();
210  // Make sure a solution exists:
211  vecX.setRandom();
212  vecB = A * vecX;
213  vecX.setZero();
214  ldltlo.compute(A);
215  VERIFY_IS_APPROX(A, ldltlo.reconstructedMatrix());
216  vecX = ldltlo.solve(vecB);
217  VERIFY_IS_APPROX(A * vecX, vecB);
218  }
219 
220  // check non-full rank matrices
221  if (rows >= 3) {
222  Index r = internal::random<Index>(1, rows - 1);
224  SquareMatrixType A = a * a.adjoint();
225  // Make sure a solution exists:
226  vecX.setRandom();
227  vecB = A * vecX;
228  vecX.setZero();
229  ldltlo.compute(A);
230  VERIFY_IS_APPROX(A, ldltlo.reconstructedMatrix());
231  vecX = ldltlo.solve(vecB);
232  VERIFY_IS_APPROX(A * vecX, vecB);
233  }
234 
235  // check matrices with a wide spectrum
236  if (rows >= 3) {
237  using std::pow;
238  using std::sqrt;
239  RealScalar s = (std::min)(16, std::numeric_limits<RealScalar>::max_exponent10 / 8);
242  for (Index k = 0; k < rows; ++k) d(k) = d(k) * pow(RealScalar(10), internal::random<RealScalar>(-s, s));
243  SquareMatrixType A = a * d.asDiagonal() * a.adjoint();
244  // Make sure a solution exists:
245  vecX.setRandom();
246  vecB = A * vecX;
247  vecX.setZero();
248  ldltlo.compute(A);
249  VERIFY_IS_APPROX(A, ldltlo.reconstructedMatrix());
250  vecX = ldltlo.solve(vecB);
251 
252  if (ldltlo.vectorD().real().cwiseAbs().minCoeff() > RealScalar(0)) {
253  VERIFY_IS_APPROX(A * vecX, vecB);
254  } else {
255  RealScalar large_tol = sqrt(test_precision<RealScalar>());
256  VERIFY((A * vecX).isApprox(vecB, large_tol));
257 
258  ++g_test_level;
259  VERIFY_IS_APPROX(A * vecX, vecB);
260  --g_test_level;
261  }
262  }
263  }
264 
265  // update/downdate
266  CALL_SUBTEST((test_chol_update<SquareMatrixType, LLT>(symm)));
267  CALL_SUBTEST((test_chol_update<SquareMatrixType, LDLT>(symm)));
268 }
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
Matrix3d m1
Definition: IOFormat.cpp:2
MatrixXf matB(2, 2)
MatrixType m2(n_dims)
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
SCALAR Scalar
Definition: bench_gemm.cpp:45
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Robust Cholesky decomposition of a matrix with pivoting.
Definition: LDLT.h:63
Standard Cholesky decomposition (LL^T) of a matrix and associated features.
Definition: LLT.h:70
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:569
Derived & setRandom(Index size)
Definition: Random.h:147
#define min(a, b)
Definition: datatypes.h:22
@ NumericalIssue
Definition: Constants.h:442
@ Success
Definition: Constants.h:440
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
RealScalar s
Definition: level1_cplx_impl.h:130
const Scalar * a
Definition: level2_cplx_impl.h:32
int * m
Definition: level2_cplx_impl.h:294
char char char int int * k
Definition: level2_impl.h:374
#define VERIFY(a)
Definition: main.h:362
#define STATIC_CHECK(COND)
Definition: main.h:380
#define CALL_SUBTEST(FUNC)
Definition: main.h:382
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 pow(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:625
EIGEN_DEVICE_FUNC bool isApprox(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
Definition: MathFunctions.h:1923
squared absolute value
Definition: GlobalFunctions.h:87
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
static int g_test_level
Definition: main.h:190
const int Dynamic
Definition: Constants.h:25
T sign(T x)
Definition: cxx11_tensor_builtins_sycl.cpp:172
r
Definition: UniformPSDSelfTest.py:20
int c
Definition: calibrate.py:100
void symm(int size=Size, int othersize=OtherSize)
Definition: product_symm.cpp:13
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217
Definition: fft_test_shared.h:66
#define VERIFY_EVALUATION_COUNT(XPR, N)
Definition: test/sparse_product.cpp:28

References a, calibrate::c, CALL_SUBTEST, cols, Eigen::LDLT< MatrixType_, UpLo_ >::compute(), Eigen::LLT< MatrixType_, UpLo_ >::compute(), Eigen::Dynamic, Eigen::g_test_level, Eigen::LDLT< MatrixType_, UpLo_ >::info(), Eigen::LLT< MatrixType_, UpLo_ >::info(), Eigen::internal::isApprox(), k, m, m1, m2(), matB(), Eigen::LDLT< MatrixType_, UpLo_ >::matrixL(), Eigen::LLT< MatrixType_, UpLo_ >::matrixL(), Eigen::LDLT< MatrixType_, UpLo_ >::matrixU(), Eigen::LLT< MatrixType_, UpLo_ >::matrixU(), min, Eigen::NumericalIssue, Eigen::bfloat16_impl::pow(), UniformPSDSelfTest::r, Eigen::LDLT< MatrixType_, UpLo_ >::rcond(), Eigen::LLT< MatrixType_, UpLo_ >::rcond(), Eigen::LDLT< MatrixType_, UpLo_ >::reconstructedMatrix(), Eigen::LLT< MatrixType_, UpLo_ >::reconstructedMatrix(), rows, s, Eigen::PlainObjectBase< Derived >::setZero(), SYCL::sign(), Eigen::SolverBase< Derived >::solve(), sqrt(), STATIC_CHECK, Eigen::Success, symm(), Eigen::value, Eigen::LDLT< MatrixType_, UpLo_ >::vectorD(), VERIFY, VERIFY_EVALUATION_COUNT, and VERIFY_IS_APPROX.

Referenced by cholesky_cplx(), and EIGEN_DECLARE_TEST().

◆ cholesky_bug241()

template<typename MatrixType >
void cholesky_bug241 ( const MatrixType m)
326  {
327  eigen_assert(m.rows() == 2 && m.cols() == 2);
328 
329  typedef typename MatrixType::Scalar Scalar;
331 
333  matA << 1, 1, 1, 1;
334  VectorType vecB;
335  vecB << 1, 1;
336  VectorType vecX = matA.ldlt().solve(vecB);
337  VERIFY_IS_APPROX(matA * vecX, vecB);
338 }
#define eigen_assert(x)
Definition: Macros.h:910
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > matA(size, size)

References eigen_assert, m, matA(), and VERIFY_IS_APPROX.

Referenced by EIGEN_DECLARE_TEST().

◆ cholesky_cplx()

template<typename MatrixType >
void cholesky_cplx ( const MatrixType m)
271  {
272  // classic test
273  cholesky(m);
274 
275  // test mixing real/scalar types
276 
277  Index rows = m.rows();
278  Index cols = m.cols();
279 
280  typedef typename MatrixType::Scalar Scalar;
281  typedef typename NumTraits<Scalar>::Real RealScalar;
284 
285  RealMatrixType a0 = RealMatrixType::Random(rows, cols);
286  VectorType vecB = VectorType::Random(rows), vecX(rows);
287  MatrixType matB = MatrixType::Random(rows, cols), matX(rows, cols);
288  RealMatrixType symm = a0 * a0.adjoint();
289  // let's make sure the matrix is not singular or near singular
290  for (int k = 0; k < 3; ++k) {
291  RealMatrixType a1 = RealMatrixType::Random(rows, cols);
292  symm += a1 * a1.adjoint();
293  }
294 
295  {
296  RealMatrixType symmLo = symm.template triangularView<Lower>();
297 
298  LLT<RealMatrixType, Lower> chollo(symmLo);
299  VERIFY_IS_APPROX(symm, chollo.reconstructedMatrix());
300 
301  check_solverbase<VectorType, VectorType>(symm, chollo, rows, rows, 1);
302  // check_solverbase<MatrixType, MatrixType>(symm, chollo, rows, cols, rows);
303  }
304 
305  // LDLT
306  {
307  int sign = internal::random<int>() % 2 ? 1 : -1;
308 
309  if (sign == -1) {
310  symm = -symm; // test a negative matrix
311  }
312 
313  RealMatrixType symmLo = symm.template triangularView<Lower>();
314 
315  LDLT<RealMatrixType, Lower> ldltlo(symmLo);
316  VERIFY(ldltlo.info() == Success);
317  VERIFY_IS_APPROX(symm, ldltlo.reconstructedMatrix());
318 
319  check_solverbase<VectorType, VectorType>(symm, ldltlo, rows, rows, 1);
320  // check_solverbase<MatrixType, MatrixType>(symm, ldltlo, rows, cols, rows);
321  }
322 }
void cholesky(const MatrixType &m)
Definition: cholesky.cpp:55

References cholesky(), cols, Eigen::LDLT< MatrixType_, UpLo_ >::info(), k, m, matB(), Eigen::LDLT< MatrixType_, UpLo_ >::reconstructedMatrix(), Eigen::LLT< MatrixType_, UpLo_ >::reconstructedMatrix(), rows, SYCL::sign(), Eigen::Success, symm(), VERIFY, and VERIFY_IS_APPROX.

Referenced by EIGEN_DECLARE_TEST().

◆ cholesky_definiteness()

template<typename MatrixType >
void cholesky_definiteness ( const MatrixType m)
344  {
345  eigen_assert(m.rows() == 2 && m.cols() == 2);
346  MatrixType mat;
347  LDLT<MatrixType> ldlt(2);
348 
349  {
350  mat << 1, 0, 0, -1;
351  ldlt.compute(mat);
352  VERIFY(ldlt.info() == Success);
353  VERIFY(!ldlt.isNegative());
354  VERIFY(!ldlt.isPositive());
355  VERIFY_IS_APPROX(mat, ldlt.reconstructedMatrix());
356  }
357  {
358  mat << 1, 2, 2, 1;
359  ldlt.compute(mat);
360  VERIFY(ldlt.info() == Success);
361  VERIFY(!ldlt.isNegative());
362  VERIFY(!ldlt.isPositive());
363  VERIFY_IS_APPROX(mat, ldlt.reconstructedMatrix());
364  }
365  {
366  mat << 0, 0, 0, 0;
367  ldlt.compute(mat);
368  VERIFY(ldlt.info() == Success);
369  VERIFY(ldlt.isNegative());
370  VERIFY(ldlt.isPositive());
371  VERIFY_IS_APPROX(mat, ldlt.reconstructedMatrix());
372  }
373  {
374  mat << 0, 0, 0, 1;
375  ldlt.compute(mat);
376  VERIFY(ldlt.info() == Success);
377  VERIFY(!ldlt.isNegative());
378  VERIFY(ldlt.isPositive());
379  VERIFY_IS_APPROX(mat, ldlt.reconstructedMatrix());
380  }
381  {
382  mat << -1, 0, 0, 0;
383  ldlt.compute(mat);
384  VERIFY(ldlt.info() == Success);
385  VERIFY(ldlt.isNegative());
386  VERIFY(!ldlt.isPositive());
387  VERIFY_IS_APPROX(mat, ldlt.reconstructedMatrix());
388  }
389 }
Eigen::SparseMatrix< double > mat
Definition: EigenUnitTest.cpp:10

References Eigen::LDLT< MatrixType_, UpLo_ >::compute(), eigen_assert, Eigen::LDLT< MatrixType_, UpLo_ >::info(), Eigen::LDLT< MatrixType_, UpLo_ >::isNegative(), Eigen::LDLT< MatrixType_, UpLo_ >::isPositive(), m, Eigen::LDLT< MatrixType_, UpLo_ >::reconstructedMatrix(), Eigen::Success, VERIFY, and VERIFY_IS_APPROX.

Referenced by EIGEN_DECLARE_TEST().

◆ cholesky_faillure_cases()

template<typename >
void cholesky_faillure_cases ( )
392  {
393  MatrixXd mat;
394  LDLT<MatrixXd> ldlt;
395 
396  {
397  mat.resize(2, 2);
398  mat << 0, 1, 1, 0;
399  ldlt.compute(mat);
401  VERIFY(ldlt.info() == NumericalIssue);
402  }
403 #if (!EIGEN_ARCH_i386) || defined(EIGEN_VECTORIZE_SSE2)
404  {
405  mat.resize(3, 3);
406  mat << -1, -3, 3, -3, -8.9999999999999999999, 1, 3, 1, 0;
407  ldlt.compute(mat);
408  VERIFY(ldlt.info() == NumericalIssue);
410  }
411 #endif
412  {
413  mat.resize(3, 3);
414  mat << 1, 2, 3, 2, 4, 1, 3, 1, 0;
415  ldlt.compute(mat);
416  VERIFY(ldlt.info() == NumericalIssue);
418  }
419 
420  {
421  mat.resize(8, 8);
422  mat << 0.1, 0, -0.1, 0, 0, 0, 1, 0, 0, 4.24667, 0, 2.00333, 0, 0, 0, 0, -0.1, 0, 0.2, 0, -0.1, 0, 0, 0, 0, 2.00333,
423  0, 8.49333, 0, 2.00333, 0, 0, 0, 0, -0.1, 0, 0.1, 0, 0, 1, 0, 0, 0, 2.00333, 0, 4.24667, 0, 0, 1, 0, 0, 0, 0, 0,
424  0, 0, 0, 0, 0, 0, 1, 0, 0, 0;
425  ldlt.compute(mat);
426  VERIFY(ldlt.info() == NumericalIssue);
428  }
429 
430  // bug 1479
431  {
432  mat.resize(4, 4);
433  mat << 1, 2, 0, 1, 2, 4, 0, 2, 0, 0, 0, 1, 1, 2, 1, 1;
434  ldlt.compute(mat);
435  VERIFY(ldlt.info() == NumericalIssue);
437  }
438 }
LDLT & compute(const EigenBase< InputType > &matrix)
MatrixType reconstructedMatrix() const
Definition: LDLT.h:608
ComputationInfo info() const
Reports whether previous computation was successful.
Definition: LDLT.h:241
void resize(Index rows, Index cols)
Definition: SparseMatrix.h:734
#define VERIFY_IS_NOT_APPROX(a, b)
Definition: integer_types.cpp:15

References Eigen::LDLT< MatrixType_, UpLo_ >::compute(), Eigen::LDLT< MatrixType_, UpLo_ >::info(), Eigen::NumericalIssue, Eigen::LDLT< MatrixType_, UpLo_ >::reconstructedMatrix(), Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::resize(), VERIFY, and VERIFY_IS_NOT_APPROX.

◆ cholesky_verify_assert()

template<typename MatrixType >
void cholesky_verify_assert ( )
441  {
442  MatrixType tmp;
443 
445  VERIFY_RAISES_ASSERT(llt.matrixL())
446  VERIFY_RAISES_ASSERT(llt.matrixU())
450  VERIFY_RAISES_ASSERT(llt.solveInPlace(tmp))
451 
452  LDLT<MatrixType> ldlt;
453  VERIFY_RAISES_ASSERT(ldlt.matrixL())
454  VERIFY_RAISES_ASSERT(ldlt.transpositionsP())
455  VERIFY_RAISES_ASSERT(ldlt.vectorD())
456  VERIFY_RAISES_ASSERT(ldlt.isPositive())
457  VERIFY_RAISES_ASSERT(ldlt.isNegative())
461  VERIFY_RAISES_ASSERT(ldlt.solveInPlace(tmp))
462 }
void adjoint(const MatrixType &m)
Definition: adjoint.cpp:85
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > tmp
Definition: level3_impl.h:365
EIGEN_DONT_INLINE void llt(const Mat &A, const Mat &B, Mat &C)
Definition: llt.cpp:4
#define VERIFY_RAISES_ASSERT(a)
Definition: main.h:329
void transpose()
Definition: skew_symmetric_matrix3.cpp:135
Update the problem specs before solve
Definition: steady_axisym_advection_diffusion.cc:353

References Eigen::LDLT< MatrixType_, UpLo_ >::adjoint(), Eigen::LDLT< MatrixType_, UpLo_ >::isNegative(), Eigen::LDLT< MatrixType_, UpLo_ >::isPositive(), llt(), Eigen::LDLT< MatrixType_, UpLo_ >::matrixL(), Eigen::SolverBase< Derived >::solve(), Eigen::LDLT< MatrixType_, UpLo_ >::solveInPlace(), tmp, Eigen::SolverBase< Derived >::transpose(), Eigen::LDLT< MatrixType_, UpLo_ >::transpositionsP(), Eigen::LDLT< MatrixType_, UpLo_ >::vectorD(), and VERIFY_RAISES_ASSERT.

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( cholesky  )
464  {
465  int s = 0;
466  for (int i = 0; i < g_repeat; i++) {
468  CALL_SUBTEST_3(cholesky(Matrix2d()));
469  CALL_SUBTEST_3(cholesky_bug241(Matrix2d()));
471  CALL_SUBTEST_4(cholesky(Matrix3f()));
472  CALL_SUBTEST_5(cholesky(Matrix4d()));
473 
474  s = internal::random<int>(1, EIGEN_TEST_MAX_SIZE);
475  CALL_SUBTEST_2(cholesky(MatrixXd(s, s)));
477 
478  s = internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 2);
479  CALL_SUBTEST_6(cholesky_cplx(MatrixXcd(s, s)));
481  }
482  // empty matrix, regression test for Bug 785:
483  CALL_SUBTEST_2(cholesky(MatrixXd(0, 0)));
484 
485  // This does not work yet:
486  // CALL_SUBTEST_2( cholesky(Matrix<double,0,0>()) );
487 
488  CALL_SUBTEST_4(cholesky_verify_assert<Matrix3f>());
489  CALL_SUBTEST_7(cholesky_verify_assert<Matrix3d>());
490  CALL_SUBTEST_8(cholesky_verify_assert<MatrixXf>());
491  CALL_SUBTEST_2(cholesky_verify_assert<MatrixXd>());
492 
493  // Test problem size constructors
496 
497  CALL_SUBTEST_2(cholesky_faillure_cases<void>());
498 
500 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_TEST_MAX_SIZE
Definition: boostmultiprec.cpp:16
void cholesky_cplx(const MatrixType &m)
Definition: cholesky.cpp:271
void cholesky_definiteness(const MatrixType &m)
Definition: cholesky.cpp:344
void cholesky_bug241(const MatrixType &m)
Definition: cholesky.cpp:326
#define TEST_SET_BUT_UNUSED_VARIABLE(X)
Definition: main.h:139
static int g_repeat
Definition: main.h:191
static long int nb_temporaries
Definition: sparse_permutations.cpp:21
#define CALL_SUBTEST_6(FUNC)
Definition: split_test_helper.h:34
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
#define CALL_SUBTEST_8(FUNC)
Definition: split_test_helper.h:46
#define CALL_SUBTEST_5(FUNC)
Definition: split_test_helper.h:28
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
#define CALL_SUBTEST_7(FUNC)
Definition: split_test_helper.h:40
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22
#define CALL_SUBTEST_9(FUNC)
Definition: split_test_helper.h:52

References CALL_SUBTEST_1, CALL_SUBTEST_2, CALL_SUBTEST_3, CALL_SUBTEST_4, CALL_SUBTEST_5, CALL_SUBTEST_6, CALL_SUBTEST_7, CALL_SUBTEST_8, CALL_SUBTEST_9, cholesky(), cholesky_bug241(), cholesky_cplx(), cholesky_definiteness(), EIGEN_TEST_MAX_SIZE, Eigen::g_repeat, i, nb_temporaries, s, and TEST_SET_BUT_UNUSED_VARIABLE.

◆ matrix_l1_norm()

template<typename MatrixType , int UpLo>
MatrixType::RealScalar matrix_l1_norm ( const MatrixType m)
18  {
19  if (m.cols() == 0) return typename MatrixType::RealScalar(0);
20  MatrixType symm = m.template selfadjointView<UpLo>();
21  return symm.cwiseAbs().colwise().sum().maxCoeff();
22 }

References m, and symm().

◆ test_chol_update()

template<typename MatrixType , template< typename, int > class CholType>
void test_chol_update ( const MatrixType symm)
25  {
26  typedef typename MatrixType::Scalar Scalar;
27  typedef typename MatrixType::RealScalar RealScalar;
29 
30  MatrixType symmLo = symm.template triangularView<Lower>();
31  MatrixType symmUp = symm.template triangularView<Upper>();
32  MatrixType symmCpy = symm;
33 
34  CholType<MatrixType, Lower> chollo(symmLo);
35  CholType<MatrixType, Upper> cholup(symmUp);
36 
37  for (int k = 0; k < 10; ++k) {
38  VectorType vec = VectorType::Random(symm.rows());
39  RealScalar sigma = internal::random<RealScalar>();
40  symmCpy += sigma * vec * vec.adjoint();
41 
42  // we are doing some downdates, so it might be the case that the matrix is not SPD anymore
43  CholType<MatrixType, Lower> chol(symmCpy);
44  if (chol.info() != Success) break;
45 
46  chollo.rankUpdate(vec, sigma);
47  VERIFY_IS_APPROX(symmCpy, chollo.reconstructedMatrix());
48 
49  cholup.rankUpdate(vec, sigma);
50  VERIFY_IS_APPROX(symmCpy, cholup.reconstructedMatrix());
51  }
52 }
int sigma
Definition: calibrate.py:179

References k, calibrate::sigma, Eigen::Success, symm(), and VERIFY_IS_APPROX.