Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F104194265
matrix_coo.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Mar 7, 03:42
Size
881 B
Mime Type
text/x-c++
Expires
Sun, Mar 9, 03:42 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
24762701
Attached To
R12662 PHPC-graded_hw_1
matrix_coo.hh
View Options
#include <algorithm>
#include <string>
#include <vector>
#ifndef __MATRIX_COO_H_
#define __MATRIX_COO_H_
class MatrixCOO {
public:
MatrixCOO() = default;
inline int m() const { return m_m; }
inline int n() const { return m_n; }
inline int nz() const { return irn.size(); }
inline int is_sym() const { return m_is_sym; }
void read(const std::string & filename);
void mat_vec(const std::vector<double> & x, std::vector<double> & y) {
std::fill_n(y.begin(), y.size(), 0.);
for (size_t z = 0; z < irn.size(); ++z) {
auto i = irn[z];
auto j = jcn[z];
auto a_ = a[z];
y[i] += a_ * x[j];
if (m_is_sym and (i != j)) {
y[j] += a_ * x[i];
}
}
}
std::vector<int> irn;
std::vector<int> jcn;
std::vector<double> a;
private:
int m_m{0};
int m_n{0};
bool m_is_sym{false};
};
#endif // __MATRIX_COO_H_
Event Timeline
Log In to Comment