-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvectorCPU.hpp
61 lines (57 loc) · 1.56 KB
/
vectorCPU.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once
#include <vector>
class VectorCPU {
protected:
// attributes
unsigned rows;
unsigned columns;
std::vector<double> mat;
public:
/** Constructors */
VectorCPU() : VectorCPU(0, 0){}; // Default Constr.
VectorCPU(unsigned r, unsigned c) : rows(r), columns(c) { // Constr. #2
this->mat.resize(r * c, 0);
};
VectorCPU(unsigned r, unsigned c, double *v) : rows(r), columns(c) {
mat.resize(r * c);
mat.assign(v, v + r * c);
};
VectorCPU(const VectorCPU &v) : columns(v.columns), rows(v.rows), mat(v.mat){};
VectorCPU(VectorCPU &&v) noexcept : VectorCPU(v) {
v.rows = 0;
v.columns = 0;
v.mat.clear();
}
~VectorCPU() { mat.clear(); };
/** Assignments */
VectorCPU &operator=(const VectorCPU &v) { // Copy Assignment
rows = v.rows;
columns = v.columns;
mat = v.mat;
return *this;
};
VectorCPU &operator=(VectorCPU &&v) noexcept { // Move Assignment
// call copy assignment
*this = v;
v.rows = 0;
v.columns = 0;
v.mat.clear();
return *this;
};
// operator overloads
VectorCPU operator*(VectorCPU &v);
VectorCPU operator*(double i);
VectorCPU operator-(VectorCPU v);
VectorCPU operator+(VectorCPU v);
double operator()(unsigned i);
double operator()(unsigned r, unsigned c);
double operator[](unsigned i);
// member functions
double *getMat() { return this->mat.data(); };
void printMat();
int getRows() { return this->rows; };
int getColumns() { return this->columns; };
double Dnrm2();
double normalNorm();
VectorCPU transpose();
};