monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
random_stracture.cpp
Go to the documentation of this file.
1 
2 #include "../../../include/monolish_blas.hpp"
3 #include "../../internal/monolish_internal.hpp"
4 
5 namespace monolish {
6 
7 template <typename T>
9  const int nnzrow, const T val) {
10  Logger &logger = Logger::get_instance();
11  logger.util_in(monolish_func);
12 
13  if (N <= nnzrow) {
14  throw std::runtime_error("error nnzrow <= matrix size");
15  }
16 
17  matrix::COO<T> mat(M, N);
18 
19  std::random_device seed;
20  std::default_random_engine rng(seed());
21 
22  for (int i = 0; i < M; i++) {
23  std::uniform_int_distribution<> dist_pos(0, N - 1);
24  for (int j = 0; j < nnzrow; j++) {
25  int c = dist_pos(rng);
26  if (mat.at(i, c) != 0)
27  j--;
28  mat.insert(i, c, val);
29  }
30  }
31 
32  mat.sort(true);
33 
34  logger.util_out();
35 
36  return mat;
37 }
39  const int N,
40  const int nnzrow,
41  const double val);
43  const int N,
44  const int nnzrow,
45  const float val);
46 } // namespace monolish
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
monolish::util::random_structure_matrix
matrix::COO< T > random_structure_matrix(const int M, const int N, const int nnzrow, const T val)
create random structure matrix (column number is decided by random)
Definition: random_stracture.cpp:8
monolish::Logger
logger class (singleton, for developper class)
Definition: monolish_logger.hpp:19
monolish::matrix::COO::insert
void insert(const size_t m, const size_t n, const Float val)
insert element to (m, n)
Definition: at_insert_sort_coo.cpp:30
monolish::Logger::util_out
void util_out()
Definition: logger_utils.cpp:123
monolish::matrix::COO::sort
void sort(bool merge)
sort COO matrix elements (and merge elements)
Definition: at_insert_sort_coo.cpp:108
monolish::Logger::util_in
void util_in(const std::string func_name)
Definition: logger_utils.cpp:113
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::matrix::COO::at
Float at(const size_t i, const size_t j) const
Get matrix element (A(i,j))
Definition: at_insert_sort_coo.cpp:9
monolish::matrix::COO
Coodinate (COO) format Matrix (need to sort)
Definition: monolish_coo.hpp:38
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42