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

Functions

template<typename MatrixType >
void check_generateRandomUnitaryMatrix (const Index dim)
 
template<typename VectorType , typename RealScalarType >
void check_setupRandomSvs (const Index dim, const RealScalarType max)
 
template<typename VectorType , typename RealScalarType >
void check_setupRangeSvs (const Index dim, const RealScalarType min, const RealScalarType max)
 
template<typename MatrixType , typename RealScalar , typename RealVectorType >
void check_generateRandomMatrixSvs (const Index rows, const Index cols, const Index diag_size, const RealScalar min_svs, const RealScalar max_svs)
 
template<typename MatrixType >
void check_random_matrix (const MatrixType &m)
 
 EIGEN_DECLARE_TEST (random_matrix)
 

Function Documentation

◆ check_generateRandomMatrixSvs()

template<typename MatrixType , typename RealScalar , typename RealVectorType >
void check_generateRandomMatrixSvs ( const Index  rows,
const Index  cols,
const Index  diag_size,
const RealScalar  min_svs,
const RealScalar  max_svs 
)
55  {
56  RealVectorType svs = setupRangeSvs<RealVectorType, RealScalar>(diag_size, min_svs, max_svs);
57 
60 
61  // validate dimensions
64  VERIFY_IS_EQUAL(svs.size(), diag_size);
65 
66  // validate singular values
68  VERIFY_IS_APPROX(svs, SVD.singularValues());
69 }
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Two-sided Jacobi SVD decomposition of a rectangular matrix.
Definition: JacobiSVD.h:500
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:192
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:191
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
void generateRandomMatrixSvs(const RealScalarVectorType &svs, const Index rows, const Index cols, MatrixType &M)
Definition: random_matrix_helper.h:169
double Zero
Definition: pseudosolid_node_update_elements.cc:35

References cols, Eigen::PlainObjectBase< Derived >::cols(), Eigen::generateRandomMatrixSvs(), rows, Eigen::PlainObjectBase< Derived >::rows(), Eigen::SVDBase< Derived >::singularValues(), VERIFY_IS_APPROX, VERIFY_IS_EQUAL, and oomph::PseudoSolidHelper::Zero.

◆ check_generateRandomUnitaryMatrix()

template<typename MatrixType >
void check_generateRandomUnitaryMatrix ( const Index  dim)
14  {
15  const MatrixType Q = generateRandomUnitaryMatrix<MatrixType>(dim);
16 
17  // validate dimensions
18  VERIFY_IS_EQUAL(Q.rows(), dim);
19  VERIFY_IS_EQUAL(Q.cols(), dim);
20 
22 }
MatrixXf Q
Definition: HouseholderQR_householderQ.cpp:1
#define VERIFY_IS_UNITARY(a)
Definition: main.h:378

References Q, VERIFY_IS_EQUAL, and VERIFY_IS_UNITARY.

◆ check_random_matrix()

template<typename MatrixType >
void check_random_matrix ( const MatrixType m)
72  {
73  enum {
74  Rows = MatrixType::RowsAtCompileTime,
75  Cols = MatrixType::ColsAtCompileTime,
76  DiagSize = internal::min_size_prefer_dynamic(Rows, Cols)
77  };
78  typedef typename MatrixType::Scalar Scalar;
79  typedef typename NumTraits<Scalar>::Real RealScalar;
80  typedef Matrix<RealScalar, DiagSize, 1> RealVectorType;
81 
82  const Index rows = m.rows(), cols = m.cols();
83  const Index diag_size = (std::min)(rows, cols);
84  const RealScalar min_svs = 1.0, max_svs = 1000.0;
85 
86  // check generation of unitary random matrices
87  typedef Matrix<Scalar, Rows, Rows> MatrixAType;
88  typedef Matrix<Scalar, Cols, Cols> MatrixBType;
89  check_generateRandomUnitaryMatrix<MatrixAType>(rows);
90  check_generateRandomUnitaryMatrix<MatrixBType>(cols);
91 
92  // test generators for singular values
93  check_setupRandomSvs<RealVectorType, RealScalar>(diag_size, max_svs);
94  check_setupRangeSvs<RealVectorType, RealScalar>(diag_size, min_svs, max_svs);
95 
96  // check generation of random matrices
97  check_generateRandomMatrixSvs<MatrixType, RealScalar, RealVectorType>(rows, cols, diag_size, min_svs, max_svs);
98 }
SCALAR Scalar
Definition: bench_gemm.cpp:45
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
#define min(a, b)
Definition: datatypes.h:22
int * m
Definition: level2_cplx_impl.h:294
constexpr int min_size_prefer_dynamic(A a, B b)
Definition: Meta.h:668
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217

