v0.6.9
Tensor4_Expr.hpp
Go to the documentation of this file.
1 /* Declare a wrapper class for generic rank 4 Tensor expressions. */
2 
7 
8 template<class A, class T, int Dim0, int Dim1, int Dim2, int Dim3, char i, char j, char k, char l>
10 {
11  A iter;
12 public:
13  Tensor4_Expr(A &a): iter(a) {}
14  T operator()(const int N1, const int N2, const int N3, const int N4) const
15  {
16  return iter(N1,N2,N3,N4);
17  }
18 };
19 
20 template<class A, class T, int Dim0, int Dim1, int Dim2, int Dim3,
21  char i, char j, char k, char l>
22 class Tensor4_Expr<Tensor4<A,Dim0,Dim1,Dim2,Dim3>,T,Dim0,Dim1,Dim2,Dim3,i,j,k,l>
23 {
25 public:
27  T & operator()(const int N1, const int N2, const int N3, const int N4)
28  {
29  return iter(N1,N2,N3,N4);
30  }
31  T operator()(const int N1, const int N2, const int N3, const int N4) const
32  {
33  return iter(N1,N2,N3,N4);
34  }
35 
36  /* Various assignment operators. I have to explicitly declare the
37  second operator= because otherwise the compiler will generate its
38  own and not use the template code. */
39 
40  template<class B, class U>
41  const Tensor4_Expr<Tensor4<A,Dim0,Dim1,Dim2,Dim3>,T,Dim0,Dim1,Dim2,Dim3,i,j,k,l> &
42  operator=(const Tensor4_Expr<B,U,Dim0,Dim1,Dim2,Dim3,i,j,k,l> &result);
43 
44  const Tensor4_Expr<Tensor4<A,Dim0,Dim1,Dim2,Dim3>,T,Dim0,Dim1,Dim2,Dim3,i,j,k,l> &
45  operator=(const Tensor4_Expr<Tensor4<A,Dim0,Dim1,Dim2,Dim3>,T,Dim0,Dim1,Dim2,Dim3,i,j,k,l> &result);
46 
47  /* 24 permutations of assignment for tensor4 */
48 
49  #define EQUAL(D0,D1,D2,D3,I,J,K,L) \
50  template<class B, class U> inline \
51  const Tensor4_Expr<Tensor4<A,Dim0,Dim1,Dim2,Dim3>,T, \
52  Dim0,Dim1,Dim2,Dim3,i,j,k,l> & \
53  operator=(const Tensor4_Expr<B,U,D0,D1,D2,D3,I,J,K,L> &result);
54 
55  // ij jk kl
56  // ik jl lk
57  // il kj
58  // ji lj
59  // ki
60  // li
61  //
62  // ijik ijlk ikjl iklj iljk ilkj jikl jilk kijl kilj lijk likj (12)
63  // jkil jkli jlik jlki kjil kjli ljik ljki (8)
64  // klij klji lkij lkji
65 
66  EQUAL(Dim1,Dim0,Dim2,Dim3,j,i,k,l); // jikl
67  EQUAL(Dim1,Dim2,Dim0,Dim3,j,k,i,l); // jkil
68  EQUAL(Dim1,Dim2,Dim3,Dim0,j,k,l,i); // jkli
69  EQUAL(Dim2,Dim1,Dim3,Dim0,k,j,l,i); // kjli
70  EQUAL(Dim2,Dim3,Dim1,Dim0,k,l,j,i); // klji
71  EQUAL(Dim2,Dim3,Dim0,Dim1,k,l,i,j); // klij
72  EQUAL(Dim3,Dim2,Dim0,Dim1,l,k,i,j); // lkij
73  EQUAL(Dim3,Dim0,Dim2,Dim1,l,i,k,j); // likj
74  EQUAL(Dim3,Dim0,Dim1,Dim2,l,i,j,k); // lijk
75  EQUAL(Dim0,Dim3,Dim1,Dim2,i,l,j,k); // iljk
76  EQUAL(Dim0,Dim1,Dim3,Dim2,i,j,l,k); // ijlk
77  EQUAL(Dim3,Dim2,Dim1,Dim0,l,k,j,i); // lkji
78  EQUAL(Dim0,Dim2,Dim1,Dim3,i,k,j,l); // ikjl
79  EQUAL(Dim0,Dim2,Dim3,Dim1,i,k,l,j); // iklj
80  EQUAL(Dim0,Dim3,Dim2,Dim1,i,l,k,j); // ilkj
81  EQUAL(Dim1,Dim0,Dim3,Dim2,j,i,l,k); // jilk
82  EQUAL(Dim2,Dim0,Dim1,Dim3,k,i,j,l); // kijl
83  EQUAL(Dim2,Dim0,Dim3,Dim1,k,i,l,j); // kilj
84  EQUAL(Dim1,Dim3,Dim0,Dim2,j,l,i,k); // jlik
85  EQUAL(Dim1,Dim3,Dim2,Dim0,j,l,k,i); // jlki
86  EQUAL(Dim2,Dim1,Dim0,Dim3,k,j,i,l); // kjil
87  EQUAL(Dim3,Dim1,Dim0,Dim2,l,j,i,k); // ljik
88  EQUAL(Dim3,Dim1,Dim2,Dim0,l,j,k,i); // ljki
89 
90  #undef EQUAL
91 
92  /* This is for int's, double's, etc. */
93 
94  template <class U> inline
95  const Tensor4_Expr<Tensor4<A,Dim0,Dim1,Dim2,Dim3>,T,Dim0,Dim1,Dim2,Dim3,i,j,k,l> &
96  operator=(const U &d);
97 
98  template <class U> inline
99  const Tensor4_Expr<Tensor4<A,Dim0,Dim1,Dim2,Dim3>,T,Dim0,Dim1,Dim2,Dim3,i,j,k,l> &
100  operator*=(const U &d);
101 
102 
103 };
104 
105 #include "Tensor4_Expr_equals.hpp"
T operator()(const int N1, const int N2, const int N3, const int N4) const
Tensor4_Expr(A &a)
T operator()(const int N1, const int N2, const int N3, const int N4) const
#define EQUAL(D0, D1, D2, D3, I, J, K, L)
Definition: FTensor.hpp:49
T & operator()(const int N1, const int N2, const int N3, const int N4)
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:22