monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
convert_coo.cpp
Go to the documentation of this file.
1 #include "../../../include/common/monolish_dense.hpp"
2 #include "../../../include/common/monolish_logger.hpp"
3 #include "../../../include/common/monolish_matrix.hpp"
4 #include "../../internal/monolish_internal.hpp"
5 
6 namespace monolish {
7 namespace matrix {
8 
9 template <typename T> void COO<T>::convert(const CRS<T> &crs) {
10  Logger &logger = Logger::get_instance();
11  logger.util_in(monolish_func);
12 
13  set_row(crs.get_row());
14  set_col(crs.get_col());
15  set_nnz(crs.get_nnz());
16 
17  row_index.resize(nnz);
18  col_index.resize(nnz);
19  val.resize(nnz);
20 
21  for (size_t i = 0; i < get_row(); i++) {
22  for (size_t j = (size_t)crs.row_ptr[i]; j < (size_t)crs.row_ptr[i + 1];
23  j++) {
24  row_index[j] = i;
25  col_index[j] = crs.col_ind[j];
26  val[j] = crs.val[j];
27  }
28  }
29 
30  logger.util_out();
31 }
32 template void COO<double>::convert(const CRS<double> &crs);
33 template void COO<float>::convert(const CRS<float> &crs);
34 
35 template <typename T> void COO<T>::convert(const Dense<T> &dense) {
36  Logger &logger = Logger::get_instance();
37  logger.util_in(monolish_func);
38 
39  set_row(dense.get_row());
40  set_col(dense.get_col());
41  row_index.resize(0);
42  col_index.resize(0);
43  val.resize(0);
44  size_t nz = 0;
45 
46  for (size_t i = 0; i < dense.get_row(); i++) {
47  for (size_t j = 0; j < dense.get_col(); j++) {
48  if (dense.at(i, j) != 0) {
49  row_index.push_back(i);
50  col_index.push_back(j);
51  val.push_back(dense.at(i, j));
52  nz++;
53  }
54  }
55  }
56  set_nnz(nz);
57 
58  logger.util_out();
59 }
60 template void COO<double>::convert(const Dense<double> &dense);
61 template void COO<float>::convert(const Dense<float> &dense);
62 
63 template <typename T>
64 void COO<T>::convert(const LinearOperator<T> &linearoperator) {
65  Logger &logger = Logger::get_instance();
66  logger.util_in(monolish_func);
67 
68  Dense<T> dense(linearoperator.get_row(), linearoperator.get_col());
69  linearoperator.convert_to_Dense(dense);
70  convert(dense);
71 
72  logger.util_out();
73 }
74 
75 template void
76 COO<double>::convert(const LinearOperator<double> &linearoperator);
77 template void COO<float>::convert(const LinearOperator<float> &linearoperator);
78 
79 } // namespace matrix
80 } // namespace monolish
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::matrix::COO::convert
void convert(const matrix::CRS< Float > &crs)
Create COO matrix from CRS matrix.
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42