Sacado Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_Fad_ViewFad_tmpl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Sacado Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25 // (etphipp@sandia.gov).
26 //
27 // ***********************************************************************
28 // @HEADER
29 
30 #include "Sacado_mpl_apply.hpp"
31 #include "Sacado_mpl_if.hpp"
32 #include "Sacado_mpl_type_wrap.hpp"
33 
34 namespace Sacado {
35 
36  namespace FAD_NS {
37 
48  template <typename ValueT, unsigned length, unsigned stride,
49  typename BaseFadT>
50  class ViewFad :
51  public Expr< GeneralFad<ValueT,Fad::ViewStorage<ValueT,length,stride,BaseFadT> > > {
52 
53  public:
54 
57  typedef GeneralFad<ValueT,StorageType> GeneralFadType;
58  typedef Expr<GeneralFadType> ExprType;
59 
61  typedef typename ExprType::value_type value_type;
62 
64  typedef typename ExprType::scalar_type scalar_type;
65 
68 
70  typedef BaseFadT base_fad_type;
71 
73  template <typename T>
74  struct apply {
75  // BaseExprType<T>::type is T if T is not a view
79  };
80 
85 
86  // ViewFad cannot be created with the usual constructors, so we remove
87  // them here.
88 
91  ViewFad(const StorageType& s) :
92  ExprType(s) {}
93 
96  ViewFad(ValueT* v, const int arg_size = 0, const int arg_stride = 0) :
97  ExprType( StorageType(v,arg_size,arg_stride) ) {}
98 
100 
103  ~ViewFad() {}
104 
106  template <typename S>
108  SACADO_ENABLE_VALUE_FUNC(ViewFad&) operator=(const S& v) {
109  GeneralFadType::operator=(v);
110  return *this;
111  }
112 
115  ViewFad& operator=(const ViewFad& x) {
116  GeneralFadType::operator=(static_cast<const GeneralFadType&>(x));
117  return *this;
118  }
119 
121  template <typename S>
123  SACADO_ENABLE_EXPR_FUNC(ViewFad&) operator=(const Expr<S>& x)
124  {
125  GeneralFadType::operator=(x);
126  return *this;
127  }
128 
130 
135 
137  template <typename S>
139  SACADO_ENABLE_VALUE_FUNC(ViewFad&) operator += (const S& x) {
140  GeneralFadType::operator+=(x);
141  return *this;
142  }
143 
145  template <typename S>
147  SACADO_ENABLE_VALUE_FUNC(ViewFad&) operator -= (const S& x) {
148  GeneralFadType::operator-=(x);
149  return *this;
150  }
151 
153  template <typename S>
155  SACADO_ENABLE_VALUE_FUNC(ViewFad&) operator *= (const S& x) {
156  GeneralFadType::operator*=(x);
157  return *this;
158  }
159 
161  template <typename S>
163  SACADO_ENABLE_VALUE_FUNC(ViewFad&) operator /= (const S& x) {
164  GeneralFadType::operator/=(x);
165  return *this;
166  }
167 
170  ViewFad& operator += (const ViewFad& x) {
171  GeneralFadType::operator+=(static_cast<const GeneralFadType&>(x));
172  return *this;
173  }
174 
177  ViewFad& operator -= (const ViewFad& x) {
178  GeneralFadType::operator-=(static_cast<const GeneralFadType&>(x));
179  return *this;
180  }
181 
184  ViewFad& operator *= (const ViewFad& x) {
185  GeneralFadType::operator*=(static_cast<const GeneralFadType&>(x));
186  return *this;
187  }
188 
191  ViewFad& operator /= (const ViewFad& x) {
192  GeneralFadType::operator/=(static_cast<const GeneralFadType&>(x));
193  return *this;
194  }
195 
197  template <typename S>
199  SACADO_ENABLE_EXPR_FUNC(ViewFad&) operator += (const Expr<S>& x) {
200  GeneralFadType::operator+=(x);
201  return *this;
202  }
203 
205  template <typename S>
207  SACADO_ENABLE_EXPR_FUNC(ViewFad&) operator -= (const Expr<S>& x) {
208  GeneralFadType::operator-=(x);
209  return *this;
210  }
211 
213  template <typename S>
215  SACADO_ENABLE_EXPR_FUNC(ViewFad&) operator *= (const Expr<S>& x) {
216  GeneralFadType::operator*=(x);
217  return *this;
218  }
219 
221  template <typename S>
223  SACADO_ENABLE_EXPR_FUNC(ViewFad&) operator /= (const Expr<S>& x) {
224  GeneralFadType::operator/=(x);
225  return *this;
226  }
227 
229 
230  }; // class ViewFad<ValueT>
231 
232  template <typename T, unsigned l, unsigned s, typename U>
233  struct BaseExpr< GeneralFad<T,Fad::ViewStorage<T,l,s,U> > > {
234  //typedef ViewFad<T,l,s,U> type;
235  typedef U type;
236  };
237 
238  template <typename T, unsigned l, unsigned s, typename U>
239  struct ExprLevel< ViewFad<T,l,s,U> > {
240  static const unsigned value =
241  ExprLevel< typename ViewFad<T,l,s,U>::value_type >::value + 1;
242  };
243 
244  template <typename T, unsigned l, unsigned s, typename U>
245  struct IsFadExpr< ViewFad<T,l,s,U> > {
246  static const bool value = true;
247  };
248 
249  } // namespace Fad
250 
251  template <typename T, unsigned l, unsigned s, typename U>
252  struct IsView< Sacado::FAD_NS::ViewFad<T,l,s,U> > {
253  static const bool value = true;
254  };
255 
256  template <typename T, unsigned l, unsigned s, typename U>
257  struct IsFad< FAD_NS::ViewFad<T,l,s,U> > {
258  static const bool value = true;
259  };
260 
261  template <typename T, unsigned l, unsigned s, typename U>
262  struct IsExpr< FAD_NS::ViewFad<T,l,s,U> > {
263  static const bool value = true;
264  };
265 
266  template <typename T, unsigned l, unsigned s, typename U>
267  struct BaseExprType< FAD_NS::ViewFad<T,l,s,U> > {
269  };
270 
271 } // namespace Sacado
ViewFad< T, length, stride, new_base_fad_type > type
Fad::ViewStorage< ValueT, length, stride, BaseFadT > StorageType
Base classes.
Base template specification for whether a type is a Fad type.
KOKKOS_INLINE_FUNCTION ViewFad(ValueT *v, const int arg_size=0, const int arg_stride=0)
View-specific constructor.
ExprType::value_type value_type
Typename of values.
Forward-mode AD class using dynamic memory allocation and expression templates.
static const bool value
KOKKOS_INLINE_FUNCTION ~ViewFad()
Destructor.
Is a type an expression.
lambda< F >::type ::template apply< A1, A2, A3, A4, A5 >::type type
#define KOKKOS_INLINE_FUNCTION
#define T
Definition: Sacado_rad.hpp:573
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
Determine whether a given type is a view.
Get the base Fad type from a view/expression.
KOKKOS_INLINE_FUNCTION ViewFad(const StorageType &s)
Constructor with supplied storage s.
#define SACADO_ENABLE_EXPR_FUNC(RETURN_TYPE)
FAD_NS::ViewFad< T, l, s, U >::base_expr_type type
GeneralFad< ValueT, StorageType > GeneralFadType
static const bool value
Turn ViewFad into a meta-function class usable with mpl::apply.
ExprType::scalar_type scalar_type
Typename of scalar&#39;s (which may be different from value_type)
ScalarType< ValueT >::type ScalarT
Typename of scalar&#39;s (which may be different from ValueT)
mpl::apply< base_fad_type, T_for_base >::type new_base_fad_type
Derivative array storage class that is a view into a contiguous memory allocation. It does not provide proper value semantics and thus should not be used in a general-purpose scalar type.
BaseFadT base_fad_type
Fad type view is based on.
static const bool value
#define FAD_NS
Expr< GeneralFadType > ExprType