-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathndmatrix_matrices.h
133 lines (109 loc) · 2.67 KB
/
ndmatrix_matrices.h
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* Synthesizable struct for addressing a multi-dimensional
* array using a single wide Vector.
*
* Created By Dionisis Filippas 30/11/2022 */
#ifndef __NDMATRIX_MATRICES__
#define __NDMATRIX_MATRICES__
template<typename T, int N , int M, int K, int L>
struct Mat4d {
#ifdef __SYNTHESIS__
T ar[N*M*K*L];
Mat4d(){};
~Mat4d(){};
#else
T* ar;
Mat4d() { ar = new T[N*M*K*L]; };
~Mat4d() { delete[] ar; };
#endif
struct Dim1 {
Mat4d& _ar;
int cur_n;
Dim1(Mat4d& A, const int n) : _ar(A), cur_n(n) {};
struct Dim2 {
Dim1& d1;
int cur_m;
Dim2(Dim1& A, const int m) : d1(A), cur_m(m) {};
struct Dim3 {
Dim2& d2;
int cur_k;
Dim3(Dim2& A, const int k) : d2(A), cur_k(k) {};
T& operator[] (const int l) {
return d2.d1._ar.ar[d2.d1.cur_n*M*K*L + d2.cur_m*K*L + cur_k*L + l];
};
};
Dim3 operator[] (const int k) { return Dim3(*this, k); };
};
Dim2 operator[] (const int m) { return Dim2(*this, m); };
};
Dim1 operator[] (const int n) { return Dim1(*this, n); };
};// struct Mat4d
template<typename T, int N , int M, int K>
struct Mat3d {
#ifdef __SYNTHESIS__
T ar[N*M*K];
Mat3d(){};
~Mat3d(){};
#else
T* ar;
Mat3d() { ar = new T[N*M*K]; };
~Mat3d() { delete[] ar; };
#endif
struct Dim1 {
Mat3d& _ar;
int cur_n;
Dim1(Mat3d& A, const int n) : _ar(A), cur_n(n) {};
struct Dim2 {
Dim1& __ar;
int cur_m;
Dim2(Dim1& A, const int m) : __ar(A), cur_m(m) {};
T& operator[] (const int k) {
return __ar._ar.ar[__ar.cur_n*M*K +cur_m*K + k];
};
};
Dim2 operator[] (const int m) { return Dim2(*this, m); };
};
Dim1 operator[] (const int n) { return Dim1(*this, n); };
}; // struct Mat3d
template<typename T, int N , int M>
struct Mat2d {
#ifdef __SYNTHESIS__
T ar[N*M];
Mat2d(){};
~Mat2d(){};
#else
T* ar;
Mat2d() { ar = new T[N*M]; };
~Mat2d() { delete[] ar; };
#endif
struct Dim1 {
Mat2d& _ar;
int cur_n;
Dim1(Mat2d& A, const int n) : _ar(A), cur_n(n) {};
T& operator[] (const int m) {
return _ar.ar[cur_n*M + m];
};
};
Dim1 operator[] (const int n) { return Dim1(*this, n); };
}; // struct Mat2d
template<typename T, int N>
struct Mat1d {
#ifdef __SYNTHESIS__
T ar[N];
Mat1d(){};
~Mat1d(){};
#else
T* ar;
Mat1d() { ar = new T[N]{0}; };
Mat1d(const Mat1d<T, N> &old) {
ar = new T[N]{0};
for (int i = 0; i < N; i++) {
ar[i] = old.ar[i];
}
}
~Mat1d() { delete[] ar; };
#endif
T& operator[] (const int n) {
return ar[n];
};
}; // struct Mat2d
#endif