-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.h
More file actions
100 lines (72 loc) · 2.46 KB
/
matrix.h
File metadata and controls
100 lines (72 loc) · 2.46 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef MATRIX_H
#define MATRIX_H
#include <fstream>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <omp.h>
#include <sparsematrix.h>
//class SparseMatrix;
#define MATRIX_OPTIMIZATION
#define SPARSE_END 0
class Vector
{
public:
Vector();
Vector(const Vector &V1);
Vector(size_t h);
Vector(std::vector<double> &V1);
Vector(const char *file);
~Vector(){}
std::vector<double> V;
size_t H;
inline double get(size_t i) const;
inline void set(size_t i, double value);
void zeros(size_t h);
void resize(size_t h);
void print() const;
void permute(std::vector<size_t>& P);
double normInf();
friend Vector operator +(const Vector &V1, const Vector &V2);
friend Vector operator -(const Vector &V1, const Vector &V2);
friend Vector& operator -=(Vector &V1, const Vector &V2);
friend Vector& operator +=(Vector &V1, const Vector &V2);
double& operator()(size_t i);
friend Vector operator *(const SparseMatrix &S, const Vector &V);
void save2file(const char* file);
};
class Matrix
{
public:
Matrix();
Matrix(const Matrix &_M);
Matrix(size_t h, size_t w);
Matrix(size_t h);
Matrix(const char *file);
Matrix(const SparseMatrix &S);
std::vector<double> M;
size_t H;
size_t W;
void zeros(size_t h, size_t w);
void print() const;
void swapRow(size_t r1, size_t r2);
void swapCol(size_t c1, size_t c2);
double& operator()(size_t row, size_t col);
friend Matrix operator +(const Matrix &M1, const Matrix &M2);
friend Matrix operator -(const Matrix &M1, const Matrix &M2);
friend Matrix& operator -=(Matrix &M1, const Matrix &M2);
friend Matrix& operator +=(Matrix &M1, const Matrix &M2);
friend Matrix operator *(const Matrix &M1, const Matrix &M2);
friend Vector operator *(const Matrix &M, const Vector &V);
friend Matrix operator *(const SparseMatrix &S, const Matrix &M);
friend Matrix operator *(const Matrix &M, const SparseMatrix &S);
friend Vector operator *(const SparseMatrix &S, const Vector &V);
friend Matrix operator +(const SparseMatrix &S, const Matrix &M);
friend Matrix operator +(const Matrix &M, const SparseMatrix &S);
friend Matrix& operator +=(Matrix &M, const SparseMatrix &S);
friend Matrix operator -(const SparseMatrix &S, const Matrix &M);
friend Matrix operator -(const Matrix &M, const SparseMatrix &S);
};
#endif // MATRIX_H