12 #ifndef EIGEN_RANDOM_MATRIX_HELPER
13 #define EIGEN_RANDOM_MATRIX_HELPER
23 template <
typename MatrixType>
26 template <
typename PermutationVectorType>
29 template <
typename MatrixType>
32 template <
typename MatrixType,
typename RealScalarVectorType>
35 template <
typename VectorType,
typename RealScalar>
38 template <
typename VectorType,
typename RealScalar>
59 template <
typename MatrixType>
62 enum { Rows = MatrixType::RowsAtCompileTime, Cols = MatrixType::ColsAtCompileTime };
68 if (desired_rank == 0) {
73 if (desired_rank == 1) {
75 m = VectorType::Random(
rows).normalized() * VectorType::Random(
cols).normalized().transpose();
79 MatrixAType
a = MatrixAType::Random(
rows,
rows);
81 MatrixBType
b = MatrixBType::Random(
cols,
cols);
85 if (diag_size != desired_rank)
86 d.diagonal().segment(desired_rank, diag_size - desired_rank) =
VectorType::Zero(diag_size - desired_rank);
100 template <
typename PermutationVectorType>
105 if (
size == 1)
return;
107 Index i = internal::random<Index>(0,
size - 1);
109 do j = internal::random<Index>(0,
size - 1);
125 template <
typename MatrixType>
133 v.col(
i).tail(dim -
i - 1) = VectorType::Random(dim -
i - 1);
134 h(
i) = 2 /
v.col(
i).tail(dim -
i).squaredNorm();
168 template <
typename MatrixType,
typename RealScalarVectorType>
170 enum { Rows = MatrixType::RowsAtCompileTime, Cols = MatrixType::ColsAtCompileTime };
177 const MatrixAType
U = generateRandomUnitaryMatrix<MatrixAType>(
rows);
178 const MatrixBType
V = generateRandomUnitaryMatrix<MatrixBType>(
cols);
180 M =
U.block(0, 0,
rows, min_dim) * svs.asDiagonal() *
V.block(0, 0,
cols, min_dim).transpose();
199 template <
typename VectorType,
typename RealScalar>
202 std::sort(svs.begin(), svs.end(), std::greater<RealScalar>());
224 template <
typename VectorType,
typename RealScalar>
227 if (dim == 0)
return svs;
232 std::sort(svs.begin(), svs.end(), std::greater<RealScalar>());
235 const RealScalar c_min = svs(dim - 1), c_max = svs(0);
236 svs = (svs - VectorType::Constant(dim, c_min)) / (c_max - c_min);
237 return min * (VectorType::Ones(dim) - svs) +
max * svs;
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
int i
Definition: BiCGSTAB_step_by_step.cpp:9
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
MatrixXcd V
Definition: EigenSolver_EigenSolver_MatrixType.cpp:15
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
Scalar * b
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Householder QR decomposition of a matrix.
Definition: HouseholderQR.h:59
HouseholderSequenceType householderQ() const
Definition: HouseholderQR.h:160
Sequence of Householder reflections acting on subspaces with decreasing size.
Definition: HouseholderSequence.h:117
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
#define min(a, b)
Definition: datatypes.h:22
EIGEN_BLAS_FUNC() swap(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:117
const Scalar * a
Definition: level2_cplx_impl.h:32
int * m
Definition: level2_cplx_impl.h:294
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
void createRandomPIMatrixOfRank(Index desired_rank, Index rows, Index cols, MatrixType &m)
Definition: random_matrix_helper.h:60
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
CleanedUpDerType< DerType >::type() min(const AutoDiffScalar< DerType > &x, const T &y)
Definition: AutoDiffScalar.h:494
CleanedUpDerType< DerType >::type() max(const AutoDiffScalar< DerType > &x, const T &y)
Definition: AutoDiffScalar.h:499
void randomPermutationVector(PermutationVectorType &v, Index size)
Definition: random_matrix_helper.h:101
VectorType setupRandomSvs(const Index dim, const RealScalar max)
Definition: random_matrix_helper.h:200
MatrixType generateRandomUnitaryMatrix(const Index dim)
Definition: random_matrix_helper.h:126
VectorType setupRangeSvs(const Index dim, const RealScalar min, const RealScalar max)
Definition: random_matrix_helper.h:225
void generateRandomMatrixSvs(const RealScalarVectorType &svs, const Index rows, const Index cols, MatrixType &M)
Definition: random_matrix_helper.h:169
double U
Swimming speed.
Definition: two_d_variable_diff_adapt.cc:53
double Zero
Definition: pseudosolid_node_update_elements.cc:35
Definition: ForwardDeclarations.h:21
Definition: fft_test_shared.h:66
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2