16 template <
class T,
int Tensor_Dim0,
int Tensor_Dim1,
int Tensor_Dim2,
20 T
data[Tensor_Dim0][Tensor_Dim1][Tensor_Dim2][Tensor_Dim3];
26 static_assert(
sizeof...(
d) ==
sizeof(
data) /
sizeof(T),
27 "Incorrect number of Arguments. Constructor should "
28 "initialize the entire Tensor");
35 T &
operator()(
const int N1,
const int N2,
const int N3,
const int N4)
38 if(N1 >= Tensor_Dim0 || N1 < 0 || N2 >= Tensor_Dim1 || N2 < 0
39 || N3 >= Tensor_Dim2 || N3 < 0 || N4 >= Tensor_Dim3 || N4 < 0)
42 s <<
"Bad index in Tensor4<T," << Tensor_Dim0 <<
"," << Tensor_Dim1
43 <<
"," << Tensor_Dim2 <<
"," << Tensor_Dim3 <<
">.operator(" << N1
44 <<
"," << N2 <<
"," << N3 <<
"," << N4 <<
") const" << std::endl;
45 throw std::out_of_range(s.str());
48 return data[N1][N2][N3][N4];
51 T
operator()(
const int N1,
const int N2,
const int N3,
const int N4)
const
54 if(N1 >= Tensor_Dim0 || N1 < 0 || N2 >= Tensor_Dim1 || N2 < 0
55 || N3 >= Tensor_Dim2 || N3 < 0 || N4 >= Tensor_Dim3 || N4 < 0)
58 s <<
"Bad index in Tensor4<T," << Tensor_Dim0 <<
"," << Tensor_Dim1
59 <<
"," << Tensor_Dim2 <<
"," << Tensor_Dim3 <<
">.operator(" << N1
60 <<
"," << N2 <<
"," << N3 <<
"," << N4 <<
")" << std::endl;
61 throw std::out_of_range(s.str());
64 return data[N1][N2][N3][N4];
71 template <
char i,
char j,
char k,
char l,
int Dim0,
int Dim1,
int Dim2,
74 (Tensor_Dim0 >= Dim0 && Tensor_Dim1 >= Dim1 && Tensor_Dim2 >= Dim2
75 && Tensor_Dim3 >= Dim3),
77 T, Dim0, Dim1, Dim2, Dim3,
i,
j,
k,
l>>::
type
83 Dim0, Dim1, Dim2, Dim3,
i,
j,
k,
l>(*this);
86 template <
char i,
char j,
char k,
char l,
int Dim0,
int Dim1,
int Dim2,
89 (Tensor_Dim0 >= Dim0 && Tensor_Dim1 >= Dim1 && Tensor_Dim2 >= Dim2
90 && Tensor_Dim3 >= Dim3),
93 T, Dim0, Dim1, Dim2, Dim3,
i,
j,
k,
l>>::
type
99 T, Dim0, Dim1, Dim2, Dim3,
i,
j,
k,
l>(*this);
106 template <
char i,
char j,
char k,
int Dim0,
int Dim1,
int Dim23>
110 static_assert(Tensor_Dim0 >= Dim0 && Tensor_Dim1 >= Dim1
111 && Tensor_Dim2 >= Dim23 && Tensor_Dim3 >= Dim23,
112 "Incompatible indices");
121 template <
char i,
char j,
char k,
int Dim0,
int Dim13,
int Dim2>
125 static_assert(Tensor_Dim0 >= Dim0 && Tensor_Dim1 >= Dim13
126 && Tensor_Dim2 >= Dim2 && Tensor_Dim3 >= Dim13,
127 "Incompatible indices");
136 template <
char i,
char j,
char l,
int Dim0,
int Dim12,
int Dim3>
140 static_assert(Tensor_Dim0 >= Dim0 && Tensor_Dim1 >= Dim12
141 && Tensor_Dim2 >= Dim12 && Tensor_Dim3 >= Dim3,
142 "Incompatible indices");
151 template <
char i,
char j,
char k,
int Dim03,
int Dim1,
int Dim2>
155 static_assert(Tensor_Dim0 >= Dim03 && Tensor_Dim1 >= Dim1
156 && Tensor_Dim2 >= Dim2 && Tensor_Dim3 >= Dim03,
157 "Incompatible indices");
166 template <
char i,
char j,
char l,
int Dim02,
int Dim1,
int Dim3>
170 static_assert(Tensor_Dim0 >= Dim02 && Tensor_Dim1 >= Dim1
171 && Tensor_Dim2 >= Dim02 && Tensor_Dim3 >= Dim3,
172 "Incompatible indices");
181 template <
char i,
char k,
char l,
int Dim01,
int Dim2,
int Dim3>
185 static_assert(Tensor_Dim0 >= Dim01 && Tensor_Dim1 >= Dim01
186 && Tensor_Dim2 >= Dim2 && Tensor_Dim3 >= Dim3,
187 "Incompatible indices");
204 template <
char i,
char j,
char k,
int N,
int Dim0,
int Dim1,
int Dim3>
206 (Tensor_Dim0 >= Dim0 && Tensor_Dim1 >= Dim1 && Tensor_Dim2 >
N &&
207 Tensor_Dim3 >= Dim3),
209 Tensor_Dim2, Tensor_Dim3>,
211 T, Dim0, Dim1, Dim3,
i,
j,
k>>::
type
219 template <
char i,
char j,
char k,
int N,
int Dim0,
int Dim1,
int Dim3>
221 (Tensor_Dim0 >= Dim0 && Tensor_Dim1 >= Dim1 && Tensor_Dim2 >
N &&
222 Tensor_Dim3 >= Dim3),
224 Tensor_Dim2, Tensor_Dim3>,
226 T, Dim0, Dim1, Dim3,
i,
j,
k>>::
type
238 template <
char i,
char j,
char k,
int N,
int Dim0,
int Dim1,
int Dim2>
240 (Tensor_Dim0 >= Dim0 && Tensor_Dim1 >= Dim1 && Tensor_Dim2 >= Dim2 &&
243 Tensor_Dim2, Tensor_Dim3>,
245 T, Dim0, Dim1, Dim2,
i,
j,
k>>::
type
253 template <
char i,
char j,
char k,
int N,
int Dim0,
int Dim1,
int Dim2>
255 (Tensor_Dim0 >= Dim0 && Tensor_Dim1 >= Dim1 && Tensor_Dim2 >= Dim2 &&
258 Tensor_Dim2, Tensor_Dim3>,
260 T, Dim0, Dim1, Dim2,
i,
j,
k>>::
type
276 template <
class T,
int Tensor_Dim0,
int Tensor_Dim1,
int Tensor_Dim2,
281 const int &iterator0,
const int &iterator1,
const int &iterator2)
284 for(
int i = 0;
i < Tensor_Dim3 - 1; ++
i)
286 os <<
t(iterator0, iterator1, iterator2,
i);
289 os <<
t(iterator0, iterator1, iterator2, Tensor_Dim3 - 1);
295 template <
class T,
int Tensor_Dim0,
int Tensor_Dim1,
int Tensor_Dim2,
300 const int &iterator0,
const int &iterator1)
303 for(
int i = 0;
i < Tensor_Dim2 - 1; ++
i)
314 template <
class T,
int Tensor_Dim0,
int Tensor_Dim1,
int Tensor_Dim2,
319 const int &iterator0)
322 for(
int i = 0;
i < Tensor_Dim1 - 1; ++
i)
334 template <
class T,
int Tensor_Dim0,
int Tensor_Dim1,
int Tensor_Dim2,
338 Tensor_Dim2, Tensor_Dim3> &
t)
341 for(
int i = 0;
i < Tensor_Dim0 - 1; ++
i)