00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef SACADO_TAY_CACHETAYLOR_HPP
00033 #define SACADO_TAY_CACHETAYLOR_HPP
00034
00035 #include <valarray>
00036
00037 #include "Sacado_Tay_CacheTaylorExpr.hpp"
00038
00039
00040 namespace Sacado {
00041 namespace Tay {
00042 template <class ExprT> class UnaryPlusOp;
00043 template <class ExprT> class UnaryMinusOp;
00044 }
00045 }
00046
00047 namespace Sacado {
00048
00049 namespace Tay {
00050
00052
00057 template <typename T>
00058 class CacheTaylorImplementation {
00059
00060 public:
00061
00063 typedef T value_type;
00064
00066 CacheTaylorImplementation() : coeff_(T(0.),1) {}
00067
00069
00072 CacheTaylorImplementation(const T& x) : coeff_(x,1) {}
00073
00075
00078 CacheTaylorImplementation(unsigned int d, const T & x) :
00079 coeff_(T(0.),d+1) {
00080 coeff_[0] = x;
00081 }
00082
00084 CacheTaylorImplementation(const CacheTaylorImplementation& x) :
00085 coeff_(x.coeff_) {}
00086
00088 ~CacheTaylorImplementation() {}
00089
00094
00096 const T& val() const { return coeff_[0];}
00097
00099 T& val() { return coeff_[0];}
00100
00102
00107
00109 unsigned int degree() const { return coeff_.size()-1;}
00110
00112 bool hasFastAccess(unsigned int d) const { return coeff_.size()>=d+1;}
00113
00115 const std::valarray<T>& coeff() const { return coeff_;}
00116
00118 const T coeff(unsigned int i) const {
00119 T tmp= i<coeff_.size() ? coeff_[i]:T(0.); return tmp;}
00120
00122 T coeff(unsigned int i) {
00123 T tmp= i<coeff_.size() ? coeff_[i]:T(0.); return tmp;}
00124
00126 T& fastAccessCoeff(unsigned int i) { return coeff_[i];}
00127
00129 T fastAccessCoeff(unsigned int i) const { return coeff_[i];}
00130
00132 void allocateCache(unsigned int d) const {}
00133
00135
00136 protected:
00137
00139 void resizeCoeffs(unsigned int dnew) {
00140 std::valarray<T> tmp = coeff_;
00141 std::slice s(0,coeff_.size(),1);
00142 coeff_.resize(dnew+1,T(0.));
00143 coeff_[s] = tmp;
00144 }
00145
00146 protected:
00147
00149 std::valarray<T> coeff_;
00150
00151 };
00152
00154
00157 template <typename T>
00158 class Expr< CacheTaylorImplementation<T> > :
00159 public CacheTaylorImplementation<T> {
00160
00161 public:
00162
00164 Expr() : CacheTaylorImplementation<T>() {}
00165
00167
00170 Expr(const T & x) : CacheTaylorImplementation<T>(x) {}
00171
00173
00176 Expr(unsigned int d, const T & x) : CacheTaylorImplementation<T>(d,x) {}
00177
00179 Expr(const Expr& x) : CacheTaylorImplementation<T>(x) {}
00180
00181 };
00182
00184
00188 template <typename T>
00189 class CacheTaylor : public Expr< CacheTaylorImplementation<T> > {
00190
00191 public:
00192
00197
00199 CacheTaylor() : Expr< CacheTaylorImplementation<T> >() {}
00200
00202
00205 CacheTaylor(const T & x) : Expr< CacheTaylorImplementation<T> >(x) {}
00206
00208
00211 CacheTaylor(unsigned int d, const T & x) :
00212 Expr< CacheTaylorImplementation<T> >(d,x) {}
00213
00215 CacheTaylor(const CacheTaylor& x) : Expr< CacheTaylorImplementation<T> >(x) {}
00216
00218 template <typename S> CacheTaylor(const Expr<S>& x);
00219
00221
00223 ~CacheTaylor() {}
00224
00229
00231 CacheTaylor<T>& operator=(const T& val);
00232
00234 CacheTaylor<T>& operator=(const CacheTaylor<T>& x);
00235
00237 template <typename S> CacheTaylor<T>& operator=(const Expr<S>& x);
00238
00240
00245
00247 inline Expr< UnaryExpr< CacheTaylor<T>, UnaryPlusOp > >
00248 operator + () const {
00249 typedef UnaryExpr< CacheTaylor<T>, UnaryPlusOp > expr_t;
00250 return Expr<expr_t>(expr_t(*this));
00251 }
00252
00254 inline Expr< UnaryExpr< CacheTaylor<T>, UnaryMinusOp > >
00255 operator - () const {
00256 typedef UnaryExpr< CacheTaylor<T>, UnaryMinusOp > expr_t;
00257 return Expr<expr_t>(expr_t(*this));
00258 }
00259
00261 CacheTaylor<T>& operator += (const T& x);
00262
00264 CacheTaylor<T>& operator -= (const T& x);
00265
00267 CacheTaylor<T>& operator *= (const T& x);
00268
00270 CacheTaylor<T>& operator /= (const T& x);
00271
00273 template <typename S> CacheTaylor<T>& operator += (const S& x);
00274
00276 template <typename S> CacheTaylor<T>& operator -= (const S& x);
00277
00279 template <typename S> CacheTaylor<T>& operator *= (const S& x);
00280
00282 template <typename S> CacheTaylor<T>& operator /= (const S& x);
00283
00285
00286 };
00287
00288 }
00289
00290 }
00291
00292 #include "Sacado_Tay_CacheTaylorTraits.hpp"
00293 #include "Sacado_Tay_CacheTaylorImp.hpp"
00294 #include "Sacado_Tay_CacheTaylorOps.hpp"
00295
00296 #endif // SACADO_TAYLOR_CACHETAYLOR_HPP