12#ifndef TLAPACK_MATRIXMARKET_HH
13#define TLAPACK_MATRIXMARKET_HH
36 const uint64_t a = 6364136223846793005;
37 const uint64_t c = 1442695040888963407;
41 static constexpr uint32_t min()
noexcept {
return 0; }
43 constexpr void seed(
uint64_t s)
noexcept { state =
s; }
48 state = state * a + c;
57template <
typename T, enable_if_t<is_real<T>,
bool> = true>
60 return T(
static_cast<float>(gen()) /
static_cast<float>(gen.max()));
66template <
typename T, enable_if_t<is_complex<T>,
bool> = true>
67T rand_helper(rand_generator& gen)
69 using real_t = real_type<T>;
70 real_t r1(
static_cast<float>(gen()) /
static_cast<float>(gen.max()));
71 real_t r2(
static_cast<float>(gen()) /
static_cast<float>(gen.max()));
72 return complex_type<real_t>(r1, r2);
78template <
typename T, enable_if_t<is_real<T>,
bool> = true>
81 return T(
static_cast<float>(
rand()) /
static_cast<float>(
RAND_MAX));
87template <
typename T, enable_if_t<is_complex<T>,
bool> = true>
90 using real_t = real_type<T>;
91 real_t r1(
static_cast<float>(rand()) /
static_cast<float>(RAND_MAX));
92 real_t r2(
static_cast<float>(rand()) /
static_cast<float>(RAND_MAX));
93 return complex_type<real_t>(r1, r2);
111 template <TLAPACK_MATRIX matrix_t>
116 const idx_t m = nrows(
A);
117 const idx_t n = ncols(
A);
119 for (idx_t j = 0; j < n; ++j)
120 for (idx_t i = 0; i < m; ++i)
129 template <TLAPACK_MATRIX matrix_t>
135 const idx_t m = nrows(
A);
136 const idx_t n = ncols(
A);
138 for (idx_t j = 0; j < n; ++j)
139 for (idx_t i = 0; i < m; ++i)
151 template <TLAPACK_UPLO uplo_t, TLAPACK_MATRIX matrix_t>
157 const idx_t m = nrows(
A);
158 const idx_t n = ncols(
A);
160 if (
uplo == Uplo::Upper) {
161 for (idx_t j = 0; j < n; ++j)
162 for (idx_t i = 0; i < m; ++i)
166 A(i, j) = T(
float(0xCAFEBABE));
169 for (idx_t j = 0; j < n; ++j)
170 for (idx_t i = 0; i < m; ++i)
174 A(i, j) = T(
float(0xCAFEBABE));
185 template <TLAPACK_MATRIX matrix_t>
191 const idx_t m = nrows(
A);
192 const idx_t n = ncols(
A);
194 for (idx_t j = 0; j < n; ++j)
195 for (idx_t i = 0; i < m; ++i)
199 A(i, j) = T(
float(0xFA57C0DE));
213 template <TLAPACK_MATRIX matrix_t>
219 const idx_t m = nrows(
A);
220 const idx_t n = ncols(
A);
222 for (idx_t j = 0; j < n; ++j)
223 for (idx_t i = 0; i < m; ++i)
224 A(i, j) = T(1) / T(i + j + 1);
233 template <TLAPACK_MATRIX matrix_t>
238 const idx_t m = nrows(
A);
239 const idx_t n = ncols(
A);
241 for (idx_t j = 0; j < n; ++j)
242 for (idx_t i = 0; i < m; ++i)
256 template <TLAPACK_UPLO uplo_t, TLAPACK_MATRIX matrix_t>
264 const idx_t m = nrows(
A);
265 const idx_t n = ncols(
A);
267 if (
uplo == Uplo::Upper) {
268 for (idx_t j = 0; j < n; ++j)
269 for (idx_t i = 0; i < m; ++i)
273 A(i, j) = T(
float(0xCAFEBABE));
276 for (idx_t j = 0; j < n; ++j)
277 for (idx_t i = 0; i < m; ++i)
281 A(i, j) = T(
float(0xCAFEBABE));
T rand_helper(rand_generator &gen)
Helper function to generate random numbers.
Definition MatrixMarket.hpp:58
Random number generator.
Definition MatrixMarket.hpp:34
constexpr uint32_t operator()()
Generates a pseudo-random number.
Definition MatrixMarket.hpp:46
typename traits::real_type_traits< Types..., int >::type real_type
The common real type of the list of types.
Definition scalar_type_traits.hpp:113
MatrixMarket class.
Definition MatrixMarket.hpp:102
void single_value(matrix_t &A, const type_t< matrix_t > &val) const
Generate a matrix with a single value in all entries.
Definition MatrixMarket.hpp:234
void colmajor_read(matrix_t &A, std::istream &is) const
Read a dense matrix from an input stream (file, stdin, etc).
Definition MatrixMarket.hpp:112
void random(uplo_t uplo, matrix_t &A)
Generate an upper- or lower-triangular random matrix.
Definition MatrixMarket.hpp:152
void random(matrix_t &A)
Generate a random dense matrix.
Definition MatrixMarket.hpp:130
void hessenberg(matrix_t &A)
Generate a random upper Hessenberg matrix.
Definition MatrixMarket.hpp:186
void hilbert(matrix_t &A) const
Generate a Hilbert matrix.
Definition MatrixMarket.hpp:214
void single_value(uplo_t uplo, matrix_t &A, const type_t< matrix_t > &val) const
Generate an upper- or lower-triangular matrix with a single value in all entries.
Definition MatrixMarket.hpp:257