monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
compare_vector.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 "../../../include/monolish_vml.hpp"
5 #include "../../internal/monolish_internal.hpp"
6 
7 namespace monolish {
8 
9 namespace {
10 template <typename V1, typename V2>
11 bool equal_core(const V1 &vec1, const V2 &vec2, bool compare_cpu_and_device) {
12  Logger &logger = Logger::get_instance();
13  logger.util_in(monolish_func);
14 
15  if (vec1.size() != vec2.size()) {
16  return false;
17  }
18  if (vec1.get_device_mem_stat() != vec2.get_device_mem_stat()) {
19  return false;
20  }
21 
22  if (vec1.get_device_mem_stat() == true) {
23  if (!(internal::vequal(vec1.size(), vec1.data() + vec1.get_offset(),
24  vec2.data() + vec2.get_offset(), true))) {
25  return false;
26  }
27  } else if (vec1.get_device_mem_stat() == false ||
28  compare_cpu_and_device == false) {
29  if (!(internal::vequal(vec1.size(), vec1.data() + vec1.get_offset(),
30  vec2.data() + vec2.get_offset(), false))) {
31  return false;
32  }
33  }
34 
35  logger.util_out();
36  return true;
37 }
38 } // namespace
39 
40 template <typename T>
41 bool vector<T>::equal(const vector<T> &vec, bool compare_cpu_and_device) const {
42  return equal_core(*this, vec, compare_cpu_and_device);
43 }
44 template bool vector<double>::equal(const vector<double> &vec,
45  bool compare_cpu_and_device) const;
46 template bool vector<float>::equal(const vector<float> &vec,
47  bool compare_cpu_and_device) const;
48 
49 template <typename T>
50 bool vector<T>::equal(const view1D<vector<T>, T> &vec,
51  bool compare_cpu_and_device) const {
52  return equal_core(*this, vec, compare_cpu_and_device);
53 }
54 template bool vector<double>::equal(const view1D<vector<double>, double> &vec,
55  bool compare_cpu_and_device) const;
56 template bool vector<float>::equal(const view1D<vector<float>, float> &vec,
57  bool compare_cpu_and_device) const;
58 
59 template <typename T>
60 bool vector<T>::equal(const view1D<matrix::Dense<T>, T> &vec,
61  bool compare_cpu_and_device) const {
62  return equal_core(*this, vec, compare_cpu_and_device);
63 }
64 template bool
65 vector<double>::equal(const view1D<matrix::Dense<double>, double> &vec,
66  bool compare_cpu_and_device) const;
67 template bool
68 vector<float>::equal(const view1D<matrix::Dense<float>, float> &vec,
69  bool compare_cpu_and_device) const;
70 
71 template <typename T> bool vector<T>::operator==(const vector<T> &vec) const {
72  return equal_core(*this, vec, false);
73 }
74 template bool vector<double>::operator==(const vector<double> &vec) const;
75 template bool vector<float>::operator==(const vector<float> &vec) const;
76 
77 template <typename T>
78 bool vector<T>::operator==(const view1D<vector<T>, T> &vec) const {
79  return equal_core(*this, vec, false);
80 }
81 template bool
82 vector<double>::operator==(const view1D<vector<double>, double> &vec) const;
83 template bool
84 vector<float>::operator==(const view1D<vector<float>, float> &vec) const;
85 
86 template <typename T>
87 bool vector<T>::operator==(const view1D<matrix::Dense<T>, T> &vec) const {
88  return equal_core(*this, vec, false);
89 }
90 template bool vector<double>::operator==(
91  const view1D<matrix::Dense<double>, double> &vec) const;
92 template bool
93 vector<float>::operator==(const view1D<matrix::Dense<float>, float> &vec) const;
94 
95 template <typename T> bool vector<T>::operator!=(const vector<T> &vec) const {
96  return !equal_core(*this, vec, false);
97 }
98 template bool vector<double>::operator!=(const vector<double> &vec) const;
99 template bool vector<float>::operator!=(const vector<float> &vec) const;
100 
101 template <typename T>
102 bool vector<T>::operator!=(const view1D<vector<T>, T> &vec) const {
103  return !equal_core(*this, vec, false);
104 }
105 template bool
106 vector<double>::operator!=(const view1D<vector<double>, double> &vec) const;
107 template bool
108 vector<float>::operator!=(const view1D<vector<float>, float> &vec) const;
109 
110 template <typename T>
111 bool vector<T>::operator!=(const view1D<matrix::Dense<T>, T> &vec) const {
112  return !equal_core(*this, vec, false);
113 }
114 template bool vector<double>::operator!=(
115  const view1D<matrix::Dense<double>, double> &vec) const;
116 template bool
117 vector<float>::operator!=(const view1D<matrix::Dense<float>, float> &vec) const;
118 
119 } // namespace monolish
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::vector::operator!=
bool operator!=(const vector< Float > &vec) const
Comparing vectors (v != vec)
monolish::vector::operator==
bool operator==(const vector< Float > &vec) const
Comparing vectors (v == vec)
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42
monolish::vector::equal
bool equal(const vector< Float > &vec, bool compare_cpu_and_device=false) const
Comparing matricies (A == mat)