inplace_decomposition.cpp File Reference
#include "main.h"
#include <Eigen/LU>
#include <Eigen/Cholesky>
#include <Eigen/QR>

Functions

template<typename DecType , typename MatrixType >
void inplace (bool square=false, bool SPD=false)
 
 EIGEN_DECLARE_TEST (inplace_decomposition)
 

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( inplace_decomposition  )
73  {
74  EIGEN_UNUSED typedef Matrix<double, 4, 3> Matrix43d;
75  for (int i = 0; i < g_repeat; i++) {
76  CALL_SUBTEST_1((inplace<LLT<Ref<MatrixXd> >, MatrixXd>(true, true)));
77  CALL_SUBTEST_1((inplace<LLT<Ref<Matrix4d> >, Matrix4d>(true, true)));
78 
79  CALL_SUBTEST_2((inplace<LDLT<Ref<MatrixXd> >, MatrixXd>(true, true)));
80  CALL_SUBTEST_2((inplace<LDLT<Ref<Matrix4d> >, Matrix4d>(true, true)));
81 
82  CALL_SUBTEST_3((inplace<PartialPivLU<Ref<MatrixXd> >, MatrixXd>(true, false)));
83  CALL_SUBTEST_3((inplace<PartialPivLU<Ref<Matrix4d> >, Matrix4d>(true, false)));
84 
85  CALL_SUBTEST_4((inplace<FullPivLU<Ref<MatrixXd> >, MatrixXd>(true, false)));
86  CALL_SUBTEST_4((inplace<FullPivLU<Ref<Matrix4d> >, Matrix4d>(true, false)));
87 
88  CALL_SUBTEST_5((inplace<HouseholderQR<Ref<MatrixXd> >, MatrixXd>(false, false)));
89  CALL_SUBTEST_5((inplace<HouseholderQR<Ref<Matrix43d> >, Matrix43d>(false, false)));
90 
91  CALL_SUBTEST_6((inplace<ColPivHouseholderQR<Ref<MatrixXd> >, MatrixXd>(false, false)));
92  CALL_SUBTEST_6((inplace<ColPivHouseholderQR<Ref<Matrix43d> >, Matrix43d>(false, false)));
93 
94  CALL_SUBTEST_7((inplace<FullPivHouseholderQR<Ref<MatrixXd> >, MatrixXd>(false, false)));
95  CALL_SUBTEST_7((inplace<FullPivHouseholderQR<Ref<Matrix43d> >, Matrix43d>(false, false)));
96 
99  }
100 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_UNUSED
Definition: Macros.h:940
Householder rank-revealing QR decomposition of a matrix with column-pivoting.
Definition: ColPivHouseholderQR.h:54
Complete orthogonal decomposition (COD) of a matrix.
Definition: CompleteOrthogonalDecomposition.h:54
Householder rank-revealing QR decomposition of a matrix with full pivoting.
Definition: FullPivHouseholderQR.h:63
LU decomposition of a matrix with complete pivoting, and related features.
Definition: FullPivLU.h:63
Householder QR decomposition of a matrix.
Definition: HouseholderQR.h:59
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
LU decomposition of a matrix with partial pivoting, and related features.
Definition: PartialPivLU.h:77
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:264
void inplace(bool square=false, bool SPD=false)
Definition: inplace_decomposition.cpp:18
static int g_repeat
Definition: main.h:191
#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

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, EIGEN_UNUSED, Eigen::g_repeat, i, and inplace().

◆ inplace()

template<typename DecType , typename MatrixType >
void inplace ( bool  square = false,
bool  SPD = false 
)
18  {
19  typedef typename MatrixType::Scalar Scalar;
22 
23  Index rows = MatrixType::RowsAtCompileTime == Dynamic ? internal::random<Index>(2, EIGEN_TEST_MAX_SIZE / 2)
24  : Index(MatrixType::RowsAtCompileTime);
25  Index cols = MatrixType::ColsAtCompileTime == Dynamic ? (square ? rows : internal::random<Index>(2, rows))
26  : Index(MatrixType::ColsAtCompileTime);
27 
28  MatrixType A = MatrixType::Random(rows, cols);
29  RhsType b = RhsType::Random(rows);
30  ResType x(cols);
31 
32  if (SPD) {
33  assert(square);
34  A.topRows(cols) = A.topRows(cols).adjoint() * A.topRows(cols);
35  A.diagonal().array() += 1e-3;
36  }
37 
38  MatrixType A0 = A;
39  MatrixType A1 = A;
40 
41  DecType dec(A);
42 
43  // Check that the content of A has been modified
45 
46  // Check that the decomposition is correct:
47  if (rows == cols) {
48  VERIFY_IS_APPROX(A0 * (x = dec.solve(b)), b);
49  } else {
50  VERIFY_IS_APPROX(A0.transpose() * A0 * (x = dec.solve(b)), A0.transpose() * b);
51  }
52 
53  // Check that modifying A breaks the current dec:
54  A.setRandom();
55  if (rows == cols) {
56  VERIFY_IS_NOT_APPROX(A0 * (x = dec.solve(b)), b);
57  } else {
58  VERIFY_IS_NOT_APPROX(A0.transpose() * A0 * (x = dec.solve(b)), A0.transpose() * b);
59  }
60 
61  // Check that calling compute(A1) does not modify A1:
62  A = A0;
63  dec.compute(A1);
64  VERIFY_IS_EQUAL(A0, A1);
66  if (rows == cols) {
67  VERIFY_IS_APPROX(A0 * (x = dec.solve(b)), b);
68  } else {
69  VERIFY_IS_APPROX(A0.transpose() * A0 * (x = dec.solve(b)), A0.transpose() * b);
70  }
71 }
Array< double, 1, 3 > e(1./3., 0.5, 2.)
#define assert(e,...)
Definition: Logger.h:744
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
Scalar * b
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
#define EIGEN_TEST_MAX_SIZE
Definition: boostmultiprec.cpp:16
Derived & setRandom(Index size)
Definition: Random.h:147
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
#define VERIFY_IS_NOT_APPROX(a, b)
Definition: integer_types.cpp:15
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
@ SPD
Definition: MatrixMarketIterator.h:19
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
squared absolute sa ArrayBase::abs2 DOXCOMMA MatrixBase::cwiseAbs2 square(power 2)
const int Dynamic
Definition: Constants.h:25
list x
Definition: plotDoE.py:28

References assert, b, cols, Eigen::Dynamic, e(), EIGEN_TEST_MAX_SIZE, rows, Eigen::PlainObjectBase< Derived >::setRandom(), Eigen::SPD, Eigen::square(), VERIFY_IS_APPROX, VERIFY_IS_EQUAL, VERIFY_IS_NOT_APPROX, and plotDoE::x.

Referenced by EIGEN_DECLARE_TEST(), Eigen::internal::fftw_impl< Scalar_ >::get_plan(), and Eigen::internal::imklfft::imklfft_impl< Scalar_ >::get_plan().