References cols, m, min, Eigen::internal::min_size_prefer_dynamic(), and rows.

Referenced by EIGEN_DECLARE_TEST().

◆ check_setupRandomSvs()

template<typename VectorType , typename RealScalarType >
void check_setupRandomSvs ( const Index  dim,
const RealScalarType  max 
)
25  {
26  const VectorType v = setupRandomSvs<VectorType, RealScalarType>(dim, max);
27 
28  // validate dimensions
29  VERIFY_IS_EQUAL(v.size(), dim);
30 
31  // check entries
32  for (Index i = 0; i < v.size(); ++i) VERIFY_GE(v(i), 0);
33  for (Index i = 0; i < v.size() - 1; ++i) VERIFY_GE(v(i), v(i + 1));
34 }
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define max(a, b)
Definition: datatypes.h:23
#define VERIFY_GE(a, b)
Definition: main.h:364
Definition: fft_test_shared.h:66

References i, max, v, VERIFY_GE, and VERIFY_IS_EQUAL.

◆ check_setupRangeSvs()

template<typename VectorType , typename RealScalarType >
void check_setupRangeSvs ( const Index  dim,
const RealScalarType  min,
const RealScalarType  max 
)
37  {
38  const VectorType v = setupRangeSvs<VectorType, RealScalarType>(dim, min, max);
39 
40  // validate dimensions
41  VERIFY_IS_EQUAL(v.size(), dim);
42 
43  // check entries
44  if (dim == 1) {
45  VERIFY_IS_APPROX(v(0), min);
46  } else {
47  VERIFY_IS_APPROX(v(0), max);
48  VERIFY_IS_APPROX(v(dim - 1), min);
49  }
50  for (Index i = 0; i < v.size() - 1; ++i) VERIFY_GE(v(i), v(i + 1));
51 }

References i, max, min, v, VERIFY_GE, VERIFY_IS_APPROX, and VERIFY_IS_EQUAL.

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( random_matrix  )
100  {
101  for (int i = 0; i < g_repeat; i++) {
106 
111 
112  CALL_SUBTEST_9(check_random_matrix(Matrix<std::complex<float>, 12, 12>()));
113  CALL_SUBTEST_10(check_random_matrix(Matrix<std::complex<float>, 7, 14>()));
114  CALL_SUBTEST_11(check_random_matrix(Matrix<std::complex<double>, 15, 11>()));
115  CALL_SUBTEST_12(check_random_matrix(Matrix<std::complex<double>, 6, 9>()));
116 
118  MatrixXf(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
120  MatrixXd(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
122  MatrixXcf(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
124  MatrixXcd(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
125  }
126 }
#define EIGEN_TEST_MAX_SIZE
Definition: boostmultiprec.cpp:16
static int g_repeat
Definition: main.h:191
void check_random_matrix(const MatrixType &m)
Definition: random_matrix.cpp:72
#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_16(FUNC)
Definition: split_test_helper.h:94
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
#define CALL_SUBTEST_13(FUNC)
Definition: split_test_helper.h:76
#define CALL_SUBTEST_14(FUNC)
Definition: split_test_helper.h:82
#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_11(FUNC)
Definition: split_test_helper.h:64
#define CALL_SUBTEST_12(FUNC)
Definition: split_test_helper.h:70
#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_15(FUNC)
Definition: split_test_helper.h:88
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22
#define CALL_SUBTEST_9(FUNC)
Definition: split_test_helper.h:52
#define CALL_SUBTEST_10(FUNC)
Definition: split_test_helper.h:58

References CALL_SUBTEST_1, CALL_SUBTEST_10, CALL_SUBTEST_11, CALL_SUBTEST_12, CALL_SUBTEST_13, CALL_SUBTEST_14, CALL_SUBTEST_15, CALL_SUBTEST_16, CALL_SUBTEST_2, CALL_SUBTEST_3, CALL_SUBTEST_4, CALL_SUBTEST_5, CALL_SUBTEST_6, CALL_SUBTEST_7, CALL_SUBTEST_8, CALL_SUBTEST_9, check_random_matrix(), EIGEN_TEST_MAX_SIZE, Eigen::g_repeat, and i.