monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
coo_getvec.cpp
Go to the documentation of this file.
1 #include "../../../include/monolish_blas.hpp"
2 #include "../../internal/monolish_internal.hpp"
3 
4 namespace monolish {
5 namespace matrix {
6 
7 // diag
8 template <typename T> void COO<T>::diag(vector<T> &vec) const {
9  Logger &logger = Logger::get_instance();
10  logger.func_in(monolish_func);
11 
12  size_t s = get_row() > get_col() ? get_col() : get_row();
13  assert(s == vec.size());
14 
15  for (size_t i = 0; i < vec.size(); i++) {
16  vec[i] = 0;
17  }
18 
19  for (size_t nz = 0; nz < get_nnz(); ++nz) {
20  if (get_row_ptr()[nz] == get_col_ind()[nz]) {
21  vec[get_row_ptr()[nz]] = get_val_ptr()[nz];
22  }
23  }
24 
25  logger.func_out();
26 }
27 template void monolish::matrix::COO<double>::diag(vector<double> &vec) const;
28 template void monolish::matrix::COO<float>::diag(vector<float> &vec) const;
29 
30 template <typename T> void COO<T>::diag(view1D<vector<T>, T> &vec) const {
31  Logger &logger = Logger::get_instance();
32  logger.func_in(monolish_func);
33 
34  size_t s = get_row() > get_col() ? get_col() : get_row();
35  assert(s == vec.size());
36 
37  for (size_t i = 0; i < vec.size(); i++) {
38  vec[i] = 0;
39  }
40 
41  for (size_t nz = 0; nz < get_nnz(); ++nz) {
42  if (get_row_ptr()[nz] == get_col_ind()[nz]) {
43  vec[get_row_ptr()[nz]] = get_val_ptr()[nz];
44  }
45  }
46  logger.func_out();
47 }
48 template void
49 monolish::matrix::COO<double>::diag(view1D<vector<double>, double> &vec) const;
50 template void
51 monolish::matrix::COO<float>::diag(view1D<vector<float>, float> &vec) const;
52 
53 template <typename T>
54 void COO<T>::diag(view1D<matrix::Dense<T>, T> &vec) const {
55  Logger &logger = Logger::get_instance();
56  logger.func_in(monolish_func);
57 
58  size_t s = get_row() > get_col() ? get_col() : get_row();
59  assert(s == vec.size());
60 
61  for (size_t i = 0; i < vec.size(); i++) {
62  vec[i] = 0;
63  }
64 
65  for (size_t nz = 0; nz < get_nnz(); ++nz) {
66  if (get_row_ptr()[nz] == get_col_ind()[nz]) {
67  vec[get_row_ptr()[nz]] = get_val_ptr()[nz];
68  }
69  }
70 
71  logger.func_out();
72 }
74  view1D<matrix::Dense<double>, double> &vec) const;
76  view1D<matrix::Dense<float>, float> &vec) const;
77 
78 // row
79 template <typename T> void COO<T>::row(const size_t r, vector<T> &vec) const {
80  Logger &logger = Logger::get_instance();
81  logger.func_in(monolish_func);
82 
83  assert(get_col() == vec.size());
84 
85  for (size_t i = 0; i < vec.size(); i++) {
86  vec[i] = 0;
87  }
88 
89  for (size_t nz = 0; nz < get_nnz(); ++nz) {
90  if (get_row_ptr()[nz] == static_cast<int>(r)) {
91  vec[get_col_ind()[nz]] = get_val_ptr()[nz];
92  }
93  }
94  logger.func_out();
95 }
96 template void monolish::matrix::COO<double>::row(const size_t r,
97  vector<double> &vec) const;
98 template void monolish::matrix::COO<float>::row(const size_t r,
99  vector<float> &vec) const;
100 
101 template <typename T>
102 void COO<T>::row(const size_t r, view1D<vector<T>, T> &vec) const {
103  Logger &logger = Logger::get_instance();
104  logger.func_in(monolish_func);
105 
106  assert(get_col() == vec.size());
107 
108  for (size_t i = 0; i < vec.size(); i++) {
109  vec[i] = 0;
110  }
111 
112  for (size_t nz = 0; nz < get_nnz(); ++nz) {
113  if (get_row_ptr()[nz] == static_cast<int>(r)) {
114  vec[get_col_ind()[nz]] = get_val_ptr()[nz];
115  }
116  }
117  logger.func_out();
118 }
119 template void
121  view1D<vector<double>, double> &vec) const;
122 template void
123 monolish::matrix::COO<float>::row(const size_t r,
124  view1D<vector<float>, float> &vec) const;
125 
126 template <typename T>
127 void COO<T>::row(const size_t r, view1D<matrix::Dense<T>, T> &vec) const {
128  Logger &logger = Logger::get_instance();
129  logger.func_in(monolish_func);
130 
131  assert(get_col() == vec.size());
132 
133  for (size_t i = 0; i < vec.size(); i++) {
134  vec[i] = 0;
135  }
136 
137  for (size_t nz = 0; nz < get_nnz(); ++nz) {
138  if (get_row_ptr()[nz] == static_cast<int>(r)) {
139  vec[get_col_ind()[nz]] = get_val_ptr()[nz];
140  }
141  }
142  logger.func_out();
143 }
145  const size_t r, view1D<matrix::Dense<double>, double> &vec) const;
147  const size_t r, view1D<matrix::Dense<float>, float> &vec) const;
148 
149 // col
150 template <typename T> void COO<T>::col(const size_t c, vector<T> &vec) const {
151  Logger &logger = Logger::get_instance();
152  logger.func_in(monolish_func);
153 
154  assert(get_row() == vec.size());
155 
156  for (size_t i = 0; i < vec.size(); i++) {
157  vec[i] = 0;
158  }
159 
160  for (size_t nz = 0; nz < get_nnz(); ++nz) {
161  if (get_col_ind()[nz] == static_cast<int>(c)) {
162  vec[get_row_ptr()[nz]] = get_val_ptr()[nz];
163  }
164  }
165  logger.func_out();
166 }
167 template void monolish::matrix::COO<double>::col(const size_t c,
168  vector<double> &vec) const;
169 template void monolish::matrix::COO<float>::col(const size_t c,
170  vector<float> &vec) const;
171 
172 template <typename T>
173 void COO<T>::col(const size_t c, view1D<vector<T>, T> &vec) const {
174  Logger &logger = Logger::get_instance();
175  logger.func_in(monolish_func);
176 
177  assert(get_row() == vec.size());
178 
179  for (size_t i = 0; i < vec.size(); i++) {
180  vec[i] = 0;
181  }
182 
183  for (size_t nz = 0; nz < get_nnz(); ++nz) {
184  if (get_col_ind()[nz] == static_cast<int>(c)) {
185  vec[get_row_ptr()[nz]] = get_val_ptr()[nz];
186  }
187  }
188  logger.func_out();
189 }
190 template void
192  view1D<vector<double>, double> &vec) const;
193 template void
194 monolish::matrix::COO<float>::col(const size_t c,
195  view1D<vector<float>, float> &vec) const;
196 
197 template <typename T>
198 void COO<T>::col(const size_t c, view1D<matrix::Dense<T>, T> &vec) const {
199  Logger &logger = Logger::get_instance();
200  logger.func_in(monolish_func);
201 
202  assert(get_row() == vec.size());
203 
204  for (size_t i = 0; i < vec.size(); i++) {
205  vec[i] = 0;
206  }
207 
208  for (size_t nz = 0; nz < get_nnz(); ++nz) {
209  if (get_col_ind()[nz] == static_cast<int>(c)) {
210  vec[get_row_ptr()[nz]] = get_val_ptr()[nz];
211  }
212  }
213  logger.func_out();
214 }
216  const size_t c, view1D<matrix::Dense<double>, double> &vec) const;
218  const size_t c, view1D<matrix::Dense<float>, float> &vec) const;
219 } // namespace matrix
220 } // namespace monolish
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
monolish::matrix::COO::diag
void diag(vector< Float > &vec) const
get diag. vector
monolish::matrix::COO::row
void row(const size_t r, vector< Float > &vec) const
get row vector
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42
monolish::matrix::COO::col
void col(const size_t c, vector< Float > &vec) const
get column vector