v0.8.4
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 
11 
12 #include "../permute.hpp"
13 
15 
16 namespace FTensor
17 {
18  template <class A, class T, int Dim0, int Dim1, int Dim2, int Dim3, char i,
19  char j, char k, char l>
21  {
22  A iter;
23 
24  public:
25  Tensor4_Expr(const A &a) : iter(a) {}
26  T operator()(const int N1, const int N2, const int N3, const int N4) const
27  {
28  return iter(N1, N2, N3, N4);
29  }
30  };
31 
32  template <class A, class T, int Dim0, int Dim1, int Dim2, int Dim3, char i,
33  char j, char k, char l>
34  class Tensor4_Expr<Tensor4<A, Dim0, Dim1, Dim2, Dim3>, T, Dim0, Dim1, Dim2,
35  Dim3, i, j, k, l>
36  {
38 
39  public:
41  T &operator()(const int N1, const int N2, const int N3, const int N4)
42  {
43  return iter(N1, N2, N3, N4);
44  }
45  T operator()(const int N1, const int N2, const int N3, const int N4) const
46  {
47  return iter(N1, N2, N3, N4);
48  }
49 
50  /* Various assignment operators. I have to explicitly declare the
51  second operator= because otherwise the compiler will generate its
52  own and not use the template code. */
53 
54  template <class B, class U, int Dim1_0, int Dim1_1, int Dim1_2, int Dim1_3,
55  char i_1, char j_1, char k_1, char l_1>
56  auto &equals(const Tensor4_Expr<B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3, i_1,
57  j_1, k_1, l_1> &rhs)
58  {
59  for(int ii = 0; ii < Dim0; ++ii)
60  for(int jj = 0; jj < Dim1; ++jj)
61  for(int kk = 0; kk < Dim2; ++kk)
62  for(int ll = 0; ll < Dim3; ++ll)
63  {
64  iter(ii, jj, kk, ll) = permute(*this, rhs, ii, jj, kk, ll);
65  }
66  return *this;
67  }
68 
69  template <class B, class U, int Dim1_0, int Dim1_1, int Dim1_2, int Dim1_3,
70  char i_1, char j_1, char k_1, char l_1>
71  auto &operator=(const Tensor4_Expr<B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3,
72  i_1, j_1, k_1, l_1> &rhs)
73  {
74  return equals(rhs);
75  }
76 
77  auto &
79  Dim1, Dim2, Dim3, i, j, k, l> &rhs)
80  {
81  return equals(rhs);
82  }
83 
84  template <class B, class U, int Dim1_0, int Dim1_1, int Dim1_2, int Dim1_3,
85  char i_1, char j_1, char k_1, char l_1>
86  auto &operator+=(const Tensor4_Expr<B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3,
87  i_1, j_1, k_1, l_1> &rhs)
88  {
89  for(int ii = 0; ii < Dim0; ++ii)
90  for(int jj = 0; jj < Dim1; ++jj)
91  for(int kk = 0; kk < Dim2; ++kk)
92  for(int ll = 0; ll < Dim3; ++ll)
93  {
94  iter(ii, jj, kk, ll) += permute(*this, rhs, ii, jj, kk, ll);
95  }
96  return *this;
97  }
98 
99  template <class B, class U, int Dim1_0, int Dim1_1, int Dim1_2, int Dim1_3,
100  char i_1, char j_1, char k_1, char l_1>
101  auto &operator-=(const Tensor4_Expr<B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3,
102  i_1, j_1, k_1, l_1> &rhs)
103  {
104  for(int ii = 0; ii < Dim0; ++ii)
105  for(int jj = 0; jj < Dim1; ++jj)
106  for(int kk = 0; kk < Dim2; ++kk)
107  for(int ll = 0; ll < Dim3; ++ll)
108  {
109  iter(ii, jj, kk, ll) += permute(*this, rhs, ii, jj, kk, ll);
110  }
111  return *this;
112  }
113  };
114 }
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)
auto & operator=(const Tensor4_Expr< B, U, Dim1_0, Dim1_1, Dim1_2, Dim1_3, i_1, j_1, k_1, l_1 > &rhs)
Fully Antisymmetric Levi-Civita Tensor.
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
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< Tensor4< A, Dim0, Dim1, Dim2, Dim3 >, T, Dim0, Dim1, Dim2, Dim3, i, j, k, l > &rhs)
T operator()(const int N1, const int N2, const int N3, const int N4) const