31 #if defined (__clang__) && !defined (__INTEL_COMPILER) 32 #pragma clang system_header 45 coeff_(NULL), deg_(-1), len_(0)
52 coeff_(), deg_(0), len_(1)
61 coeff_(), deg_(d), len_(d+1)
70 coeff_(), deg_(d), len_(d+1)
78 coeff_(), deg_(d), len_(l)
86 coeff_(), deg_(x.deg_), len_(x.deg_+1)
104 if (len_ < x.
deg_+1) {
118 template <
typename T>
125 template <
typename T>
128 th(new TaylorData(x))
132 template <
typename T>
139 template <
typename T>
142 th(new TaylorData(d, x))
146 template <
typename T>
149 th(new TaylorData(d))
153 template <
typename T>
160 template <
typename T>
166 template <
typename T>
171 if (d+1 > length()) {
185 template <
typename T>
190 if (d+1 > length()) {
197 template <
typename T>
216 template <
typename T>
224 template <
typename T>
233 template <
typename T>
241 template <
typename T>
247 x.
th->deg_ = th->deg_;
248 x.
th->len_ = th->deg_+1;
250 for (
int i=0; i<=th->deg_; i++)
251 x.
th->coeff_[i] = -th->coeff_[i];
256 template <
typename T>
268 template <
typename T>
280 template <
typename T>
287 for (
int i=0; i<=th->deg_; i++)
293 template <
typename T>
300 for (
int i=0; i<=th->deg_; i++)
306 template <
typename T>
315 int dmin = xd < d ? xd : d;
318 bool need_resize = l > length();
322 for (
int i=0; i<=d; i++)
323 c[i] = fastAccessCoeff(i);
327 T* xc = x.
th->coeff_;
329 for (
int i=0; i<=dmin; i++)
332 for (
int i=d+1; i<=xd; i++)
346 template <
typename T>
355 int dmin = xd < d ? xd : d;
358 bool need_resize = l > length();
362 for (
int i=0; i<=d; i++)
363 c[i] = fastAccessCoeff(i);
367 T* xc = x.
th->coeff_;
369 for (
int i=0; i<=dmin; i++)
372 for (
int i=d+1; i<=xd; i++)
386 template <
typename T>
395 if ((xd != d) && (xd != 0) && (d != 0))
396 throw "Taylor Error: Attempt to assign with incompatible degrees";
400 T* xc = x.
th->coeff_;
402 if (d > 0 && xd > 0) {
406 for (
int i=0; i<=d; i++) {
408 for (
int k=0; k<=i; ++k)
416 for (
int i=0; i<=d; i++)
420 if (length() < xd+1) {
423 for (
int i=0; i<=xd; i++)
429 for (
int i=d; i>=0; i--)
437 template <
typename T>
446 if ((xd != d) && (xd != 0) && (d != 0))
447 throw "Taylor Error: Attempt to assign with incompatible degrees";
451 T* xc = x.
th->coeff_;
453 if (d > 0 && xd > 0) {
457 for(
int i=0; i<=d; i++) {
459 for (
int k=1; k<=i; ++k)
460 tmp -= xc[k]*cc[i-k];
467 for (
int i=0; i<=d; i++)
474 cc[0] =
c[0] / xc[0];
475 for (
int i=1; i<=xd; i++) {
477 for (
int k=1; k<=i; ++k)
478 tmp -= xc[k]*cc[i-k];
487 template <
typename T>
498 template <
typename T>
508 int dc = da > db ? da : db;
511 if ((da != db) && (da != 0) && (db != 0))
512 throw "operator+(): Arguments have incompatible degrees!";
516 const T* ca =
a.coeff();
520 if (da > 0 && db > 0) {
521 for (
int i=0; i<=dc; i++)
522 cc[i] = ca[i] + cb[i];
525 cc[0] = ca[0] + cb[0];
526 for (
int i=1; i<=dc; i++)
530 cc[0] = ca[0] + cb[0];
531 for (
int i=1; i<=dc; i++)
538 template <
typename T>
552 for (
int i=1; i<=dc; i++)
558 template <
typename T>
568 const T* ca =
a.coeff();
572 for (
int i=1; i<=dc; i++)
578 template <
typename T>
588 int dc = da > db ? da : db;
591 if ((da != db) && (da != 0) && (db != 0))
592 throw "operator+(): Arguments have incompatible degrees!";
596 const T* ca =
a.coeff();
600 if (da > 0 && db > 0) {
601 for (
int i=0; i<=dc; i++)
602 cc[i] = ca[i] - cb[i];
605 cc[0] = ca[0] - cb[0];
606 for (
int i=1; i<=dc; i++)
610 cc[0] = ca[0] - cb[0];
611 for (
int i=1; i<=dc; i++)
618 template <
typename T>
632 for (
int i=1; i<=dc; i++)
638 template <
typename T>
648 const T* ca =
a.coeff();
652 for (
int i=1; i<=dc; i++)
658 template <
typename T>
668 int dc = da > db ? da : db;
671 if ((da != db) && (da != 0) && (db != 0))
672 throw "operator+(): Arguments have incompatible degrees!";
676 const T* ca =
a.coeff();
680 if (da > 0 && db > 0) {
682 for (
int i=0; i<=dc; i++) {
684 for (
int k=0; k<=i; k++)
685 tmp += ca[k]*cb[i-k];
690 for (
int i=0; i<=dc; i++)
694 for (
int i=0; i<=dc; i++)
701 template <
typename T>
714 for (
int i=0; i<=dc; i++)
720 template <
typename T>
730 const T* ca =
a.coeff();
733 for (
int i=0; i<=dc; i++)
739 template <
typename T>
749 int dc = da > db ? da : db;
752 if ((da != db) && (da != 0) && (db != 0))
753 throw "operator+(): Arguments have incompatible degrees!";
757 const T* ca =
a.coeff();
761 if (da > 0 && db > 0) {
763 for (
int i=0; i<=dc; i++) {
765 for (
int k=0; k<=i; k++)
766 tmp -= cb[k]*cc[i-k];
771 for (
int i=0; i<=dc; i++)
776 cc[0] = ca[0] / cb[0];
777 for (
int i=1; i<=dc; i++) {
779 for (
int k=0; k<=i; k++)
780 tmp -= cb[k]*cc[i-k];
788 template <
typename T>
803 for (
int i=1; i<=dc; i++) {
805 for (
int k=0; k<=i; k++)
806 tmp -= cb[k]*cc[i-k];
813 template <
typename T>
823 const T* ca =
a.coeff();
826 for (
int i=0; i<=dc; i++)
832 template <
typename T>
840 const T* ca =
a.coeff();
845 for (
int i=1; i<=dc; i++) {
847 for (
int k=1; k<=i; k++)
848 tmp += k*cc[i-k]*ca[k];
855 template <
typename T>
863 const T* ca =
a.coeff();
868 for (
int i=1; i<=dc; i++) {
870 for (
int k=1; k<=i-1; k++)
871 tmp -= k*ca[i-k]*cc[k];
872 cc[i] = tmp / (i*ca[0]);
878 template <
typename T>
886 template <
typename T>
894 const T* ca =
a.coeff();
899 for (
int i=1; i<=dc; i++) {
901 for (
int k=1; k<=i-1; k++)
902 tmp -= cc[k]*cc[i-k];
903 cc[i] = tmp / (2.0*cc[0]);
909 #ifdef HAVE_SACADO_CXX11 910 template <
typename T>
914 return pow(aa,
typename Taylor<T>::value_type(1.0/3.0));
918 template <
typename T>
928 template <
typename T>
937 template <
typename T>
946 template <
typename T>
956 if (
c.degree() != dc)
959 const T* ca =
a.coeff();
967 for (
int i=1; i<=dc; i++) {
970 for (
int k=1; k<=i; k++) {
971 tmp1 += k*ca[k]*cc[i-k];
972 tmp2 -= k*ca[k]*cs[i-k];
979 template <
typename T>
992 template <
typename T>
1005 template <
typename T>
1010 int dc =
a.degree();
1019 template <
typename T>
1026 int dc =
a.degree();
1029 if (
c.degree() != dc)
1030 c.resize(dc,
false);
1032 const T* ca =
a.coeff();
1040 for (
int i=1; i<=dc; i++) {
1043 for (
int k=1; k<=i; k++) {
1044 tmp1 += k*ca[k]*cc[i-k];
1045 tmp2 += k*ca[k]*cs[i-k];
1052 template <
typename T>
1057 int dc =
a.degree();
1065 template <
typename T>
1070 int dc =
a.degree();
1078 template <
typename T>
1083 int dc =
a.degree();
1092 template <
typename T>
1100 int dc =
a.degree();
1103 const T* ca =
a.coeff();
1109 for (
int i=1; i<=dc; i++) {
1111 for (
int k=1; k<=i; k++)
1112 tmp += k*ca[k]*cb[i-k];
1119 template <
typename T>
1128 template <
typename T>
1137 template <
typename T>
1146 template <
typename T>
1159 template <
typename T>
1171 template <
typename T>
1179 c.fastAccessCoeff(0) =
atan2(
a.coeff(0),b);
1183 template <
typename T>
1192 template <
typename T>
1201 template <
typename T>
1210 template <
typename T>
1215 if (
a.coeff(0) >= 0)
1221 template <
typename T>
1226 if (
a.coeff(0) >= 0)
1232 template <
typename T>
1240 if (
a.coeff(0) >= b.
coeff(0))
1246 template <
typename T>
1259 template <
typename T>
1266 if (
a.coeff(0) >= b)
1272 template <
typename T>
1280 if (
a.coeff(0) <= b.
coeff(0))
1286 template <
typename T>
1299 template <
typename T>
1306 if (
a.coeff(0) <= b)
1312 template <
typename T>
1319 return a.coeff(0) == b.
coeff(0);
1322 template <
typename T>
1331 template <
typename T>
1337 return a.coeff(0) == b;
1340 template <
typename T>
1347 return a.coeff(0) != b.
coeff(0);
1350 template <
typename T>
1359 template <
typename T>
1365 return a.coeff(0) != b;
1368 template <
typename T>
1370 operator<=(const Base< Taylor<T> >& aa,
1375 return a.coeff(0) <= b.
coeff(0);
1378 template <
typename T>
1380 operator<=(const typename Taylor<T>::value_type&
a,
1387 template <
typename T>
1389 operator<=(const Base< Taylor<T> >& aa,
1393 return a.coeff(0) <= b;
1396 template <
typename T>
1403 return a.coeff(0) >= b.
coeff(0);
1406 template <
typename T>
1415 template <
typename T>
1421 return a.coeff(0) >= b;
1424 template <
typename T>
1426 operator<(const Base< Taylor<T> >& aa,
1431 return a.coeff(0) < b.
coeff(0);
1434 template <
typename T>
1436 operator<(const typename Taylor<T>::value_type&
a,
1443 template <
typename T>
1445 operator<(const Base< Taylor<T> >& aa,
1449 return a.coeff(0) < b;
1452 template <
typename T>
1459 return a.coeff(0) > b.
coeff(0);
1462 template <
typename T>
1471 template <
typename T>
1477 return a.coeff(0) > b;
1480 template <
typename T>
1482 bool is_zero =
true;
1483 for (
int i=0; i<=x.
degree(); i++)
1484 is_zero = is_zero && (x.
coeff(i) == 0.0);
1488 template <
typename T>
1497 template <
typename T>
1506 template <
typename T>
1515 template <
typename T>
1524 template <
typename T>
1533 template <
typename T>
1542 template <
typename T>
1544 operator << (std::ostream& os, const Base< Taylor<T> >& aa)
1549 for (
int i=0; i<=
a.degree(); i++) {
1550 os <<
a.coeff(i) <<
" ";
void resize(int d, bool keep_coeffs)
Resize polynomial to degree d.
void sinhcosh(const Base< Taylor< T > > &a, Taylor< T > &s, Taylor< T > &c)
static KOKKOS_INLINE_FUNCTION void copy(const T *src, T *dest, int sz)
Copy array from src to dest of length sz.
double value_type
Typename of values.
const derived_type & derived() const
bool operator&&(const Base< Taylor< T > > &xx1, const typename Taylor< T >::value_type &b)
int deg_
Degree of polynomial.
void makeOwnCopy()
Make handle have its own copy of rep.
KOKKOS_INLINE_FUNCTION Expr< UnaryPlusOp< Expr< T > > > operator+(const Expr< T > &expr)
int len_
Length of allocated polynomial array.
pow(expr1.val(), expr2.val())
TaylorData & operator=(const TaylorData &x)
Assignment operator.
bool operator||(const Base< Taylor< T > > &xx1, const typename Taylor< T >::value_type &b)
static KOKKOS_INLINE_FUNCTION void destroy_and_release(T *m, int sz)
Destroy array elements and release memory.
TaylorData()
Default constructor.
Base class for Sacado types to control overload resolution.
expr expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c *expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 c
static KOKKOS_INLINE_FUNCTION T * get_and_fill(int sz)
Get memory for new array of length sz and fill with zeros.
Taylor< T > quad(const typename Taylor< T >::value_type &c0, const Base< Taylor< T > > &a, const Base< Taylor< T > > &b)
SimpleFad< ValueT > min(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
SimpleFad< ValueT > operator/(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
static KOKKOS_INLINE_FUNCTION void zero(T *dest, int sz)
Zero out array dest of length sz.
Sacado::Handle< TaylorData > th
atan2(expr1.val(), expr2.val())
T * coeff_
Taylor polynomial coefficients.
void sincos(const Base< Taylor< T > > &a, Taylor< T > &s, Taylor< T > &c)
bool operator==(const Handle< T > &h1, const Handle< T > &h2)
Compare two handles.
int operator!=(const ADvari &L, const ADvari &R)
int operator>(const ADvari &L, const ADvari &R)
SimpleFad< ValueT > operator*(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
SimpleFad< ValueT > max(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
const T * coeff() const
Returns Taylor coefficient array.
KOKKOS_INLINE_FUNCTION Expr< UnaryMinusOp< Expr< T > > > operator-(const Expr< T > &expr)
int operator>=(const ADvari &L, const ADvari &R)
int degree() const
Returns degree of polynomial.
Taylor()
Default constructor.
bool toBool(const Taylor< T > &x)