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 //
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 #ifndef SACADO_TAY_CACHETAYLOREXPR_HPP
31 #define SACADO_TAY_CACHETAYLOREXPR_HPP
32 
33 #include "Sacado_Traits.hpp"
34 
35 namespace Sacado {
36 
37  namespace Tay {
38 
40 
44  template <typename ExprT>
45  class Expr {
46 
47  public:
48 
50  typedef typename ExprT::value_type value_type;
51 
53  typedef typename ExprT::scalar_type scalar_type;
54 
56  typedef typename ExprT::base_expr_type base_expr_type;
57 
59  explicit Expr(const ExprT& expr) : expr_(expr) {}
60 
62  void allocateCache(unsigned int d) const { expr_.allocateCache(d); }
63 
65  unsigned int degree() const {return expr_.degree();}
66 
68  bool hasFastAccess(unsigned int d) const {
69  return expr_.hasFastAccess(d);}
70 
72  value_type coeff(unsigned int i) const { return expr_.coeff(i);}
73 
75  value_type fastAccessCoeff(unsigned int i) const { return
76  expr_.fastAccessCoeff(i);}
77 
78  protected:
79 
81  Expr() {}
82 
84  ExprT expr_;
85 
86  }; // class Expr
87 
89 
92  template <typename ConstT>
93  class ConstExpr {
94 
95  public:
96 
98  typedef ConstT value_type;
99 
102 
104  typedef ConstT base_expr_type;
105 
107  ConstExpr(const ConstT& constant) : constant_(constant) {}
108 
110  void allocateCache(unsigned int d) const {}
111 
113  unsigned int degree() const { return 0; }
114 
116  bool hasFastAccess(unsigned int d) const { return 1; }
117 
118  value_type value() const { return constant_; }
119 
121  value_type coeff(unsigned int i) const {
122  return i==0 ? constant_ : value_type(0); }
123 
125  value_type fastAccessCoeff(unsigned int i) const {
126  return i==0 ? constant_ : value_type(0); }
127 
128  protected:
129 
131  ConstT constant_;
132 
133  }; // class ConstExpr
134 
136 
142  template <typename ExprT, template<typename> class Op>
143  class UnaryExpr {
144 
145  public:
146 
148  typedef typename ExprT::value_type value_type;
149 
151  typedef typename ExprT::scalar_type scalar_type;
152 
154  typedef typename ExprT::base_expr_type base_expr_type;
155 
157  UnaryExpr(const ExprT& expr) : expr_(expr), op_(expr) {}
158 
160  void allocateCache(unsigned int d) const {
161  expr_.allocateCache(d);
162  op_.allocateCache(d);
163  }
164 
166  unsigned int degree() const {return expr_.degree();}
167 
169  bool hasFastAccess(unsigned int d) const {
170  return expr_.hasFastAccess(d); }
171 
173  value_type coeff(unsigned int i) const {
174  return op_.computeCoeff(i,expr_); }
175 
177  value_type fastAccessCoeff(unsigned int i) const {
178  return op_.computeFastAccessCoeff(i,expr_);
179  }
180 
181  protected:
182 
184  ExprT expr_;
185 
187  Op<ExprT> op_;
188 
189  }; // class UnaryExpr
190 
192 
199  template <typename ExprT1, typename ExprT2,
200  template<typename,typename> class Op>
201  class BinaryExpr {
202 
203  public:
204 
206  typedef typename ExprT1::value_type value_type_1;
207  typedef typename ExprT2::value_type value_type_2;
208  typedef typename Sacado::Promote<value_type_1,
210 
212  typedef typename ExprT1::scalar_type scalar_type_1;
213  typedef typename ExprT2::scalar_type scalar_type_2;
214  typedef typename Sacado::Promote<scalar_type_1,
216 
218  typedef typename ExprT1::base_expr_type base_expr_type_1;
219  typedef typename ExprT2::base_expr_type base_expr_type_2;
220  typedef typename Sacado::Promote<base_expr_type_1,
222 
224  BinaryExpr(const ExprT1& expr1, const ExprT2& expr2) :
225  expr1_(expr1), expr2_(expr2), op_(expr1,expr2) {}
226 
228  void allocateCache(unsigned int d) const {
229  expr1_.allocateCache(d);
230  expr2_.allocateCache(d);
231  op_.allocateCache(d);
232  }
233 
235  unsigned int degree() const {
236  unsigned int d1 = expr1_.degree(), d2 = expr2_.degree();
237  return d1 > d2 ? d1 : d2;
238  }
239 
241  bool hasFastAccess(unsigned int d) const {
242  return expr1_.hasFastAccess(d) && expr2_.hasFastAccess(d);}
243 
245  value_type coeff(unsigned int i) const {
246  return op_.computeCoeff(i,expr1_,expr2_); }
247 
249  value_type fastAccessCoeff(unsigned int i) const {
250  return op_.computeFastAccessCoeff(i,expr1_,expr2_);
251  }
252 
253  protected:
254 
256  ExprT1 expr1_;
257 
259  ExprT2 expr2_;
260 
262  Op<ExprT1,ExprT2> op_;
263 
264  }; // class BinaryExpr
265 
267 
274  template <typename ExprT2, template<typename,typename> class Op>
275  class BinaryExpr<ConstExpr<typename ExprT2::value_type>, ExprT2, Op> {
276 
277  public:
278 
281 
283  typedef typename ExprT2::value_type value_type;
284  typedef typename ExprT2::scalar_type scalar_type;
285  typedef typename ExprT2::base_expr_type base_expr_type;
286 
288  BinaryExpr(const ExprT1& expr1, const ExprT2& expr2) :
289  expr1_(expr1), expr2_(expr2), op_(expr1,expr2) {}
290 
292  void allocateCache(unsigned int d) const {
293  expr2_.allocateCache(d);
294  op_.allocateCache(d);
295  }
296 
298  unsigned int degree() const {
299  return expr2_.degree();
300  }
301 
303  bool hasFastAccess(unsigned int d) const {
304  return expr2_.hasFastAccess(d);}
305 
307  value_type coeff(unsigned int i) const {
308  return op_.computeCoeff(i,expr1_,expr2_); }
309 
311  value_type fastAccessCoeff(unsigned int i) const {
312  return op_.computeFastAccessCoeff(i,expr1_,expr2_);
313  }
314 
315  protected:
316 
319 
321  ExprT2 expr2_;
322 
324  Op<ExprT1,ExprT2> op_;
325 
326  }; // class BinaryExpr
327 
329 
336  template <typename ExprT1, template<typename,typename> class Op>
337  class BinaryExpr<ExprT1,ConstExpr<typename ExprT1::value_type>, Op> {
338 
339  public:
340 
343 
345  typedef typename ExprT1::value_type value_type;
346  typedef typename ExprT1::scalar_type scalar_type;
347  typedef typename ExprT1::base_expr_type base_expr_type;
348 
350  BinaryExpr(const ExprT1& expr1, const ExprT2& expr2) :
351  expr1_(expr1), expr2_(expr2), op_(expr1,expr2) {}
352 
354  void allocateCache(unsigned int d) const {
355  expr1_.allocateCache(d);
356  op_.allocateCache(d);
357  }
358 
360  unsigned int degree() const {
361  return expr1_.degree();
362  }
363 
365  bool hasFastAccess(unsigned int d) const {
366  return expr1_.hasFastAccess(d);}
367 
369  value_type coeff(unsigned int i) const {
370  return op_.computeCoeff(i,expr1_,expr2_); }
371 
373  value_type fastAccessCoeff(unsigned int i) const {
374  return op_.computeFastAccessCoeff(i,expr1_,expr2_);
375  }
376 
377  protected:
378 
380  ExprT1 expr1_;
381 
384 
386  Op<ExprT1,ExprT2> op_;
387 
388  }; // class BinaryExpr
389 
390  } // namespace Tay
391 
392  template <typename T>
393  struct IsExpr< Tay::Expr<T> > {
394  static const bool value = true;
395  };
396 
397  template <typename T>
398  struct BaseExprType< Tay::Expr<T> > {
400  };
401 
402 } // namespace Sacado
403 
404 #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.