v0.6.10
Tensor2_Expr.hpp
Go to the documentation of this file.
1 /* Declares a wrapper class for rank 2 Tensor expressions. I
2  specialize it for when I wrap a simple Tensor2 or Tensor2_ptr so
3  that it has a reference to the Tensor2(_ptr) and not a copy.
4  Otherwise assignment wouldn't work. */
5 
8 #include "Tensor2_or_Tensor2.hpp"
12 #include "Tensor2_and_Tensor1.hpp"
15 #include "Tensor2_transform.hpp"
16 #include "minus_Tensor2.hpp"
17 #include "conj_Tensor2.hpp"
18 
19 template<class A, class T, int Dim0, int Dim1, char i, char j>
21 {
22  A iter;
23 public:
24  Tensor2_Expr(A &a): iter(a) {}
25  T operator()(const int N1, const int N2) const
26  {
27  return iter(N1,N2);
28  }
29 };
30 
31 template<class A, class T, int Dim0, int Dim1, char i, char j, Layout layout>
32 class Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j>
33 {
35 public:
37  T & operator()(const int N1, const int N2)
38  {
39  return iter(N1,N2);
40  }
41  T operator()(const int N1, const int N2) const
42  {
43  return iter(N1,N2);
44  }
45 
46  /* Various assignment operators. I have to explicitly declare the
47  second operator= because otherwise the compiler will generate its
48  own and not use the template code. */
49 
50  template<class B, class U>
51  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
52  operator=(const Tensor2_Expr<B,U,Dim0,Dim1,i,j> &result);
53 
54  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
55  operator=(const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &result);
56 
57  template<class B, class U>
58  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
59  operator+=(const Tensor2_Expr<B,U,Dim0,Dim1,i,j> &result);
60 
61  template<class B, class U>
62  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
63  operator-=(const Tensor2_Expr<B,U,Dim0,Dim1,i,j> &result);
64 
65  /* This is for when the indices are switched (i,j) -> (j,i). */
66 
67  template<class B, class U>
68  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
69  operator=(const Tensor2_Expr<B,U,Dim0,Dim1,j,i> &result);
70 
71  template<class B, class U>
72  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
73  operator+=(const Tensor2_Expr<B,U,Dim0,Dim1,j,i> &result);
74 
75  template<class B, class U>
76  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
77  operator-=(const Tensor2_Expr<B,U,Dim0,Dim1,j,i> &result);
78 
79  /* This is for int's, double's, etc. */
80 
81  template <class B>
82  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
83  operator=(const B &d);
84 
85  template <class B>
86  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
87  operator+=(const B &d);
88 
89  template <class B>
90  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
91  operator-=(const B &d);
92 
93  template <class B>
94  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
95  operator*=(const B &d);
96 
97  template <class B>
98  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
99  operator/=(const B &d);
100 
101  /** Assignments operators for ADOL-C
102  */
103 
104  template<class B, class U>
105  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
106  operator<<=(const Tensor2_Expr<B,U,Dim0,Dim1,i,j> &result);
107 
108  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
109  operator<<=(const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &result);
110 
111  template<class B, class U>
112  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
113  operator<<=(const Tensor2_Expr<B,U,Dim0,Dim1,j,i> &result);
114 
115  template <class B>
116  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
117  operator<<=(const B &d);
118 
119  template<class B, class U>
120  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
121  operator>>=(const Tensor2_Expr<B,U,Dim0,Dim1,i,j> &result);
122 
123  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
124  operator>>=(const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &result);
125 
126  template<class B, class U>
127  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
128  operator>>=(const Tensor2_Expr<B,U,Dim0,Dim1,j,i> &result);
129 
130  template <class B>
131  const Tensor2_Expr<Tensor2<A,Dim0,Dim1,layout>,T,Dim0,Dim1,i,j> &
132  operator>>=(const B &d);
133 
134 };
135 
136 /* Specialized for Tensor3_dg_number_rhs_0 (Tensor3_dg with the
137  first or second index explicitly given). */
138 
139 template<class A, class T, int Dim0, int Dim1, char i, char j, int N>
140 class Tensor2_Expr<Tensor3_dg_number_rhs_0<A,T,N>,T,Dim0,Dim1,i,j>
141 {
142  A &iter;
143 public:
144  Tensor2_Expr(A &a): iter(a) {}
145  T & operator()(const int N1, const int N2)
146  {
147  return iter(N,N1,N2);
148  }
149  T operator()(const int N1, const int N2) const
150  {
151  return iter(N,N1,N2);
152  }
153 
154  /* Various assignment operators. I have to explicitly declare the
155  second operator= because otherwise the compiler will generate its
156  own and not use the template code. */
157 
158  template<class B, class U>
159  const Tensor2_Expr<Tensor3_dg_number_rhs_0<A,T,N>,T,Dim0,Dim1,i,j> &
160  operator=(const Tensor2_Expr<B,U,Dim0,Dim1,i,j> &result);
161 
162  const Tensor2_Expr<Tensor3_dg_number_rhs_0<A,T,N>,T,Dim0,Dim1,i,j> &
163  operator=(const Tensor2_Expr<Tensor3_dg_number_rhs_0
164  <A,T,N>,T,Dim0,Dim1,i,j> &result);
165 
166 };
167 
168 #include "Tensor2_Expr_equals.hpp"
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
const int N
Definition: speed_test.cpp:3
T operator()(const int N1, const int N2) const
Tensor2_Expr(A &a)