csr_generators.hh
Go to the documentation of this file.
1#pragma once
2
3#include <batchlas/export.hh>
5
6#include <complex>
7#include <stdexcept>
8
9/// @file
10/// @brief Random CSR test-matrix generators (`batchlas::csr_generators`).
11
12namespace batchlas {
13/// @brief Random sparse test-matrix generators.
14namespace csr_generators {
15
16/// @brief Generates a batch of random sparse symmetric (real) or Hermitian (complex) n x n CSR matrices.
17///
18/// Every row holds its diagonal entry. Off-diagonal entries come in (i, j) / (j, i)
19/// pairs with conjugate values, drawn uniformly from [-1, 1] (real and imaginary
20/// parts independently). Each diagonal is real and set to the row's off-diagonal
21/// absolute sum (|re| + |im| for complex) plus @p diagonal_boost, so the matrix is
22/// strictly diagonally dominant with a positive diagonal. Column indices are sorted
23/// within each row. Storage is allocated and
24/// filled on the device; the call waits before returning. Equivalent to
25/// Matrix::RandomSparseHermitian().
26/// @tparam T `float`, `double`, `std::complex<float>` or `std::complex<double>`
27/// @param n matrix order
28/// @param density target fraction of stored entries over the full n x n
29/// matrix, diagonal included; clamped to [0, 1]. The count is
30/// rounded to nearest, raised to at least n, its off-diagonal part
31/// rounded up to even, and capped at n * n.
32/// @param batch_size number of matrices
33/// @param seed RNG seed; equal seeds give identical matrices
34/// @param diagonal_boost margin added to each diagonal above its off-diagonal row sum
35/// @param shared_pattern true: every batch item has the same sparsity pattern
36/// (values still differ); false: one pattern per item
37/// @return an owning CSR Matrix; `nnz()` is the same for every item
38/// @throws batchlas::invalid_argument if n <= 0 or batch_size <= 0
39/// @ingroup api_sparse_lowlevel
40template <typename T>
42 float density,
43 int batch_size = 1,
44 unsigned seed = 42,
45 typename base_type<T>::type diagonal_boost = typename base_type<T>::type(1),
46 bool shared_pattern = true);
47
48} // namespace csr_generators
49} // namespace batchlas
Owning batch of batch_size() matrices of equal (capacity) shape.
Definition matrix.hh:1399
Matrix< T, MatrixFormat::CSR > random_sparse_hermitian_csr(int n, float density, int batch_size=1, unsigned seed=42, typename base_type< T >::type diagonal_boost=typename base_type< T >::type(1), bool shared_pattern=true)
Generates a batch of random sparse symmetric (real) or Hermitian (complex) n x n CSR matrices.
The batched containers: Matrix (owning), MatrixView (non-owning), KernelMatrixView (device-side),...
Random sparse test-matrix generators.
T type
The real type.
Definition enums.hh:30