monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
coo_constructor.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 // todo: kill cerr
7 
8 namespace monolish {
9 namespace matrix {
10 
11 // matrix constructor
12 
13 template <typename T>
14 COO<T>::COO(const size_t M, const size_t N, const size_t NNZ, const int *row,
15  const int *col, const T *value) {
16  Logger &logger = Logger::get_instance();
17  logger.util_in(monolish_func);
18  rowN = M;
19  colN = N;
20  nnz = NNZ;
21  gpu_status = false;
22  row_index.resize(nnz);
23  col_index.resize(nnz);
24  val.resize(nnz);
25 
26  std::copy(row, row + nnz, row_index.begin());
27  std::copy(col, col + nnz, col_index.begin());
28  std::copy(value, value + nnz, val.begin());
29  logger.util_out();
30 }
31 template COO<double>::COO(const size_t M, const size_t N, const size_t NNZ,
32  const int *row, const int *col, const double *value);
33 template COO<float>::COO(const size_t M, const size_t N, const size_t NNZ,
34  const int *row, const int *col, const float *value);
35 
36 template <typename T>
37 COO<T>::COO(const size_t M, const size_t N, const size_t NNZ, const int *row,
38  const int *col, const T *value, const size_t origin) {
39  Logger &logger = Logger::get_instance();
40  logger.util_in(monolish_func);
41  rowN = M;
42  colN = N;
43  nnz = NNZ;
44  gpu_status = false;
45  row_index.resize(nnz);
46  col_index.resize(nnz);
47  val.resize(nnz);
48 
49  std::copy(row, row + nnz, row_index.begin());
50  std::copy(col, col + nnz, col_index.begin());
51  std::copy(value, value + nnz, val.begin());
52 
53 #pragma omp parallel for
54  for (size_t i = 0; i < nnz; i++) {
55  row_index[i] -= origin;
56  col_index[i] -= origin;
57  }
58  logger.util_out();
59 }
60 template COO<double>::COO(const size_t M, const size_t N, const size_t NNZ,
61  const int *row, const int *col, const double *value,
62  const size_t origin);
63 template COO<float>::COO(const size_t M, const size_t N, const size_t NNZ,
64  const int *row, const int *col, const float *value,
65  const size_t origin);
66 
67 template <typename T> COO<T>::COO(const matrix::COO<T> &coo) {
68  Logger &logger = Logger::get_instance();
69  logger.util_in(monolish_func);
70  rowN = coo.get_row();
71  colN = coo.get_col();
72  nnz = coo.get_nnz();
73  gpu_status = false;
74  row_index.resize(nnz);
75  col_index.resize(nnz);
76  val.resize(nnz);
77  std::copy(coo.row_index.data(), coo.row_index.data() + nnz,
78  row_index.begin());
79  std::copy(coo.col_index.data(), coo.col_index.data() + nnz,
80  col_index.begin());
81  std::copy(coo.val.data(), coo.val.data() + nnz, val.begin());
82  logger.util_out();
83 }
84 template COO<double>::COO(const matrix::COO<double> &coo);
85 template COO<float>::COO(const matrix::COO<float> &coo);
86 
87 } // namespace matrix
88 } // namespace monolish
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
monolish::blas::copy
void copy(const matrix::Dense< double > &A, matrix::Dense< double > &C)
Dense matrix copy (C=A)
Definition: dense_copy.cpp:25
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::matrix::COO::COO
COO()
Definition: monolish_coo.hpp:79
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42