v0.10.0
Tensor4_Expr.hpp
Go to the documentation of this file.
1 /* Declare a wrapper class for generic rank 4 Tensor expressions. */
2 
3 #pragma once
4 
7 #include "Tensor4_or_Tensor4.hpp"
13 
14 #include "../permute.hpp"
15 
17 
18 namespace FTensor
19 {
20  template <class A, class T, int Dim0, int Dim1, int Dim2, int Dim3, char i,
21  char j, char k, char l>
23  {
24  A iter;
25 
26  public:
27  Tensor4_Expr(const A &a) : iter(a) {}
28  T operator()(const int N1, const int N2, const int N3, const int N4) const
29  {
30  return iter(N1, N2, N3, N4);
31  }
32  };
33 
34  template <class A, class T, int Dim0, int Dim1, int Dim2, int Dim3, char i,
35  char j, char k, char l>
36  class Tensor4_Expr<Tensor4<A, Dim0, Dim1, Dim2, Dim3>, T, Dim0, Dim1, Dim2,
37  Dim3, i, j, k, l>
38  {
40 
41  public:
43  T &operator()(const int N1, const int N2, const int N3, const int N4)
44  {
45  return iter(N1, N2, N3, N4);
46  }
47  T operator()(const int N1, const int N2, const int N3, const int N4) const
48  {
49  return iter(N1, N2, N3, N4);
50  }
51 
52  /* Various assignment operators. I have to explicitly declare the
53  second operator= because otherwise the compiler will generate its
54  own and not use the template code. */
55 
56  template <class B, class U, int Dim1_0, int Dim1_1, int Dim1_2, int Dim1_3,
57  char i_1, char j_1, char k_1, char l_1>
58  auto &equals(const Tensor4_Expr<B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3, i_1,
59  j_1, k_1, l_1> &rhs)
60  {
61  for(int ii = 0; ii < Dim0; ++ii)
62  for(int jj = 0; jj < Dim1; ++jj)
63  for(int kk = 0; kk < Dim2; ++kk)
64  for(int ll = 0; ll < Dim3; ++ll)
65  {
66  iter(ii, jj, kk, ll) = permute(*this, rhs, ii, jj, kk, ll);
67  }
68  return *this;
69  }
70 
71  template <class B, class U, int Dim1_0, int Dim1_1, int Dim1_2, int Dim1_3,
72  char i_1, char j_1, char k_1, char l_1>
73  auto &operator=(const Tensor4_Expr<B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3,
74  i_1, j_1, k_1, l_1> &rhs)
75  {
76  return equals(rhs);
77  }
78 
79  auto &
81  Dim1, Dim2, Dim3, i, j, k, l> &rhs)
82  {
83  return equals(rhs);
84  }
85 
86  template <class B, class U, int Dim01, int Dim23, char i_1, char j_1,
87  char k_1, char l_1>
88  auto &
90  for(int ii = 0; ii != Dim01; ++ii)
91  for(int jj = 0; jj != Dim01; ++jj)
92  for(int kk = 0; kk != Dim23; ++kk)
93  for (int ll = 0; ll != Dim23; ++ll) {
94  iter(ii, jj, kk, ll) = rhs(ii, jj, kk, ll);
95  }
96  return *this;
97  }
98 
99  template <class B, class U, int Dim01, int Dim23, char i_1, char j_1,
100  char k_1, char l_1>
101  auto &
103  return equals(rhs);
104  }
105 
106  template <class B, class U, int Dim1_0, int Dim1_1, int Dim1_2, int Dim1_3,
107  char i_1, char j_1, char k_1, char l_1>
108  auto &operator+=(const Tensor4_Expr<B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3,
109  i_1, j_1, k_1, l_1> &rhs)
110  {
111  for(int ii = 0; ii < Dim0; ++ii)
112  for(int jj = 0; jj < Dim1; ++jj)
113  for(int kk = 0; kk < Dim2; ++kk)
114  for(int ll = 0; ll < Dim3; ++ll)
115  {
116  iter(ii, jj, kk, ll) += permute(*this, rhs, ii, jj, kk, ll);
117  }
118  return *this;
119  }
120 
121  template <class B, class U, int Dim1_0, int Dim1_1, int Dim1_2, int Dim1_3,
122  char i_1, char j_1, char k_1, char l_1>
123  auto &operator-=(const Tensor4_Expr<B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3,
124  i_1, j_1, k_1, l_1> &rhs)
125  {
126  for(int ii = 0; ii < Dim0; ++ii)
127  for(int jj = 0; jj < Dim1; ++jj)
128  for(int kk = 0; kk < Dim2; ++kk)
129  for(int ll = 0; ll < Dim3; ++ll)
130  {
131  iter(ii, jj, kk, ll) += permute(*this, rhs, ii, jj, kk, ll);
132  }
133  return *this;
134  }
135 
136  template <class B, class U, int Dim01, int Dim23, char i_1, char j_1,
137  char k_1, char l_1>
138  auto &
140  for (int ii = 0; ii != Dim01; ++ii)
141  for (int jj = 0; jj != Dim01; ++jj)
142  for (int kk = 0; kk != Dim23; ++kk)
143  for (int ll = 0; ll != Dim23; ++ll) {
144  iter(ii, jj, kk, ll) += rhs(ii, jj, kk, ll);
145  }
146  return *this;
147  }
148 
149  template <class B, class U, int Dim01, int Dim23, char i_1, char j_1,
150  char k_1, char l_1>
151  auto &
153  for (int ii = 0; ii != Dim01; ++ii)
154  for (int jj = 0; jj != Dim01; ++jj)
155  for (int kk = 0; kk != Dim23; ++kk)
156  for (int ll = 0; ll != Dim23; ++ll) {
157  iter(ii, jj, kk, ll) -= rhs(ii, jj, kk, ll);
158  }
159  return *this;
160  }
161 
162  template <class U> auto &operator=(const U &d) {
163  for (int ii = 0; ii != Dim0; ++ii)
164  for (int jj = 0; jj != Dim1; ++jj)
165  for (int kk = 0; kk != Dim2; ++kk)
166  for (int ll = 0; ll != Dim3; ++ll)
167  iter(ii, jj, kk, ll) = d;
168  return *this;
169  }
170 
171  template <class U> auto &operator*=(const U &d) {
172  for (int ii = 0; ii != Dim0; ++ii)
173  for (int jj = 0; jj != Dim1; ++jj)
174  for (int kk = 0; kk != Dim2; ++kk)
175  for (int ll = 0; ll != Dim3; ++ll)
176  iter(ii, jj, kk, ll) *= d;
177  return *this;
178  }
179 
180  template <class U> auto &operator/=(const U &d) {
181  for (int ii = 0; ii != Dim0; ++ii)
182  for (int jj = 0; jj != Dim1; ++jj)
183  for (int kk = 0; kk != Dim2; ++kk)
184  for (int ll = 0; ll != Dim3; ++ll)
185  iter(ii, jj, kk, ll) /= d;
186  return *this;
187  }
188 
189  };
190 }
static Number< 2 > N2
static Number< 1 > N1
auto & operator+=(const Tensor4_Expr< B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3, i_1, j_1, k_1, l_1 > &rhs)
auto & operator-=(const Tensor4_Expr< B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3, i_1, j_1, k_1, l_1 > &rhs)
auto & operator=(const Tensor4_Expr< B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3, i_1, j_1, k_1, l_1 > &rhs)
auto & equals(const Ddg_Expr< B, U, Dim01, Dim23, i_1, j_1, k_1, l_1 > &rhs)
auto & operator-=(const Ddg_Expr< B, U, Dim01, Dim23, i_1, j_1, k_1, l_1 > &rhs)
auto & operator+=(const Ddg_Expr< B, U, Dim01, Dim23, i_1, j_1, k_1, l_1 > &rhs)
auto & operator=(const Ddg_Expr< B, U, Dim01, Dim23, i_1, j_1, k_1, l_1 > &rhs)
auto & operator=(const Tensor4_Expr< Tensor4< A, Dim0, Dim1, Dim2, Dim3 >, T, Dim0, Dim1, Dim2, Dim3, i, j, k, l > &rhs)
auto & equals(const Tensor4_Expr< B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3, i_1, j_1, k_1, l_1 > &rhs)
Tensor4_Expr(const A &a)
T operator()(const int N1, const int N2, const int N3, const int N4) const
FTensor::Index< 'l', 3 > l
FTensor::Index< 'j', 3 > j
FTensor::Index< 'i', 3 > i
FTensor::Index< 'k', 3 > k
const double T
JSON compatible output.
U permute(const Tensor2_Expr< A, T, Dim0_0, Dim0_1, i0, j0 > &, const Tensor2_Expr< B, U, Dim1_0, Dim1_1, i1, j1 > &rhs, const int N0, const int N1)
Definition: permute.hpp:11
const Tensor1_Expr< const dTensor0< T, Dim, i >, typename promote< T, double >::V, Dim, i > d(const Tensor0< T * > &a, const Index< i, Dim > index, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
Definition: dTensor0.hpp:27