monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
compare_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>
10 bool CRS<T>::equal(const CRS<T> &mat, bool compare_cpu_and_device) const {
11  Logger &logger = Logger::get_instance();
12  logger.util_in(monolish_func);
13 
14  if (get_row() != mat.get_row()) {
15  logger.util_out();
16  return false;
17  }
18  if (get_col() != mat.get_col()) {
19  logger.util_out();
20  return false;
21  }
22  if (get_device_mem_stat() != mat.get_device_mem_stat()) {
23  logger.util_out();
24  return false;
25  }
26 
27  if (get_device_mem_stat() == true) {
28  if (!(internal::vequal(get_nnz(), val.data(), mat.val.data(), true))) {
29  logger.util_out();
30  return false;
31  }
32  if (!(internal::vequal(get_nnz(), col_ind.data(), mat.col_ind.data(),
33  true))) {
34  logger.util_out();
35  return false;
36  }
37  if (!(internal::vequal(get_nnz(), row_ptr.data(), mat.row_ptr.data(),
38  true))) {
39  logger.util_out();
40  return false;
41  }
42  } else if (get_device_mem_stat() == false ||
43  compare_cpu_and_device == false) {
44  if (!(internal::vequal(get_nnz(), val.data(), mat.val.data(), false))) {
45  logger.util_out();
46  return false;
47  }
48  if (!(internal::vequal(get_nnz(), col_ind.data(), mat.col_ind.data(),
49  false))) {
50  logger.util_out();
51  return false;
52  }
53  if (!(internal::vequal(get_nnz(), row_ptr.data(), mat.row_ptr.data(),
54  false))) {
55  logger.util_out();
56  return false;
57  }
58  }
59 
60  logger.util_out();
61  return true;
62 }
63 template bool CRS<double>::equal(const CRS<double> &mat,
64  bool compare_cpu_and_device) const;
65 template bool CRS<float>::equal(const CRS<float> &mat,
66  bool compare_cpu_and_device) const;
67 
68 template <typename T> bool CRS<T>::operator==(const CRS<T> &mat) const {
69  Logger &logger = Logger::get_instance();
70  logger.util_in(monolish_func);
71 
72  bool ans = equal(mat, false);
73 
74  logger.util_out();
75  return ans;
76 }
77 template bool CRS<double>::operator==(const CRS<double> &mat) const;
78 template bool CRS<float>::operator==(const CRS<float> &mat) const;
79 
80 template <typename T> bool CRS<T>::operator!=(const CRS<T> &mat) const {
81  Logger &logger = Logger::get_instance();
82  logger.util_in(monolish_func);
83 
84  bool ans = equal(mat, false);
85 
86  logger.util_out();
87  return !(ans);
88 }
89 template bool CRS<double>::operator!=(const CRS<double> &mat) const;
90 template bool CRS<float>::operator!=(const CRS<float> &mat) const;
91 
92 } // namespace matrix
93 } // namespace monolish
94 
95 namespace monolish {
96 namespace util {
97 
98 template <typename T>
100  Logger &logger = Logger::get_instance();
101  logger.util_in(monolish_func);
102 
103  bool ans = true;
104 
105  if (A.get_row() != B.get_row() || A.get_col() != B.get_col()) {
106  logger.util_out();
107  ans = false;
108  }
109 
110  if (A.get_hash() != B.get_hash()) {
111  logger.util_out();
112  return false;
113  }
114 
115  logger.util_out();
116  return ans;
117 }
118 
119 template bool is_same_structure(const matrix::CRS<double> &A,
120  const matrix::CRS<double> &B);
121 template bool is_same_structure(const matrix::CRS<float> &A,
122  const matrix::CRS<float> &B);
123 
124 template <typename T>
125 bool is_same_size(const matrix::CRS<T> &A, const matrix::CRS<T> &B) {
126  Logger &logger = Logger::get_instance();
127  logger.util_in(monolish_func);
128 
129  bool ans = true;
130 
131  if (A.get_row() != B.get_row() || A.get_col() != B.get_col()) {
132  logger.util_out();
133  ans = false;
134  }
135 
136  logger.util_out();
137  return ans;
138 }
139 
140 template bool is_same_size(const matrix::CRS<double> &A,
141  const matrix::CRS<double> &B);
142 template bool is_same_size(const matrix::CRS<float> &A,
143  const matrix::CRS<float> &B);
144 
145 } // namespace util
146 } // namespace monolish
monolish::matrix::CRS::val
std::vector< Float > val
CRS format value, which stores values of the non-zero elements (size nnz)
Definition: monolish_crs.hpp:61
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
monolish::matrix::CRS::get_hash
size_t get_hash() const
get index array hash (to compare structure)
Definition: monolish_crs.hpp:279
monolish::Logger
logger class (singleton, for developper class)
Definition: monolish_logger.hpp:19
monolish::util::is_same_structure
template bool is_same_structure(const matrix::CRS< float > &A, const matrix::CRS< float > &B)
monolish::matrix::CRS::operator!=
bool operator!=(const CRS< Float > &mat) const
Comparing matricies (A != mat)
Definition: compare_crs.cpp:80
monolish::matrix::CRS::col_ind
std::vector< int > col_ind
CRS format column index, which stores column numbers of the non-zero elements (size nnz)
Definition: monolish_crs.hpp:67
monolish::Logger::util_out
void util_out()
Definition: logger_utils.cpp:123
monolish::matrix::CRS::operator==
bool operator==(const CRS< Float > &mat) const
Comparing matricies (A == mat)
Definition: compare_crs.cpp:68
monolish::Logger::util_in
void util_in(const std::string func_name)
Definition: logger_utils.cpp:113
monolish::matrix::CRS::get_row
size_t get_row() const
get # of row
Definition: monolish_crs.hpp:236
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::util::is_same_size
template bool is_same_size(const matrix::CRS< float > &A, const matrix::CRS< float > &B)
monolish::matrix::CRS::get_device_mem_stat
bool get_device_mem_stat() const
true: sended, false: not send
Definition: monolish_crs.hpp:323
monolish::matrix::CRS::get_col
size_t get_col() const
get # of col
Definition: monolish_crs.hpp:245
monolish::matrix::CRS::equal
bool equal(const CRS< Float > &mat, bool compare_cpu_and_device=false) const
Comparing matricies (A == mat)
Definition: compare_crs.cpp:10
monolish::matrix::CRS::row_ptr
std::vector< int > row_ptr
CRS format row pointer, which stores the starting points of the rows of the arrays value and col_ind ...
Definition: monolish_crs.hpp:73
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42
monolish::matrix::CRS
Compressed Row Storage (CRS) format Matrix.
Definition: monolish_coo.hpp:29