monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
convert_crs.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 CRS<T>::convert(COO<T> &coo) {
10  Logger &logger = Logger::get_instance();
11  logger.util_in(monolish_func);
12 
13  rowN = coo.get_row();
14  colN = coo.get_col();
15  nnz = coo.get_nnz();
16 
17  val = coo.val;
18  col_ind = coo.col_index;
19 
20  // todo not inplace now
21  row_ptr.resize(get_row() + 1, 0.0);
22 
23  row_ptr[0] = 0;
24  size_t c_row = 0;
25  for (size_t i = 0; i < coo.get_nnz(); i++) {
26 
27  if ((int)c_row == coo.row_index[i]) {
28  row_ptr[c_row + 1] = i + 1;
29  } else {
30  c_row = c_row + 1;
31  row_ptr[c_row + 1] = i + 1;
32  }
33  }
34  compute_hash();
35  logger.util_out();
36 }
37 template void CRS<double>::convert(COO<double> &coo);
38 template void CRS<float>::convert(COO<float> &coo);
39 
40 template <typename T> void CRS<T>::convert(CRS<T> &crs) {
41  Logger &logger = Logger::get_instance();
42  logger.util_in(monolish_func);
43 
44  val.resize(crs.get_nnz());
45  col_ind.resize(crs.get_nnz());
46  row_ptr.resize(crs.get_row() + 1);
47 
48  rowN = crs.get_row();
49  colN = crs.get_col();
50  nnz = crs.get_nnz();
51  structure_hash = crs.get_hash();
52 
53  if (crs.get_device_mem_stat() == true) {
54  throw std::runtime_error(
55  "error can not convert CRS->CRS when gpu_status == true");
56  } else {
57  internal::vcopy(crs.row_ptr.size(), crs.row_ptr.data(), row_ptr.data(),
58  false);
59  internal::vcopy(crs.col_ind.size(), crs.col_ind.data(), col_ind.data(),
60  false);
61  internal::vcopy(crs.val.size(), crs.val.data(), val.data(), false);
62  }
63 
64  logger.util_out();
65 }
66 template void CRS<double>::convert(CRS<double> &coo);
67 template void CRS<float>::convert(CRS<float> &coo);
68 
69 } // namespace matrix
70 } // namespace monolish
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::matrix::CRS::convert
void convert(COO< Float > &coo)
Convert CRS matrix from COO matrix, also compute the hash.
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42