Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_Tay_CacheTaylorExpr.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef SACADO_TAY_CACHETAYLOREXPR_HPP
11 #define SACADO_TAY_CACHETAYLOREXPR_HPP
12 
13 #include "Sacado_Traits.hpp"
14 
15 namespace Sacado {
16 
17  namespace Tay {
18 
20 
24  template <typename ExprT>
25  class Expr {
26 
27  public:
28 
30  typedef typename ExprT::value_type value_type;
31 
33  typedef typename ExprT::scalar_type scalar_type;
34 
36  typedef typename ExprT::base_expr_type base_expr_type;
37 
39  explicit Expr(const ExprT& expr) : expr_(expr) {}
40 
42  void allocateCache(unsigned int d) const { expr_.allocateCache(d); }
43 
45  unsigned int degree() const {return expr_.degree();}
46 
48  bool hasFastAccess(unsigned int d) const {
49  return expr_.hasFastAccess(d);}
50 
52  value_type coeff(unsigned int i) const { return expr_.coeff(i);}
53 
55  value_type fastAccessCoeff(unsigned int i) const { return
56  expr_.fastAccessCoeff(i);}
57 
58  protected:
59 
61  Expr() {}
62 
64  ExprT expr_;
65 
66  }; // class Expr
67 
69 
72  template <typename ConstT>
73  class ConstExpr {
74 
75  public:
76 
78  typedef ConstT value_type;
79 
82 
84  typedef ConstT base_expr_type;
85 
87  ConstExpr(const ConstT& constant) : constant_(constant) {}
88 
90  void allocateCache(unsigned int d) const {}
91 
93  unsigned int degree() const { return 0; }
94 
96  bool hasFastAccess(unsigned int d) const { return 1; }
97 
98  value_type value() const { return constant_; }
99 
101  value_type coeff(unsigned int i) const {
102  return i==0 ? constant_ : value_type(0); }
103 
105  value_type fastAccessCoeff(unsigned int i) const {
106  return i==0 ? constant_ : value_type(0); }
107 
108  protected:
109 
111  ConstT constant_;
112 
113  }; // class ConstExpr
114 
116 
122  template <typename ExprT, template<typename> class Op>
123  class UnaryExpr {
124 
125  public:
126 
128  typedef typename ExprT::value_type value_type;
129 
131  typedef typename ExprT::scalar_type scalar_type;
132 
134  typedef typename ExprT::base_expr_type base_expr_type;
135 
137  UnaryExpr(const ExprT& expr) : expr_(expr), op_(expr) {}
138 
140  void allocateCache(unsigned int d) const {
141  expr_.allocateCache(d);
142  op_.allocateCache(d);
143  }
144 
146  unsigned int degree() const {return expr_.degree();}
147 
149  bool hasFastAccess(unsigned int d) const {
150  return expr_.hasFastAccess(d); }
151 
153  value_type coeff(unsigned int i) const {
154  return op_.computeCoeff(i,expr_); }
155 
157  value_type fastAccessCoeff(unsigned int i) const {
158  return op_.computeFastAccessCoeff(i,expr_);
159  }
160 
161  protected:
162 
164  ExprT expr_;
165 
167  Op<ExprT> op_;
168 
169  }; // class UnaryExpr
170 
172 
179  template <typename ExprT1, typename ExprT2,
180  template<typename,typename> class Op>
181  class BinaryExpr {
182 
183  public:
184 
186  typedef typename ExprT1::value_type value_type_1;
187  typedef typename ExprT2::value_type value_type_2;
188  typedef typename Sacado::Promote<value_type_1,
190 
192  typedef typename ExprT1::scalar_type scalar_type_1;
193  typedef typename ExprT2::scalar_type scalar_type_2;
194  typedef typename Sacado::Promote<scalar_type_1,
196 
198  typedef typename ExprT1::base_expr_type base_expr_type_1;
199  typedef typename ExprT2::base_expr_type base_expr_type_2;
200  typedef typename Sacado::Promote<base_expr_type_1,
202 
204  BinaryExpr(const ExprT1& expr1, const ExprT2& expr2) :
205  expr1_(expr1), expr2_(expr2), op_(expr1,expr2) {}
206 
208  void allocateCache(unsigned int d) const {
209  expr1_.allocateCache(d);
210  expr2_.allocateCache(d);
211  op_.allocateCache(d);
212  }
213 
215  unsigned int degree() const {
216  unsigned int d1 = expr1_.degree(), d2 = expr2_.degree();
217  return d1 > d2 ? d1 : d2;
218  }
219 
221  bool hasFastAccess(unsigned int d) const {
222  return expr1_.hasFastAccess(d) && expr2_.hasFastAccess(d);}
223 
225  value_type coeff(unsigned int i) const {
226  return op_.computeCoeff(i,expr1_,expr2_); }
227 
229  value_type fastAccessCoeff(unsigned int i) const {
230  return op_.computeFastAccessCoeff(i,expr1_,expr2_);
231  }
232 
233  protected:
234 
236  ExprT1 expr1_;
237 
239  ExprT2 expr2_;
240 
242  Op<ExprT1,ExprT2> op_;
243 
244  }; // class BinaryExpr
245 
247 
254  template <typename ExprT2, template<typename,typename> class Op>
255  class BinaryExpr<ConstExpr<typename ExprT2::value_type>, ExprT2, Op> {
256 
257  public:
258 
261 
263  typedef typename ExprT2::value_type value_type;
264  typedef typename ExprT2::scalar_type scalar_type;
265  typedef typename ExprT2::base_expr_type base_expr_type;
266 
268  BinaryExpr(const ExprT1& expr1, const ExprT2& expr2) :
269  expr1_(expr1), expr2_(expr2), op_(expr1,expr2) {}
270 
272  void allocateCache(unsigned int d) const {
273  expr2_.allocateCache(d);
274  op_.allocateCache(d);
275  }
276 
278  unsigned int degree() const {
279  return expr2_.degree();
280  }
281 
283  bool hasFastAccess(unsigned int d) const {
284  return expr2_.hasFastAccess(d);}
285 
287  value_type coeff(unsigned int i) const {
288  return op_.computeCoeff(i,expr1_,expr2_); }
289 
291  value_type fastAccessCoeff(unsigned int i) const {
292  return op_.computeFastAccessCoeff(i,expr1_,expr2_);
293  }
294 
295  protected:
296 
299 
301  ExprT2 expr2_;
302 
304  Op<ExprT1,ExprT2> op_;
305 
306  }; // class BinaryExpr
307 
309 
316  template <typename ExprT1, template<typename,typename> class Op>
317  class BinaryExpr<ExprT1,ConstExpr<typename ExprT1::value_type>, Op> {
318 
319  public:
320 
323 
325  typedef typename ExprT1::value_type value_type;
326  typedef typename ExprT1::scalar_type scalar_type;
327  typedef typename ExprT1::base_expr_type base_expr_type;
328 
330  BinaryExpr(const ExprT1& expr1, const ExprT2& expr2) :
331  expr1_(expr1), expr2_(expr2), op_(expr1,expr2) {}
332 
334  void allocateCache(unsigned int d) const {
335  expr1_.allocateCache(d);
336  op_.allocateCache(d);
337  }
338 
340  unsigned int degree() const {
341  return expr1_.degree();
342  }
343 
345  bool hasFastAccess(unsigned int d) const {
346  return expr1_.hasFastAccess(d);}
347 
349  value_type coeff(unsigned int i) const {
350  return op_.computeCoeff(i,expr1_,expr2_); }
351 
353  value_type fastAccessCoeff(unsigned int i) const {
354  return op_.computeFastAccessCoeff(i,expr1_,expr2_);
355  }
356 
357  protected:
358 
360  ExprT1 expr1_;
361 
364 
366  Op<ExprT1,ExprT2> op_;
367 
368  }; // class BinaryExpr
369 
370  } // namespace Tay
371 
372  template <typename T>
373  struct IsExpr< Tay::Expr<T> > {
374  static const bool value = true;
375  };
376 
377  template <typename T>
378  struct BaseExprType< Tay::Expr<T> > {
380  };
381 
382 } // namespace Sacado
383 
384 #endif // SACADO_TAY_CACHETAYLOREXPR_HPP
Sacado::Promote< scalar_type_1, scalar_type_2 >::type scalar_type
value_type fastAccessCoeff(unsigned int i) const
Return degree i term of expression.
Expr(const ExprT &expr)
Constructor with given expression expr.
Constant expression template.
unsigned int degree() const
Return degree of polynomial.
ExprT::scalar_type scalar_type
Typename of scalar&#39;s (which may be different from value_type)
value_type coeff(unsigned int i) const
Return degree i term of expression.
unsigned int degree() const
Return degree of polynomial.
ExprT1::value_type value_type_1
Typename of the expression values.
value_type coeff(unsigned int i) const
Return degree i term of expression.
ExprT1::base_expr_type base_expr_type_1
Typename of the base expression.
value_type fastAccessCoeff(unsigned int i) const
Return degree i term of expression.
ExprT::value_type value_type
Typename of values.
Binary expression template.
BinaryExpr(const ExprT1 &expr1, const ExprT2 &expr2)
Constructor.
value_type fastAccessCoeff(unsigned int i) const
Return degree i term of expression.
Unary expression template.
bool hasFastAccess(unsigned int d) const
Return if operation has fast access.
void allocateCache(unsigned int d) const
Allocate coefficient cache.
UnaryExpr(const ExprT &expr)
Constructor.
value_type fastAccessCoeff(unsigned int i) const
eturn degree i term of expression
static const bool value
value_type coeff(unsigned int i) const
Return degree i term of expression.
Sacado::Promote< base_expr_type_1, base_expr_type_2 >::type base_expr_type
ConstT value_type
Typename of argument values.
Is a type an expression.
void allocateCache(unsigned int d) const
Allocate coefficient cache.
bool hasFastAccess(unsigned int d) const
Return if expression has fast access.
bool hasFastAccess(unsigned int d) const
Return if operation has fast access.
Get the base Fad type from a view/expression.
ConstT base_expr_type
Typename of base-expressions.
ExprT::value_type value_type
Typename of argument value.
value_type coeff(unsigned int i) const
Return degree i term of expression.
value_type fastAccessCoeff(unsigned int i) const
Return degree i term of expression.
ExprT2::base_expr_type base_expr_type_2
unsigned int degree() const
Return degree of polynomial.
Sacado::Promote< value_type_1, value_type_2 >::type value_type
value_type coeff(unsigned int i) const
Return degree i term of expression.
ExprT::scalar_type scalar_type
Typename of scalar&#39;s (which may be different from value_type)
ConstExpr< typename ExprT2::value_type > ExprT1
Typename of constant expression.
ScalarType< value_type >::type scalar_type
Typename of scalar&#39;s (which may be different from ConstT)
bool hasFastAccess(unsigned int d) const
Return if operation has fast access.
bool hasFastAccess(unsigned int d) const
Return if operation has fast access.
void allocateCache(unsigned int d) const
Allocate coefficient cache.
ExprT::base_expr_type base_expr_type
Typename of base-expressions.
Op< ExprT1, ExprT2 > op_
Operator.
ConstExpr< typename ExprT1::value_type > ExprT2
Typename of constant expression.
unsigned int degree() const
Return degree of polynomial.
void allocateCache(unsigned int d) const
Allocate coefficient cache.
Wrapper for a generic expression template.
ExprT::base_expr_type base_expr_type
Typename of base-expressions.
Expr()
Disallow default constructor.
bool hasFastAccess(unsigned int d) const
Return if operation has fast access.
ExprT1::scalar_type scalar_type_1
Typename of the expression scalars.
value_type coeff(unsigned int i) const
Return degree i term of expression.
Base template specification for Promote.
value_type fastAccessCoeff(unsigned int i) const
Return derivative component i of operation.
ConstExpr(const ConstT &constant)
Constructor.