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 template <typename T>
00033 template <typename S>
00034 inline Sacado::Tay::CacheTaylor<T>::CacheTaylor(const Expr<S>& x) :
00035 Expr< CacheTaylorImplementation<T> >(x.degree(), T(0.))
00036 {
00037 unsigned int d = this->degree();
00038
00039 x.allocateCache(d);
00040
00041
00042
00043
00044 if (x.hasFastAccess(d))
00045 for(int i=d; i>=0; --i)
00046 this->coeff_[i] = x.fastAccessCoeff(i);
00047 else
00048 for(int i=d; i>=0; --i)
00049 this->coeff_[i] = x.coeff(i);
00050
00051 }
00052
00053 template <typename T>
00054 inline Sacado::Tay::CacheTaylor<T>&
00055 Sacado::Tay::CacheTaylor<T>::operator=(const T& val)
00056 {
00057 this->coeff_[0] = val;
00058
00059 for (unsigned int i=1; i<this->coeff_.size(); i++)
00060 this->coeff_[i] = T(0.);
00061
00062 return *this;
00063 }
00064
00065 template <typename T>
00066 inline Sacado::Tay::CacheTaylor<T>&
00067 Sacado::Tay::CacheTaylor<T>::operator=(const Sacado::Tay::CacheTaylor<T>& x)
00068 {
00069 if (x.coeff_.size() != this->coeff_.size())
00070 this->coeff_.resize(x.coeff_.size());
00071 this->coeff_ = x.coeff_;
00072
00073 return *this;
00074 }
00075
00076 template <typename T>
00077 template <typename S>
00078 inline Sacado::Tay::CacheTaylor<T>&
00079 Sacado::Tay::CacheTaylor<T>::operator=(const Expr<S>& x)
00080 {
00081 unsigned int d = this->degree();
00082 unsigned int xd = x.degree();
00083
00084
00085 if (xd > d) {
00086 this->coeff_.resize(xd+1);
00087 d = xd;
00088 }
00089
00090 x.allocateCache(d);
00091
00092
00093
00094
00095
00096
00097
00098 if (x.hasFastAccess(d))
00099 for(int i=d; i>=0; --i)
00100 this->coeff_[i] = x.fastAccessCoeff(i);
00101 else
00102 for(int i=d; i>=0; --i)
00103 this->coeff_[i] = x.coeff(i);
00104
00105 return *this;
00106 }
00107
00108 template <typename T>
00109 inline Sacado::Tay::CacheTaylor<T>&
00110 Sacado::Tay::CacheTaylor<T>::operator += (const T& val)
00111 {
00112 this->coeff_[0] += val;
00113
00114 return *this;
00115 }
00116
00117 template <typename T>
00118 inline Sacado::Tay::CacheTaylor<T>&
00119 Sacado::Tay::CacheTaylor<T>::operator -= (const T& val)
00120 {
00121 this->coeff_[0] -= val;
00122
00123 return *this;
00124 }
00125
00126 template <typename T>
00127 inline Sacado::Tay::CacheTaylor<T>&
00128 Sacado::Tay::CacheTaylor<T>::operator *= (const T& val)
00129 {
00130 this->coeff_ *= val;
00131
00132 return *this;
00133 }
00134
00135 template <typename T>
00136 inline Sacado::Tay::CacheTaylor<T>&
00137 Sacado::Tay::CacheTaylor<T>::operator /= (const T& val)
00138 {
00139 this->coeff_ /= val;
00140
00141 return *this;
00142 }
00143
00144 template <typename T>
00145 template <typename S>
00146 inline Sacado::Tay::CacheTaylor<T>&
00147 Sacado::Tay::CacheTaylor<T>::operator += (const S& x)
00148 {
00149 unsigned int xd = x.degree();
00150 unsigned int d = this->degree();
00151
00152
00153 if (xd > d) {
00154 this->resizeCoeffs(xd);
00155 d = xd;
00156 }
00157
00158 x.allocateCache(d);
00159
00160 if (x.hasFastAccess(d))
00161 for (int i=d; i>=0; --i)
00162 this->coeff_[i] += x.fastAccessCoeff(i);
00163 else
00164 for (int i=xd; i>=0; --i)
00165 this->coeff_[i] += x.coeff(i);
00166
00167 return *this;
00168 }
00169
00170 template <typename T>
00171 template <typename S>
00172 inline Sacado::Tay::CacheTaylor<T>&
00173 Sacado::Tay::CacheTaylor<T>::operator -= (const S& x)
00174 {
00175 unsigned int xd = x.degree();
00176 unsigned int d = this->degree();
00177
00178
00179 if (xd > d) {
00180 this->resizeCoeffs(xd);
00181 d = xd;
00182 }
00183
00184 x.allocateCache(d);
00185
00186 if (x.hasFastAccess(d))
00187 for (int i=d; i>=0; --i)
00188 this->coeff_[i] -= x.fastAccessCoeff(i);
00189 else
00190 for (int i=xd; i>=0; --i)
00191 this->coeff_[i] -= x.coeff(i);
00192
00193 return *this;
00194 }
00195
00196 template <typename T>
00197 template <typename S>
00198 inline Sacado::Tay::CacheTaylor<T>&
00199 Sacado::Tay::CacheTaylor<T>::operator *= (const S& x)
00200 {
00201 unsigned int xd = x.degree();
00202 unsigned int d = this->degree();
00203 unsigned int dfinal = d;
00204
00205
00206 if (xd > d) {
00207 this->resizeCoeffs(xd);
00208 dfinal = xd;
00209 }
00210
00211 x.allocateCache(dfinal);
00212
00213 if (xd) {
00214 if (d) {
00215 T tmp;
00216 if (x.hasFastAccess(dfinal))
00217 for(int i=dfinal; i>=0; --i) {
00218 tmp = T(0.);
00219 for (int k=0; k<=i; ++k)
00220 tmp += this->coeff_[k]*x.fastAccessCoeff(i-k);
00221 this->coeff_[i] = tmp;
00222 }
00223 else
00224 for(int i=dfinal; i>=0; --i) {
00225 tmp = T(0.);
00226 for (int k=0; k<=i; ++k)
00227 tmp += this->coeff_[k]*x.coeff(i-k);
00228 this->coeff_[i] = tmp;
00229 }
00230 }
00231 else {
00232 if (x.hasFastAccess(dfinal))
00233 for(int i=dfinal; i>=0; --i)
00234 this->coeff_[i] = this->coeff_[0] * x.fastAccessCoeff(i);
00235 else
00236 for(int i=dfinal; i>=0; --i)
00237 this->coeff_[i] = this->coeff_[0] * x.coeff(i);
00238 }
00239 }
00240 else
00241 this->coeff_ *= x.coeff(0);
00242
00243 return *this;
00244 }
00245
00246 template <typename T>
00247 template <typename S>
00248 inline Sacado::Tay::CacheTaylor<T>&
00249 Sacado::Tay::CacheTaylor<T>::operator /= (const S& x)
00250 {
00251 unsigned int xd = x.degree();
00252 unsigned int d = this->degree();
00253 unsigned int dfinal = d;
00254
00255
00256 if (xd > d) {
00257 this->resizeCoeffs(xd);
00258 dfinal = xd;
00259 }
00260
00261 x.allocateCache(dfinal);
00262
00263 if (xd) {
00264 std::valarray<T> tmp(this->coeff_);
00265 if (x.hasFastAccess(dfinal))
00266 for(unsigned int i=0; i<=dfinal; i++) {
00267 for (unsigned int k=1; k<=i; k++)
00268 tmp[i] -= x.fastAccessCoeff(k)*tmp[i-k];
00269 tmp[i] /= x.fastAccessCoeff(0);
00270 }
00271 else
00272 for(unsigned int i=0; i<=dfinal; i++) {
00273 for (unsigned int k=1; k<=i; k++)
00274 tmp[i] -= x.coeff(k)*tmp[i-k];
00275 tmp[i] /= x.coeff(0);
00276 }
00277 this->coeff_ = tmp;
00278 }
00279 else
00280 this->coeff_ /= x.coeff(0);
00281
00282 return *this;
00283 }
00284