monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
band_matrix.cpp
Go to the documentation of this file.
1 #include "../../../include/monolish_blas.hpp"
2 #include "../../internal/monolish_internal.hpp"
3 
4 namespace monolish {
5 
6 template <typename T>
7 matrix::COO<T> util::band_matrix(const int M, const int N, const int W,
8  const T diag_val, const T val) {
9  Logger &logger = Logger::get_instance();
10  logger.util_in(monolish_func);
11 
12  if (N <= W) {
13  throw std::runtime_error("error band width <= matrix size");
14  }
15 
16  matrix::COO<T> mat(M, N);
17 
18  int ww = W;
19 
20  for (int i = 0; i < M; i++) {
21  int start = (i < ww ? 0 : i - ww);
22  int end = (N <= (i + ww + 1) ? N : i + ww + 1);
23  for (int j = start; j < end; j++) {
24  if (i == j)
25  mat.insert(i, j, diag_val);
26  else
27  mat.insert(i, j, val);
28  }
29  }
30 
31  logger.util_out();
32 
33  return mat;
34 }
35 template matrix::COO<double> util::band_matrix(const int M, const int N,
36  const int W,
37  const double diag_val,
38  const double val);
39 template matrix::COO<float> util::band_matrix(const int M, const int N,
40  const int W, const float diag_val,
41  const float val);
42 
43 } // namespace monolish
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
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::util::band_matrix
matrix::COO< T > band_matrix(const int M, const int N, const int W, const T diag_val, const T val)
create band matrix
Definition: band_matrix.cpp:7
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
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