10#include <kernel/lafem/dense_matrix.hpp>
11#include <kernel/lafem/sparse_matrix_csr.hpp>
12#include <kernel/lafem/sparse_matrix_bcsr.hpp>
13#include <kernel/adjacency/dynamic_graph.hpp>
14#include <kernel/adjacency/graph.hpp>
15#include <kernel/util/random.hpp>
49 return static_cast<TestMatrixFlags>(
static_cast<int>(a) &
static_cast<int>(b));
55 return static_cast<TestMatrixFlags>(
static_cast<int>(a) |
static_cast<int>(b));
61 return static_cast<int>(a & b) != 0;
94 template<
typename DT_,
typename IT_>
166 template<
typename DT_,
typename IT_,
int BlockHeight_,
int BlockW
idth_>
241 XASSERT(nnze <= nrows * ncols);
247 dygraph.
insert(k / ncols, k % ncols);
253 template<
typename DT_,
typename IT_>
274 template<
typename DT_,
typename IT_,
int BlockHeight_,
int BlockW
idth_>
303 XASSERT(nnze <= nrows * ncols);
309 dygraph.
insert(k / ncols, k % ncols);
310 dygraph.
insert(k % ncols, k / ncols);
316 template<
typename DT_,
typename IT_>
340 template<
typename DT_,
typename IT_,
int BlockHeight_,
int BlockW
idth_>
343 XASSERT(BlockWidth_ == BlockHeight_);
368 XASSERT(nnze <= nrows * ncols);
372 for(
Index i(0); i < ncols; ++i)
380 dygraph.
insert(k / ncols, k % ncols);
386 template<
typename DT_,
typename IT_>
409 template<
typename DT_,
typename IT_,
int BlockHeight_,
int BlockW
idth_>
412 XASSERT(BlockWidth_ == BlockHeight_);
423 template<
typename DT_,
typename IT_>
426 DT_* values = matrix.
val();
428 for(
Index i(0); i < nnze; ++i)
429 values[i] = rng(-DT_(1), DT_(1));
439 template<
typename DT_,
typename IT_,
int BlockHeight_,
int BlockW
idth_>
442 auto * values = matrix.
val();
444 for(
Index i(0); i < nnze; ++i)
445 for(
int j(0); j < BlockHeight_; ++j)
446 for(
int k(0); k< BlockWidth_; ++k)
447 values[i][j][k] = rng(-DT_(1), DT_(1));
457 template<
typename DT_,
typename IT_>
460 DT_* values = matrix.
val();
462 for(
Index i(0); i < nnze; ++i)
463 values[i] = rng(DT_(0), DT_(1));
473 template<
typename DT_,
typename IT_,
int BlockHeight_,
int BlockW
idth_>
476 auto* values = matrix.
val();
478 for(
Index i(0); i < nnze; ++i)
479 for(
int j(0); j < BlockHeight_; ++j)
480 for(
int k(0); k< BlockWidth_; ++k)
481 values[i][j][k] = rng(DT_(0), DT_(1));
494 template<
typename DT_,
typename IT_>
497 DT_* values = matrix.
val();
499 const IT_ * col_idx = matrix.
col_ind();
500 const IT_ * row_ptr = matrix.
row_ptr();
502 for (
Index i = 0; i < nrows; ++i)
504 for (IT_ j = row_ptr[i]; j < row_ptr[i + 1]; ++j)
506 Index col_j = col_idx[j];
511 for (IT_ k = row_ptr[col_j]; k < row_ptr[col_j + 1]; ++k)
515 values[k] = values[j];
534 template<
typename DT_,
typename IT_,
int BlockHeight_,
int BlockW
idth_>
537 auto* values = matrix.
val();
538 const IT_* col_idx = matrix.
col_ind();
539 const IT_* row_ptr = matrix.
row_ptr();
542 for (
Index i = 0; i < nrows; ++i) {
543 for (IT_ j = row_ptr[i]; j < row_ptr[i + 1]; ++j) {
544 Index col_j = col_idx[j];
549 for (IT_ k = row_ptr[col_j]; k < row_ptr[col_j + 1]; ++k)
553 for (
int l = 0; l < BlockHeight_; ++l)
555 for (
int m = 0; m < BlockWidth_; ++m)
557 values[k][m][l] = values[j][l][m];
578 template<
typename DT_,
typename IT_>
581 DT_* values = matrix.
val();
582 const IT_* col_idx = matrix.
col_ind();
583 const IT_* row_ptr = matrix.
row_ptr();
586 for(
Index i = 0; i < nrows; ++i)
588 for(IT_ j = row_ptr[i]; j < row_ptr[i+1]; ++j)
592 values[j] = rng(DT_(0.1), DT_(1));
609 template<
typename DT_,
typename IT_,
int BlockHeight_,
int BlockW
idth_>
612 auto* values = matrix.
val();
613 const IT_* col_idx = matrix.
col_ind();
614 const IT_* row_ptr = matrix.
row_ptr();
617 for(
Index i = 0; i < nrows; ++i)
619 for(IT_ j = row_ptr[i]; j < row_ptr[i+1]; ++j)
623 for(
int l(0); l < BlockHeight_; ++l)
624 values[j][l][l] = rng(DT_(0.1), DT_(1));
641 template<
typename DT_,
typename IT_>
644 DT_* values = matrix.
val();
645 const IT_* col_idx = matrix.
col_ind();
646 const IT_* row_ptr = matrix.
row_ptr();
649 for(
Index i = 0; i < nrows; ++i)
651 DT_ off_diagonal = 0;
652 for(IT_ j = row_ptr[i]; j < row_ptr[i + 1]; ++j)
656 off_diagonal += std::abs(values[j]);
660 for(IT_ j = row_ptr[i]; j < row_ptr[i + 1]; ++j)
664 values[j] = off_diagonal + rng(DT_(0.1), DT_(1));
681 template<
typename DT_,
typename IT_,
int BlockHeight_,
int BlockW
idth_>
684 auto* values = matrix.
val();
685 const IT_* col_idx = matrix.
col_ind();
686 const IT_* row_ptr = matrix.
row_ptr();
689 for(
Index i = 0; i < nrows; ++i)
691 DT_ off_diagonal = 0;
692 for(IT_ j = row_ptr[i]; j < row_ptr[i + 1]; ++j)
696 for(
int k(0); k < BlockWidth_; ++k)
698 for(
int l(0); l < BlockHeight_; ++l)
700 off_diagonal += std::abs(values[j][k][l]);
706 for(
int k(0); k < BlockWidth_; ++k)
708 for(
int l(0); l < BlockHeight_; ++l)
711 off_diagonal += std::abs(values[j][k][l]);
717 for(IT_ j = row_ptr[i]; j < row_ptr[i + 1]; ++j)
721 for(
int k(0); k < BlockWidth_; ++k)
722 values[j][k][k] = off_diagonal + rng(DT_(0.1), DT_(1));
#define XASSERT(expr)
Assertion macro definition.
Dynamic Adjacency Graph implementation.
bool insert(Index domain_node, Index image_node)
Inserts a new adjacency entry to the graph.
Index get_num_indices() const
Returns the total number of indices.
Adjacency Graph implementation.
CSR based blocked sparse matrix.
Index rows() const
Retrieve matrix row count.
IT_ * col_ind()
Retrieve column indices array.
IT_ * row_ptr()
Retrieve row start index array.
Index used_elements() const
Retrieve non zero element count.
auto val() const -> const typename Intern::BCSRPerspectiveHelper< DT_, BlockHeight_, BlockWidth_, perspective_ >::Type *
Retrieve non zero element array.
IT_ * col_ind()
Retrieve column indices array.
DT_ * val()
Retrieve non zero element array.
Index rows() const
Retrieve matrix row count.
Index used_elements() const
Retrieve non zero element count.
IT_ * row_ptr()
Retrieve row start index array.
Adjacency::Graph _create_non_empty_diag_struct(Index nrows, Index ncols, Index nnze)
Creates a non empty diagonal sparse matrix structure in CSR format based on the specified dimensions ...
void _make_diagonal_dominant(SparseMatrixCSR< DT_, IT_ > &matrix)
Ensures that a sparse matrix in CSR format is diagonal dominant.
void create(SparseMatrixBCSR< DT_, IT_, BlockHeight_, BlockWidth_ > &matrix, Index nrows, Index ncols, Index nnze, TestMatrixFlags flags)
Creates a sparse matrix in BCSR format with various properties based on the specified flags.
void create(SparseMatrixCSR< DT_, IT_ > &matrix, Index nrows, Index ncols, Index nnze, TestMatrixFlags flags)
Creates a sparse matrix in CSR format with various properties based on the specified flags.
void _make_symmetric_values(SparseMatrixBCSR< DT_, IT_, BlockHeight_, BlockWidth_ > &matrix)
Ensures that the values of a sparse matrix in BCSR format are symmetric.
void _fill_generic_values(SparseMatrixCSR< DT_, IT_ > &matrix)
Fills the values of a sparse matrix in CSR format with random values between -1 and 1.
void _create_non_empty_diag_struct(SparseMatrixBCSR< DT_, IT_, BlockHeight_, BlockWidth_ > &matrix, Index nrows, Index ncols, Index nnze)
Creates a non empty diagonal sparse matrix structure in BCSR format based on the specified dimensions...
void _make_diagonal_dominant(SparseMatrixBCSR< DT_, IT_, BlockHeight_, BlockWidth_ > &matrix)
Ensures that a sparse matrix in BCSR format is diagonal dominant.
void _fill_non_negative_values(SparseMatrixCSR< DT_, IT_ > &matrix)
Fills the values of a sparse matrix in CSR format with random non negative values between 0 and 1.
void _fill_non_negative_values(SparseMatrixBCSR< DT_, IT_, BlockHeight_, BlockWidth_ > &matrix)
Fills the values of a sparse matrix in BCSR format with random non negative values between 0 and 1.
Adjacency::Graph _create_generic_struct(Index nrows, Index ncols, Index nnze)
Creates a generic sparse matrix structure in CSR format based on the specified dimensions and non-zer...
void _create_symmetric_struct(SparseMatrixBCSR< DT_, IT_, BlockHeight_, BlockWidth_ > &matrix, Index nrows, Index ncols, Index nnze)
Creates a symmetric sparse matrix structure in BCSR format based on the specified dimensions and non-...
void _make_symmetric_values(SparseMatrixCSR< DT_, IT_ > &matrix)
Ensures that the values of a sparse matrix in CSR format are symmetric.
void _make_non_zero_diag(SparseMatrixCSR< DT_, IT_ > &matrix)
Ensures that the diagonal entries of a sparse matrix in CSR format are non-zero.
void _make_non_zero_diag(SparseMatrixBCSR< DT_, IT_, BlockHeight_, BlockWidth_ > &matrix)
Ensures that the diagonal entries of a sparse matrix in BCSR format are non-zero.
Adjacency::Graph _create_symmetric_struct(Index nrows, Index ncols, Index nnze)
Creates a symmetric sparse matrix structure in CSR format based on the specified dimensions and non-z...
void _fill_generic_values(SparseMatrixBCSR< DT_, IT_, BlockHeight_, BlockWidth_ > &matrix)
Fills the values of a sparse matrix in BCSR format with random values between -1 and 1.
void _create_generic_struct(SparseMatrixBCSR< DT_, IT_, BlockHeight_, BlockWidth_ > &matrix, Index nrows, Index ncols, Index nnze)
Creates a generic sparse matrix structure in BCSR format based on the specified dimensions and non-ze...
Pseudo-Random Number Generator.
std::uint64_t SeedType
seed type
SeedType get_seed() const
@ as_is
Render-As-Is mode.
TestMatrixFlags
Flags for desired test matrix.
@ non_zero_diag
all main diagonal entries non-zero
@ non_empty_diag
all main diagonal entries non-empty
@ diagonal_dominant
diagonal dominant matrix
@ generic
generic matrix without special properties, values in range [-1,+1]
@ non_empty_cols
all columns non-empty
@ non_negative
all values non-negative, i.e. values in range [0,1]
@ symmetric_struct
matrix with symmetric structure
@ non_empty_rows
all rows non-empty
@ symmetric
matrix with symmetric structure and values
bool operator*(TestMatrixFlags a, TestMatrixFlags b)
checks whether a & b != 0
CompressionModes operator&(CompressionModes a, CompressionModes b)
bit-wise AND operator for CompressionModes
CompressionModes operator|(CompressionModes a, CompressionModes b)
bit-wise OR operator for Pack::Type
std::uint64_t Index
Index data type.