v0.7.2
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 
6 #pragma once
7 
10 #include "Tensor2_or_Tensor2.hpp"
14 #include "Tensor2_and_Tensor1.hpp"
17 #include "Tensor2_transform.hpp"
18 #include "minus_Tensor2.hpp"
19 #include "conj_Tensor2.hpp"
20 
21 namespace FTensor
22 {
23  template<class A, class T, int Dim0, int Dim1, char i, char j>
25  {
26  A iter;
27  public:
28  Tensor2_Expr(A &a): iter(a) {}
29  T operator()(const int N1, const int N2) const
30  {
31  return iter(N1,N2);
32  }
33  };
34 
35  template<class A, class T, int Tensor_Dim0, int Tensor_Dim1,
36  int Dim0, int Dim1, char i, char j, Layout layout>
37  class Tensor2_Expr<Tensor2<A,Tensor_Dim0,Tensor_Dim1,layout>,T,Dim0,Dim1,i,j>
38  {
40  public:
42  T & operator()(const int N1, const int N2)
43  {
44  return iter(N1,N2);
45  }
46  T operator()(const int N1, const int N2) const
47  {
48  return iter(N1,N2);
49  }
50 
51  /* Various assignment operators. I have to explicitly declare the
52  second operator= because otherwise the compiler will generate its
53  own and not use the template code. */
54 
55  template<class B, class U>
57  T,Dim0,Dim1,i,j> &
58  operator=(const Tensor2_Expr<B,U,Dim0,Dim1,i,j> &result);
59 
61  T,Dim0,Dim1,i,j> &
63  T,Dim0,Dim1,i,j> &result);
64 
65  template<class B, class U>
67  T,Dim0,Dim1,i,j> &
68  operator+=(const Tensor2_Expr<B,U,Dim0,Dim1,i,j> &result);
69 
70  template<class B, class U>
72  T,Dim0,Dim1,i,j> &
73  operator-=(const Tensor2_Expr<B,U,Dim0,Dim1,i,j> &result);
74 
75  /* This is for when the indices are switched (i,j) -> (j,i). */
76 
77  template<class B, class U>
79  T,Dim0,Dim1,i,j> &
80  operator=(const Tensor2_Expr<B,U,Dim0,Dim1,j,i> &result);
81 
82  template<class B, class U>
84  T,Dim0,Dim1,i,j> &
85  operator+=(const Tensor2_Expr<B,U,Dim0,Dim1,j,i> &result);
86 
87  template<class B, class U>
89  T,Dim0,Dim1,i,j> &
90  operator-=(const Tensor2_Expr<B,U,Dim0,Dim1,j,i> &result);
91 
92  /* This is for int's, double's, etc. */
93 
94  template <class B>
96  T,Dim0,Dim1,i,j> &
97  operator=(const B &d);
98 
99  template <class B>
101  T,Dim0,Dim1,i,j> &
102  operator+=(const B &d);
103 
104  template <class B>
106  T,Dim0,Dim1,i,j> &
107  operator-=(const B &d);
108 
109  template <class B>
111  T,Dim0,Dim1,i,j> &
112  operator*=(const B &d);
113 
114  template <class B>
116  T,Dim0,Dim1,i,j> &
117  operator/=(const B &d);
118 
119  /** Assignments operators for ADOL-C */
120 
121  template <class B, class U>
123  j> &
124  operator<<=(const Tensor2_Expr<B, U, Dim0, Dim1, i, j> &result);
125 
126  template <class B, class U>
128  j> &
129  operator>>=(const Tensor2_Expr<B, U, Dim0, Dim1, i, j> &result);
130 
132  j> &
133  operator<<=(const Tensor2_Expr<Tensor2<A, Tensor_Dim0, Tensor_Dim1, layout>,
134  T, Dim0, Dim1, i, j> &result);
135 
137  j> &
139  T, Dim0, Dim1, i, j> &result);
140 
141  };
142 
143  /* Specialized for Dg_number_rhs_0 (Dg with the
144  first or second index explicitly given). */
145 
146  template<class A, class T, int Dim0, int Dim1, char i, char j, int N>
147  class Tensor2_Expr<Dg_number_rhs_0<A,T,N>,T,Dim0,Dim1,i,j>
148  {
149  A &iter;
150  public:
151  Tensor2_Expr(A &a): iter(a) {}
152  T & operator()(const int N1, const int N2)
153  {
154  return iter(N,N1,N2);
155  }
156  T operator()(const int N1, const int N2) const
157  {
158  return iter(N,N1,N2);
159  }
160 
161  /* Various assignment operators. I have to explicitly declare the
162  second operator= because otherwise the compiler will generate its
163  own and not use the template code. */
164 
165  template<class B, class U>
166  Tensor2_Expr<Dg_number_rhs_0<A,T,N>,T,Dim0,Dim1,i,j> &
167  operator=(const Tensor2_Expr<B,U,Dim0,Dim1,i,j> &result);
168 
169  Tensor2_Expr<Dg_number_rhs_0<A,T,N>,T,Dim0,Dim1,i,j> &
170  operator=(const Tensor2_Expr<Dg_number_rhs_0
171  <A,T,N>,T,Dim0,Dim1,i,j> &result);
172 
173  };
174 }
175 
176 #include "Tensor2_Expr_equals.hpp"
T operator()(const int N1, const int N2) const
JSON compatible output.
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:26
const int N
Definition: speed_test.cpp:3