7 template <
class T,
int Tensor_Dim01,
int Tensor_Dim23>
class Ddg
9 T
data[(Tensor_Dim01 * (Tensor_Dim01 + 1)) / 2]
10 [(Tensor_Dim23 * (Tensor_Dim23 + 1)) / 2];
17 T &
operator()(
const int N1,
const int N2,
const int N3,
const int N4)
20 if(N1 >= Tensor_Dim01 || N1 < 0 || N2 >= Tensor_Dim01 || N2 < 0
21 || N3 >= Tensor_Dim23 || N3 < 0 || N4 >= Tensor_Dim23 || N4 < 0)
24 s <<
"Bad index in Dg<T," << Tensor_Dim01 <<
"," << Tensor_Dim23
25 <<
">.operator(" << N1 <<
"," << N2 <<
"," << N3 <<
"," << N4
27 throw std::out_of_range(s.str());
31 ? (N3 > N4 ?
data[N1 + (N2 * (2 * Tensor_Dim01 - N2 - 1)) / 2]
32 [N3 + (N4 * (2 * Tensor_Dim23 - N4 - 1)) / 2]
33 :
data[N1 + (N2 * (2 * Tensor_Dim01 - N2 - 1)) / 2]
34 [N4 + (N3 * (2 * Tensor_Dim23 - N3 - 1)) / 2])
35 : (N3 > N4 ?
data[N2 + (N1 * (2 * Tensor_Dim01 - N1 - 1)) / 2]
36 [N3 + (N4 * (2 * Tensor_Dim23 - N4 - 1)) / 2]
37 :
data[N2 + (N1 * (2 * Tensor_Dim01 - N1 - 1)) / 2]
38 [N4 + (N3 * (2 * Tensor_Dim23 - N3 - 1)) / 2]);
41 T
operator()(
const int N1,
const int N2,
const int N3,
const int N4)
const
44 if(N1 >= Tensor_Dim01 || N1 < 0 || N2 >= Tensor_Dim01 || N2 < 0
45 || N3 >= Tensor_Dim23 || N3 < 0 || N4 >= Tensor_Dim23 || N4 < 0)
48 s <<
"Bad index in Dg<T," << Tensor_Dim01 <<
"," << Tensor_Dim23
49 <<
">.operator(" << N1 <<
"," << N2 <<
"," << N3 <<
"," << N4
50 <<
") const" << std::endl;
51 throw std::out_of_range(s.str());
55 ? (N3 > N4 ?
data[N1 + (N2 * (2 * Tensor_Dim01 - N2 - 1)) / 2]
56 [N3 + (N4 * (2 * Tensor_Dim23 - N4 - 1)) / 2]
57 :
data[N1 + (N2 * (2 * Tensor_Dim01 - N2 - 1)) / 2]
58 [N4 + (N3 * (2 * Tensor_Dim23 - N3 - 1)) / 2])
59 : (N3 > N4 ?
data[N2 + (N1 * (2 * Tensor_Dim01 - N1 - 1)) / 2]
60 [N3 + (N4 * (2 * Tensor_Dim23 - N4 - 1)) / 2]
61 :
data[N2 + (N1 * (2 * Tensor_Dim01 - N1 - 1)) / 2]
62 [N4 + (N3 * (2 * Tensor_Dim23 - N3 - 1)) / 2]);
65 template <
int N1,
int N2,
int N3,
int N4>
69 static_assert(N1 < Tensor_Dim01,
"Bad index N1");
70 static_assert(N2 < Tensor_Dim01,
"Bad index N2");
71 static_assert(N3 < Tensor_Dim23,
"Bad index N3");
72 static_assert(N4 < Tensor_Dim23,
"Bad index N4");
74 if constexpr (N1 > N2) {
75 if constexpr (N3 > N4)
76 return data[N1 + (N2 * (2 * Tensor_Dim01 - N2 - 1)) / 2]
77 [N3 + (N4 * (2 * Tensor_Dim23 - N4 - 1)) / 2];
79 return data[N1 + (N2 * (2 * Tensor_Dim01 - N2 - 1)) / 2]
80 [N4 + (N3 * (2 * Tensor_Dim23 - N3 - 1)) / 2];
82 if constexpr (N3 > N4)
83 return data[N2 + (N1 * (2 * Tensor_Dim01 - N1 - 1)) / 2]
84 [N3 + (N4 * (2 * Tensor_Dim23 - N4 - 1)) / 2];
86 return data[N2 + (N1 * (2 * Tensor_Dim01 - N1 - 1)) / 2]
87 [N4 + (N3 * (2 * Tensor_Dim23 - N3 - 1)) / 2];
91 template <
int N1,
int N2,
int N3,
int N4>
95 static_assert(N1 < Tensor_Dim01,
"Bad index N1");
96 static_assert(N2 < Tensor_Dim01,
"Bad index N2");
97 static_assert(N3 < Tensor_Dim23,
"Bad index N3");
98 static_assert(N4 < Tensor_Dim23,
"Bad index N4");
100 if constexpr (N1 > N2) {
101 if constexpr (N3 > N4)
102 return data[N1 + (N2 * (2 * Tensor_Dim01 - N2 - 1)) / 2]
103 [N3 + (N4 * (2 * Tensor_Dim23 - N4 - 1)) / 2];
105 return data[N1 + (N2 * (2 * Tensor_Dim01 - N2 - 1)) / 2]
106 [N4 + (N3 * (2 * Tensor_Dim23 - N3 - 1)) / 2];
108 if constexpr (N3 > N4)
109 return data[N2 + (N1 * (2 * Tensor_Dim01 - N1 - 1)) / 2]
110 [N3 + (N4 * (2 * Tensor_Dim23 - N4 - 1)) / 2];
112 return data[N2 + (N1 * (2 * Tensor_Dim01 - N1 - 1)) / 2]
113 [N4 + (N3 * (2 * Tensor_Dim23 - N3 - 1)) / 2];
122 template <
char i,
char j,
char k,
char l,
int Dim01,
int Dim23>
123 typename std::enable_if<(Tensor_Dim01 >= Dim01 && Tensor_Dim23 >= Dim23),
133 template <
char i,
char j,
char k,
char l,
int Dim01,
int Dim23>
134 typename std::enable_if<(Tensor_Dim01 >= Dim01 && Tensor_Dim23 >= Dim23),
141 Dim23,
i,
j,
k,
l>(*this);
147 template <
char i,
char j,
int N0,
int N1,
int Dim>
149 (Tensor_Dim01 > N0 && Tensor_Dim01 > N1 && Tensor_Dim23 >= Dim),
162 template <
char i,
char j,
int N0,
int N1,
int Dim>
164 (Tensor_Dim01 > N0 && Tensor_Dim01 > N1 && Tensor_Dim23 >= Dim),
179 template <
char i,
char j,
char k,
int N0,
int Dim1,
int Dim23>
181 (Tensor_Dim01 > N0 && Tensor_Dim01 >= Dim1 && Tensor_Dim23 >= Dim23),
192 template <
char i,
char j,
char k,
int N0,
int Dim1,
int Dim23>
194 (Tensor_Dim01 > N0 && Tensor_Dim01 >= Dim1 && Tensor_Dim23 >= Dim23),
209 template <
char i,
char j,
int Dim>
211 (Tensor_Dim23 >= Dim),
221 TensorExpr(*
this, N0, N1));
224 template <
char i,
char j,
int Dim>
226 (Tensor_Dim01 >= Dim),
236 TensorExpr(*
this, N2, N3));
241 template <
char i,
char j,
int Dim1,
int Dim3>
243 (Tensor_Dim01 >= Dim1 && Tensor_Dim23 >= Dim3),
245 T, Dim1, Dim3,
i,
j>>::
type
252 TensorExpr(*
this, N0, N2));
257 template <
char i,
int Dim>
259 (Tensor_Dim01 >= Dim),
267 TensorExpr(*
this, N1, N2, N3));
270 template <
char i,
int Dim>
272 (Tensor_Dim01 >= Dim),
280 TensorExpr(*
this, N1, N2, N3));
287 template <
char i,
char j,
char k,
int Dim1,
int Dim23>
289 (Tensor_Dim01 >= Dim1 && Tensor_Dim23 >= Dim23),
298 TensorExpr(*
this, N0));