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