jacobi.cpp File Reference
#include "main.h"
#include <Eigen/SVD>

Functions

template<typename MatrixType , typename JacobiScalar >
void jacobi (const MatrixType &m=MatrixType())
 
 EIGEN_DECLARE_TEST (jacobi)
 

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( jacobi  )
56  {
57  for (int i = 0; i < g_repeat; i++) {
58  CALL_SUBTEST_1((jacobi<Matrix3f, float>()));
59  CALL_SUBTEST_2((jacobi<Matrix4d, double>()));
60  CALL_SUBTEST_3((jacobi<Matrix4cf, float>()));
61  CALL_SUBTEST_3((jacobi<Matrix4cf, std::complex<float> >()));
62 
65  CALL_SUBTEST_3((jacobi<Matrix<std::complex<float>, 4, 4, RowMajor>, float>()));
66  CALL_SUBTEST_3((jacobi<Matrix<std::complex<float>, 4, 4, RowMajor>, std::complex<float> >()));
67 
68  int r = internal::random<int>(2, internal::random<int>(1, EIGEN_TEST_MAX_SIZE) / 2),
69  c = internal::random<int>(2, internal::random<int>(1, EIGEN_TEST_MAX_SIZE) / 2);
70  CALL_SUBTEST_4((jacobi<MatrixXf, float>(MatrixXf(r, c))));
71  CALL_SUBTEST_5((jacobi<MatrixXcd, double>(MatrixXcd(r, c))));
72  CALL_SUBTEST_5((jacobi<MatrixXcd, std::complex<double> >(MatrixXcd(r, c))));
73  // complex<float> is really important to test as it is the only way to cover conjugation issues in certain unaligned
74  // paths
75  CALL_SUBTEST_6((jacobi<MatrixXcf, float>(MatrixXcf(r, c))));
76  CALL_SUBTEST_6((jacobi<MatrixXcf, std::complex<float> >(MatrixXcf(r, c))));
77 
80  }
81 }
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
@ RowMajor
Definition: Constants.h:320
void jacobi(const MatrixType &m=MatrixType())
Definition: jacobi.cpp:15
#define TEST_SET_BUT_UNUSED_VARIABLE(X)
Definition: main.h:139
static int g_repeat
Definition: main.h:191
r
Definition: UniformPSDSelfTest.py:20
int c
Definition: calibrate.py:100
#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_4(FUNC)
Definition: split_test_helper.h:22

References calibrate::c, CALL_SUBTEST_1, CALL_SUBTEST_2, CALL_SUBTEST_3, CALL_SUBTEST_4, CALL_SUBTEST_5, CALL_SUBTEST_6, EIGEN_TEST_MAX_SIZE, Eigen::g_repeat, i, jacobi(), UniformPSDSelfTest::r, Eigen::RowMajor, and TEST_SET_BUT_UNUSED_VARIABLE.

◆ jacobi()

template<typename MatrixType , typename JacobiScalar >
void jacobi ( const MatrixType m = MatrixType())
15  {
16  Index rows = m.rows();
17  Index cols = m.cols();
18 
19  enum { RowsAtCompileTime = MatrixType::RowsAtCompileTime, ColsAtCompileTime = MatrixType::ColsAtCompileTime };
20 
21  typedef Matrix<JacobiScalar, 2, 1> JacobiVector;
22 
23  const MatrixType a(MatrixType::Random(rows, cols));
24 
25  JacobiVector v = JacobiVector::Random().normalized();
26  JacobiScalar c = v.x(), s = v.y();
28 
29  {
30  Index p = internal::random<Index>(0, rows - 1);
31  Index q;
32  do {
33  q = internal::random<Index>(0, rows - 1);
34  } while (q == p);
35 
36  MatrixType b = a;
37  b.applyOnTheLeft(p, q, rot);
38  VERIFY_IS_APPROX(b.row(p), c * a.row(p) + numext::conj(s) * a.row(q));
39  VERIFY_IS_APPROX(b.row(q), -s * a.row(p) + numext::conj(c) * a.row(q));
40  }
41 
42  {
43  Index p = internal::random<Index>(0, cols - 1);
44  Index q;
45  do {
46  q = internal::random<Index>(0, cols - 1);
47  } while (q == p);
48 
49  MatrixType b = a;
50  b.applyOnTheRight(p, q, rot);
51  VERIFY_IS_APPROX(b.col(p), c * a.col(p) - s * a.col(q));
52  VERIFY_IS_APPROX(b.col(q), numext::conj(s) * a.col(p) + numext::conj(c) * a.col(q));
53  }
54 }
AnnoyingScalar conj(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:133
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
float * p
Definition: Tutorial_Map_using.cpp:9
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
Scalar * b
Definition: benchVecAdd.cpp:17
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Rotation given by a cosine-sine pair.
Definition: Jacobi.h:38
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
RealScalar s
Definition: level1_cplx_impl.h:130
EIGEN_BLAS_FUNC() rot(int *n, Scalar *px, int *incx, Scalar *py, int *incy, Scalar *pc, Scalar *ps)
Definition: level1_real_impl.h:88
const Scalar * a
Definition: level2_cplx_impl.h:32
int * m
Definition: level2_cplx_impl.h:294
EIGEN_DEVICE_FUNC const Scalar & q
Definition: SpecialFunctionsImpl.h:2019
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83

References a, b, calibrate::c, cols, conj(), m, p, Eigen::numext::q, rot(), rows, s, v, and VERIFY_IS_APPROX.

Referenced by EIGEN_DECLARE_TEST().