product_selfadjoint.cpp File Reference
#include "main.h"

Functions

template<typename MatrixType >
void product_selfadjoint (const MatrixType &m)
 
 EIGEN_DECLARE_TEST (product_selfadjoint)
 

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( product_selfadjoint  )
62  {
63  int s = 0;
64  for (int i = 0; i < g_repeat; i++) {
68 
69  s = internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 2);
70  CALL_SUBTEST_4(product_selfadjoint(MatrixXcf(s, s)));
72 
73  s = internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 2);
74  CALL_SUBTEST_5(product_selfadjoint(MatrixXcd(s, s)));
76 
77  s = internal::random<int>(1, EIGEN_TEST_MAX_SIZE);
80 
81  s = internal::random<int>(1, EIGEN_TEST_MAX_SIZE);
84  }
85 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_TEST_MAX_SIZE
Definition: boostmultiprec.cpp:16
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
RealScalar s
Definition: level1_cplx_impl.h:130
#define TEST_SET_BUT_UNUSED_VARIABLE(X)
Definition: main.h:139
static int g_repeat
Definition: main.h:191
void product_selfadjoint(const MatrixType &m)
Definition: product_selfadjoint.cpp:13
#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_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, EIGEN_TEST_MAX_SIZE, Eigen::g_repeat, i, product_selfadjoint(), s, and TEST_SET_BUT_UNUSED_VARIABLE.

◆ product_selfadjoint()

template<typename MatrixType >
void product_selfadjoint ( const MatrixType m)
13  {
14  typedef typename MatrixType::Scalar Scalar;
17 
19 
20  Index rows = m.rows();
21  Index cols = m.cols();
22 
23  MatrixType m1 = MatrixType::Random(rows, cols), m2 = MatrixType::Random(rows, cols), m3;
24  VectorType v1 = VectorType::Random(rows), v2 = VectorType::Random(rows), v3(rows);
25  RowVectorType r1 = RowVectorType::Random(rows), r2 = RowVectorType::Random(rows);
26  RhsMatrixType m4 = RhsMatrixType::Random(rows, 10);
27 
28  Scalar s1 = internal::random<Scalar>(), s2 = internal::random<Scalar>(), s3 = internal::random<Scalar>();
29 
30  m1 = (m1.adjoint() + m1).eval();
31 
32  // rank2 update
33  m2 = m1.template triangularView<Lower>();
34  m2.template selfadjointView<Lower>().rankUpdate(v1, v2);
35  VERIFY_IS_APPROX(m2, (m1 + v1 * v2.adjoint() + v2 * v1.adjoint()).template triangularView<Lower>().toDenseMatrix());
36 
37  m2 = m1.template triangularView<Upper>();
38  m2.template selfadjointView<Upper>().rankUpdate(-v1, s2 * v2, s3);
39  VERIFY_IS_APPROX(m2, (m1 + (s3 * (-v1) * (s2 * v2).adjoint() + numext::conj(s3) * (s2 * v2) * (-v1).adjoint()))
40  .template triangularView<Upper>()
41  .toDenseMatrix());
42 
43  m2 = m1.template triangularView<Upper>();
44  m2.template selfadjointView<Upper>().rankUpdate(-s2 * r1.adjoint(), r2.adjoint() * s3, s1);
45  VERIFY_IS_APPROX(m2, (m1 + s1 * (-s2 * r1.adjoint()) * (r2.adjoint() * s3).adjoint() +
46  numext::conj(s1) * (r2.adjoint() * s3) * (-s2 * r1.adjoint()).adjoint())
47  .template triangularView<Upper>()
48  .toDenseMatrix());
49 
50  if (rows > 1) {
51  m2 = m1.template triangularView<Lower>();
52  m2.block(1, 1, rows - 1, cols - 1)
53  .template selfadjointView<Lower>()
54  .rankUpdate(v1.tail(rows - 1), v2.head(cols - 1));
55  m3 = m1;
56  m3.block(1, 1, rows - 1, cols - 1) +=
57  v1.tail(rows - 1) * v2.head(cols - 1).adjoint() + v2.head(cols - 1) * v1.tail(rows - 1).adjoint();
58  VERIFY_IS_APPROX(m2, m3.template triangularView<Lower>().toDenseMatrix());
59  }
60 }
AnnoyingScalar conj(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:133
Matrix3d m1
Definition: IOFormat.cpp:2
MatrixType m2(n_dims)
Map< RowVectorXf > v2(M2.data(), M2.size())
M1<< 1, 2, 3, 4, 5, 6, 7, 8, 9;Map< RowVectorXf > v1(M1.data(), M1.size())
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
void adjoint(const MatrixType &m)
Definition: adjoint.cpp:85
SCALAR Scalar
Definition: bench_gemm.cpp:45
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
int * m
Definition: level2_cplx_impl.h:294
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
internal::nested_eval< T, 1 >::type eval(const T &xpr)
Definition: sparse_permutations.cpp:47
Definition: fft_test_shared.h:66

References adjoint(), cols, conj(), eval(), m, m1, m2(), rows, v1(), v2(), and VERIFY_IS_APPROX.

Referenced by EIGEN_DECLARE_TEST().