-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixOperation.h
More file actions
86 lines (62 loc) · 1.44 KB
/
MatrixOperation.h
File metadata and controls
86 lines (62 loc) · 1.44 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
/*
* MatrixOperation.h
*
* Created on: Mar 17, 2019
* Author: Claire
*/
#ifndef MATRIXOPERATION_H_
#define MATRIXOPERATION_H_
#include <array>
#include "ComplexNumber.h"
template<int rows, int columns, class T>
class Matrix{
public:
Matrix() : data{} {}
std::array<std::array<T, columns>, rows> data;
T operator()(int x, int y){
return data[x][y];
}
};
template<class T>
class Matrix<2, 2, T>{
public:
Matrix() : data{} {}
Matrix(std::initializer_list<std::initializer_list<T>> init) {
auto dp = data.begin();
for (auto row : init) {
std::copy(row.begin(), row.end(), dp->begin());
dp++;
}
}
T operator()(int x, int y){
return data[x][y];
}
std::array<std::array<T, 2>, 2> data;
};
template<class T>
class Matrix<2, 1, T>{
public:
Matrix() : data{} {}
Matrix(std::initializer_list<std::initializer_list<T>> init) {
auto dp = data.begin();
for (auto row : init) {
std::copy(row.begin(), row.end(), dp->begin());
dp++;
}
}
T &operator()(int x, int y){
return data[x][y];
}
T operator()(int x, int y) const {
return data[x][y];
}
std::array<std::array<T, 1>, 2> data;
};
inline class Matrix<2, 1, ComplexNumber> operator*(Matrix<2, 2, double> &l, Matrix<2, 1, ComplexNumber> &r){
Matrix<2, 1, ComplexNumber> result;
ComplexNumber a;
result(0, 0) = l(0, 0) * r(0, 0) + l(0, 1) * r(1, 0);
result(1, 0) = l(1, 0) * r(0, 0) + l(1, 1) * r(1, 0);
return result;
};
#endif /* MATRIXOPERATION_H_ */