23 for(
int i=d;
i>=0; --
i)
26 for(
int i=d;
i>=0; --
i)
37 for (
int i=1;
i<this->coeff_size();
i++)
38 this->coeff_[
i] =
T(0.);
59 int d = this->degree();
64 this->coeff_.resize(xd+1);
77 for(
int i=d;
i>=0; --
i)
80 for(
int i=d;
i>=0; --
i)
104 template <
typename T>
113 template <
typename T>
122 template <
typename T>
123 template <
typename S>
128 int d = this->degree();
132 this->resizeCoeffs(xd);
138 if (x.hasFastAccess(d))
139 for (
int i=d;
i>=0; --
i)
140 this->coeff_[
i] += x.fastAccessCoeff(
i);
142 for (
int i=xd;
i>=0; --
i)
143 this->coeff_[
i] += x.coeff(
i);
148 template <
typename T>
149 template <
typename S>
154 int d = this->degree();
158 this->resizeCoeffs(xd);
164 if (x.hasFastAccess(d))
165 for (
int i=d;
i>=0; --
i)
166 this->coeff_[
i] -= x.fastAccessCoeff(
i);
168 for (
int i=xd;
i>=0; --
i)
169 this->coeff_[
i] -= x.coeff(
i);
174 template <
typename T>
175 template <
typename S>
180 int d = this->degree();
185 this->resizeCoeffs(xd);
189 x.allocateCache(dfinal);
194 if (x.hasFastAccess(dfinal))
195 for(
int i=dfinal;
i>=0; --
i) {
197 for (
int k=0; k<=
i; ++k)
198 tmp += this->coeff_[k]*x.fastAccessCoeff(
i-k);
199 this->coeff_[
i] = tmp;
202 for(
int i=dfinal;
i>=0; --
i) {
204 for (
int k=0; k<=
i; ++k)
205 tmp += this->coeff_[k]*x.coeff(
i-k);
206 this->coeff_[
i] = tmp;
210 if (x.hasFastAccess(dfinal))
211 for(
int i=dfinal;
i>=0; --
i)
212 this->coeff_[
i] = this->coeff_[0] * x.fastAccessCoeff(
i);
214 for(
int i=dfinal;
i>=0; --
i)
215 this->coeff_[
i] = this->coeff_[0] * x.coeff(
i);
219 this->coeff_ *= x.coeff(0);
224 template <
typename T>
225 template <
typename S>
230 int d = this->degree();
235 this->resizeCoeffs(xd);
239 x.allocateCache(dfinal);
242 std::valarray<T> tmp(this->coeff_);
243 if (x.hasFastAccess(dfinal))
244 for(
int i=0;
i<=dfinal;
i++) {
245 for (
int k=1; k<=
i; k++)
246 tmp[
i] -= x.fastAccessCoeff(k)*tmp[
i-k];
247 tmp[
i] /= x.fastAccessCoeff(0);
250 for(
int i=0;
i<=dfinal;
i++) {
251 for (
int k=1; k<=
i; k++)
252 tmp[
i] -= x.coeff(k)*tmp[
i-k];
253 tmp[
i] /= x.coeff(0);
258 this->coeff_ /= x.coeff(0);
CacheTaylor< T > & operator=(const T &v)
Assignment operator with constant right-hand-side.
Forward-mode AD class using dynamic memory allocation.
unsigned int degree() const
Return degree of polynomial.
int degree() const
Returns degree of polynomial.
CacheTaylor()
Default constructor.
value_type fastAccessCoeff(unsigned int i) const
Return degree i term of expression.
bool hasFastAccess(unsigned int d) const
Return if expression has fast access.
std::valarray< T > coeff_
Taylor polynomial coefficients.
CacheTaylor< T > & operator/=(const T &x)
Division-assignment operator with constant right-hand-side.
CacheTaylor< T > & operator+=(const T &x)
Addition-assignment operator with constant right-hand-side.
CacheTaylor< T > & operator-=(const T &x)
Subtraction-assignment operator with constant right-hand-side.
value_type coeff(unsigned int i) const
Return degree i term of expression.
CacheTaylor< T > & operator*=(const T &x)
Multiplication-assignment operator with constant right-hand-side.
void allocateCache(unsigned int d) const
Allocate coefficient cache.
Wrapper for a generic expression template.
Taylor polynomial class using caching expression templates.