42#if defined(RAD_DEBUG_BLOCKKEEP) && !defined(HAVE_SACADO_UNINIT)
43#undef RAD_DEBUG_BLOCKKEEP
54#undef RAD_ALLOW_WANTDERIV
55#ifndef RAD_DISALLOW_WANTDERIV
56#define RAD_ALLOW_WANTDERIV
62#define RAD_REINIT_0(x)
63#define RAD_REINIT_1(x)
64#define RAD_REINIT_2(x)
69#define RAD_REINIT_1(x) x
70#ifdef RAD_ALLOW_WANTDERIV
72#define IndepADvar IndepADvar_1n
75#define IndepADvar IndepADvar_1
79#define RAD_REINIT_2(x) x
81#define RAD_cvchk(x) if (x.gen != x.IndepADvar_root.gen) { x.cv = new ADvari<Double>(x.Val);\
82 x.gen = x.IndepADvar_root.gen; }
83#ifdef RAD_ALLOW_WANTDERIV
84#define IndepADvar IndepADvar_2n
87#define IndepADvar IndepADvar_2
91Botch! Expected
"RAD_REINIT" to be 0, 1, or 2.
94#undef RAD_ALLOW_WANTDERIV
96#define RAD_REINIT_0(x) x
99#ifdef RAD_ALLOW_WANTDERIV
100#define Allow_noderiv(x) x
102#define Allow_noderiv(x)
107#undef RAD_AUTO_AD_Const
108#undef RAD_DEBUG_BLOCKKEEP
115#ifndef RAD_AUTO_AD_Const
116#define RAD_AUTO_AD_Const
130#ifndef RAD_AUTO_AD_Const
131#ifdef RAD_DEBUG_BLOCKKEEP
139#ifdef RAD_AUTO_AD_Const
140#undef RAD_DEBUG_BLOCKKEEP
142#ifdef RAD_DEBUG_BLOCKKEEP
143#if !(RAD_DEBUG_BLOCKKEEP > 0)
144#undef RAD_DEBUG_BLOCKKEEP
152struct UninitType<float> {
153 static const int utype = 4;
157struct UninitType<double> {
158 static const int utype = 5;
162struct UninitType<
std::complex<T> > {
163 static const int utype = UninitType<T>::utype + 2;
172 template<
typename T>
class
205#define Dtype typename DoubleAvoid<Double>::dtype
206#define Ltype typename DoubleAvoid<Double>::ltype
207#define Itype typename DoubleAvoid<Double>::itype
208#define Ttype typename DoubleAvoid<Double>::ttype
210 template<
typename Double>
class IndepADvar;
211 template<
typename Double>
class ConstADvar;
212 template<
typename Double>
class ConstADvari;
213 template<
typename Double>
class ADvar;
214 template<
typename Double>
class ADvari;
215 template<
typename Double>
class ADvar1;
216 template<
typename Double>
class ADvar1s;
217 template<
typename Double>
class ADvar2;
218 template<
typename Double>
class ADvar2q;
219 template<
typename Double>
class ADvarn;
220 template<
typename Double>
class Derp;
222 template<
typename Double>
struct
230 template<
typename Double>
class
243 size_t DMleft, nderps;
245#ifdef RAD_DEBUG_BLOCKKEEP
254 void *Memalloc(
size_t len);
255 static void Gradcomp(
int wantgrad);
270 template<
typename Double>
class
275 friend class ADvar<Double>;
280 template<
typename Double>
class
283 friend class ADvarn<Double>;
287 inline void *
operator new(size_t,
Derp *x) {
return x; }
288 inline void operator delete(
void*,
Derp *) {}
297 Derp(
const ADVari *);
298 Derp(
const Double *,
const ADVari *);
299 Derp(
const Double *,
const ADVari *,
const ADVari *);
305 template<
typename Double> Derp<Double>*
306ADcontext<Double>::new_Derp(
const Double *
a,
const ADvari<Double> *b,
const ADvari<Double> *
c)
311 if (this->DMleft == 0) {
318 this->DMleft = nderps;
320 rv = &((DErp*)DBusy->
memblk)[--this->DMleft];
328#define Ai const Base< ADvari<Double> >&
329#define AI const Base< IndepADvar<Double> >&
330#define T template<typename Double>
357#define F ADvari<Double>&
405 template<
typename Double>ADvari<Double>&
ADf1(Double f, Double g,
const IndepADvar<Double> &x);
406 template<
typename Double>ADvari<Double>&
ADf2(Double f, Double gx, Double gy,
407 const IndepADvar<Double> &x,
const IndepADvar<Double> &y);
408 template<
typename Double>ADvari<Double>&
ADfn(Double f,
int n,
409 const IndepADvar<Double> *x,
const Double *g);
411 template<
typename Double> IndepADvar<Double>&
ADvar_operatoreq(IndepADvar<Double>*,
412 const ADvari<Double>&);
413 template<
typename Double> ADvar<Double>&
ADvar_operatoreq(ADvar<Double>*,
const ADvari<Double>&);
414 template<
typename Double>
void AD_Const(
const IndepADvar<Double>&);
415 template<
typename Double>
void AD_Const1(Double*,
const IndepADvar<Double>&);
416 template<
typename Double> ADvari<Double>&
ADf1(Double, Double,
const ADvari<Double>&);
417 template<
typename Double> ADvari<Double>&
ADf2(Double, Double, Double,
418 const ADvari<Double>&,
const ADvari<Double>&);
419 template<
typename Double> ADvari<Double>&
ADf2(Double, Double, Double,
420 const IndepADvar<Double>&,
const ADvari<Double>&);
421 template<
typename Double> ADvari<Double>&
ADf2(Double, Double, Double,
422 const ADvari<Double>&,
const IndepADvar<Double>&);
423 template<
typename Double> Double
val(
const ADvari<Double>&);
425 template<
typename Double>
class
431#ifdef RAD_AUTO_AD_Const
441 static ADvari *First_ADvari, **Last_ADvari;
443 inline void ADvari_padv(
const IndepADVar *v) {
445 Last_ADvari = &this->Next;
452 static int gcgen_cur, last_opno, zap_gcgen, zap_gcgen1, zap_opno;
453 static FILE *debug_file;
458 void *
operator new(
size_t len) {
461 rv->gcgen = gcgen_cur;
462 rv->opno = ++last_opno;
463 if (last_opno == zap_opno && gcgen_cur == zap_gcgen)
464 printf(
"Got to opno %d\n", last_opno);
470 void operator delete(
void*) {}
471#ifdef RAD_ALLOW_WANTDERIV
472 inline ADvari(Double t): Val(t), aval(0.), wantderiv(1) {}
473 inline ADvari(): Val(0.), aval(0.), wantderiv(1) {}
474 inline void no_deriv() { wantderiv = 0; }
479#ifdef RAD_AUTO_AD_Const
481 friend class ADvar<Double>;
482 friend class ADvar1<Double>;
484 friend class ADvar2<Double>;
487 ADvari(
const IndepADVar *, Double);
488 ADvari(
const IndepADVar *, Double, Double);
492#define Ai const Base< ADvari >&
494#define T1(r,f) F r f <>(Ai);
542 friend ADvari&
ADf1<>(Double f, Double g,
const ADvari &x);
543 friend ADvari&
ADf2<>(Double f, Double gx, Double gy,
const ADvari &x,
const ADvari &y);
544 friend ADvari&
ADfn<>(Double f,
int n,
const IndepADVar *x,
const Double *g);
546 inline operator Double() {
return this->Val; }
547 inline operator Double()
const {
return this->Val; }
552 template<
typename Double>
class
558 ADvar1(Double val1,
const Double *a1,
const ADVari *c1): ADVari(val1) {
559#ifdef RAD_ALLOW_WANTDERIV
560 if (!ADVari::adc.new_Derp(a1,
this,c1))
563 ADVari::adc.new_Derp(a1,
this,c1);
571#ifdef RAD_AUTO_AD_Const
572 typedef typename ADVari::IndepADVar IndepADVar;
574 ADvar1(
const IndepADVar*,
const IndepADVar&);
575 ADvar1(
const IndepADVar*,
const ADVari&);
576 ADvar1(
const Double val1,
const Double *a1,
const ADVari *c1,
const ADVar *v):
577 ADVari(val1), d(a1,this,c1) {
579 this->ADvari_padv(v);
586 template<
typename Double>
class
601 inline void *
operator new(
size_t len) {
return ADVari::adc.Memalloc(len); }
602 inline ConstADvari(Double t): ADVari(t) {}
604 static void aval_reset(
void);
607 template<
typename Double>
class
614 typedef unsigned long ADGenType;
615 mutable ADGenType gen;
621 template<
typename Double>
class
631 IndepADvar_root.ADvprev = (this->ADvprev = IndepADvar_root.ADvprev)->ADvnext =
this;
632 this->ADvnext = &IndepADvar_root;
643 (this->ADvnext->ADvprev = this->ADvprev)->ADvnext = this->ADvnext;
657template<
typename Double> IndepADvar_base0<Double>
658 IndepADvar_base<Double>::IndepADvar_root(0.);
660 template<
typename Double>
void
661IndepADvar_base<Double>::Move_to_end() {
662 if (
this != IndepADvar_root.ADvprev) {
663 (this->ADvnext->ADvprev = this->ADvprev)->ADvnext = this->ADvnext;
664 IndepADvar_root.ADvprev = (this->ADvprev = IndepADvar_root.ADvprev)->ADvnext =
this;
665 this->ADvnext = &IndepADvar_root;
674 template<
typename Double>
class
683#ifdef RAD_AUTO_AD_Const
688#elif defined(RAD_EQ_ALIAS)
699 friend class ADvar<Double>;
701 friend class ADvar1<Double>;
702 friend class ADvarn<Double>;
710#ifdef RAD_ALLOW_WANTDERIV
711 inline int Wantderiv() {
return this->wantderiv; }
714 IndepADvar(
Ttype,
int);
715 IndepADvar(Double,
int);
720#ifdef RAD_AUTO_AD_Const
722 inline IndepADvar() { cv = 0; }
723 inline ~IndepADvar() {
738 inline operator ADVari&()
const {
739 ADVari *tcv = this->cv;
744 inline operator ADVari*()
const {
745 ADVari *tcv = this->cv;
755 inline Double
val()
const {
762 inline Double
adj()
const {
772 friend ADVari&
ADf2<>(Double, Double, Double,
const ADVari&,
const IndepADvar&);
773 friend ADVari&
ADf2<>(Double, Double, Double,
const IndepADvar&,
const ADVari&);
789#define Ai const Base< ADVari >&
790#define AI const Base< IndepADvar >&
798#define T1(f) friend ADVari& f<> (AI);
800#define F friend ADVari&
850 template<
typename Double>
class
866#ifdef RAD_AUTO_AD_Const
868 x->ADvari_padv(
this);
882 friend class ADvar1<Double>;
891#ifdef RAD_AUTO_AD_Const
892 inline ADvar(IndepADVar &x) {
893 this->cv = x.cv ?
new ADVar1(
this, x) : 0;
896 inline ADvar(ADVari &x) { this->cv = &x; x.ADvari_padv(
this); }
897 inline ADvar& operator=(IndepADVar &x) {
900 this->cv =
new ADVar1(
this,x);
903 inline ADvar& operator=(ADVari &x) {
906 this->cv =
new ADVar1(
this, x);
913 inline ADvar(
const IndepADVar &x) {
915 this->cv = (ADVari*)x.cv;
917 inline ADvar(
const ADVari &x) { this->cv = (ADVari*)&x; }
918 inline ADvar& operator=(IndepADVar &x) {
920 this->cv = (ADVari*)x.cv;
return *
this;
922 inline ADvar& operator=(
const ADVari &x) { this->cv = (ADVari*)&x;
return *
this; }
928 this->cv =
new ADVar1(x.
cv->Val, &this->cv->adc.One, x.
cv);
946 this->cv =
new ADVar1(x.
Val, &this->cv->adc.One, &x);
972 inline static bool get_fpval_implies_const(
void) {
return true; }
973 inline static void set_fpval_implies_const(
bool newval) {}
974 inline static bool setget_fpval_implies_const(
bool newval) {
return newval; }
988template<
typename Double>
992template<
typename Double>
995template<
typename Double>
996 inline void AD_Const(
const IndepADvar<Double>&v) {}
999 template<
typename Double>
class
1027#ifdef RAD_NO_CONST_UPDATE
1033 this->cv =
new ADVari(d);
1042 this->cv =
new ADVar1(
this,d);
1051#ifdef RAD_ALLOW_WANTDERIV
1052 template<
typename Double>
class
1056 typedef ADvar<Double>
ADVar;
1057 typedef IndepADvar<Double> IndepADVar;
1058 typedef typename IndepADVar::ADVari ADVari;
1059 typedef ADvar1<Double> ADVar1;
1061 void ADvar_ndctr(Double d) {
1062 ADVari *x =
new ADVari(d);
1073 inline ADvar_nd(Double d):
ADVar((void*)0,0) { ADvar_ndctr(d); }
1074 inline ~ADvar_nd() {}
1077 this->cv = new ADVar1(x.cv->Val, &this->cv->adc.One, x.cv);
1078 RAD_REINIT_2(this->gen = this->IndepADvar_root.gen;)
1084 this->cv =
new ADVar1(x.Val, &this->cv->adc.One, &x);
1090#define ADvar_nd ADvar
1093 template<
typename Double>
class
1103#ifdef RAD_AUTO_AD_Const
1104 typedef typename ADVar1::ADVar
ADVar;
1105 ADvar1s(Double val1, Double a1,
const ADVari *c1,
const ADVar *v):
1106 ADVar1(val1,&
a,c1,v),
a(a1) {}
1111 template<
typename Double>
class
1118 ADvar2(Double val1,
const ADVari *Lcv,
const Double *Lc,
1119 const ADVari *Rcv,
const Double *Rc): ADVari(val1) {
1120#ifdef RAD_ALLOW_WANTDERIV
1122 Ld = ADVari::adc.new_Derp(Lc,
this, Lcv);
1123 Rd = ADVari::adc.new_Derp(Rc,
this, Rcv);
1127 ADVari::adc.new_Derp(Lc,
this, Lcv);
1128 ADVari::adc.new_Derp(Rc,
this, Rcv);
1134 const ADVari *Rcv,
const Double *Rc):
1145#ifdef RAD_AUTO_AD_Const
1147 ADvar2(Double val1,
const ADVari *Lcv,
const Double *Lc,
1148 const ADVari *Rcv,
const Double *Rc,
ADVar *v):
1150 dR.
next = DErp::LastDerp;
1152 DErp::LastDerp = &dL;
1159 this->ADvari_padv(v);
1165 template<
typename Double>
class
1174#ifdef RAD_ALLOW_WANTDERIV
1190 this->
dL.next = &this->
dR;
1196 this->
dL.b = this->
dR.b =
this;
1198#ifdef RAD_AUTO_AD_Const
1199 typedef typename ADVar2::ADVar
ADVar;
1200 ADvar2q(Double val1, Double Lp, Double Rp,
const ADVari *Lcv,
1201 const ADVari *Rcv,
const ADVar *v):
1202 ADVar2(val1),
a(Lp), b(Rp) {
1203 this->dR.next = DErp::LastDerp;
1204 this->dL.next = &this->dR;
1205 DErp::LastDerp = &this->dL;
1210 this->dL.b = this->dR.b =
this;
1212 this->ADvari_padv(v);
1218 template<
typename Double>
class
1226#ifdef RAD_ALLOW_WANTDERIV
1228 for(i = nd = 0; i < n1; i++)
1234 for(
int i = 0; i < n1; i++)
1251 for(i = 0; i < n1; i++, d1++) {
1264template<
typename Double>
1269template<
typename Double>
1273 return L.
Val <
R.Val;
1275template<
typename Double>
1280template<
typename Double>
1286template<
typename Double>
1290 return L.
Val <=
R.Val;
1292template<
typename Double>
1297template<
typename Double>
1303template<
typename Double>
1307 return L.
Val ==
R.Val;
1309template<
typename Double>
1314template<
typename Double>
1320template<
typename Double>
1324 return L.
Val !=
R.Val;
1326template<
typename Double>
1331template<
typename Double>
1337template<
typename Double>
1341 return L.
Val >=
R.Val;
1343template<
typename Double>
1348template<
typename Double>
1354template<
typename Double>
1358 return L.
Val >
R.Val;
1360template<
typename Double>
1365template<
typename Double>
1371template<
typename Double>
1379template<
typename Double>
1382template<
typename Double>
1386template<
typename Double>
1388 a(*a1), b(b1),
c(c1) {}
1391template<
typename Double>
1397template<
typename Double>
1404template<
typename Double>
1423#ifdef RAD_AUTO_AD_Const
1429#ifndef RAD_DEBUG_gcgen1
1430#define RAD_DEBUG_gcgen1 -1
1449#ifdef RAD_DEBUG_BLOCKKEEP
1450 rad_busy_blocks = 0;
1458 DMleft = nderps =
sizeof(DBusy->
memblk)/
sizeof(
DErp);
1475 for(mb = ConstADVari::cadc.
Busy; mb; mb = mb1) {
1495 ConstADVari::lastcad = 0;
1510 ConstADVari::cadc.do_init();
1513template<
typename Double>
void*
1517#ifdef RAD_AUTO_AD_Const
1520#ifdef RAD_Const_WARN
1535#ifdef RAD_DEBUG_BLOCKKEEP
1539 UninitType<Double>::utype,
1542 if ((mb =
Busy->next)) {
1544 for(;; mb = mb->
next) {
1546 UninitType<Double>::utype,
1547 sizeof(
First->memblk)
1553 rad_Oldcurmb =
Busy;
1554 if (rad_busy_blocks >= RAD_DEBUG_BLOCKKEEP) {
1555 rad_busy_blocks = 0;
1559 for(mb =
Busy; mb != mb0; mb = mb1) {
1574 for(mb =
Busy; mb != mb0; mb = mb1) {
1584#ifdef RAD_AUTO_AD_Const
1585 *ADVari::Last_ADvari = 0;
1586 ADVari::Last_ADvari = &ADVari::First_ADvari;
1587 a = ADVari::First_ADvari;
1592#ifdef RAD_Const_WARN
1593 if ((i =
a->opno) > 0)
1609 while((mb1 = mb->
next)) {
1620 while((vb = vb->ADvnext) != vb0)
1621 if ((tcv = ((IADv*)vb)->cv))
1623#elif RAD_REINIT == 2
1635#ifdef RAD_DEBUG_BLOCKKEEP
1644template<
typename Double>
void
1658 if (!(mb = mb->
next))
1680 if (ADVari::gcgen_cur == ADVari::zap_gcgen1 && wantgrad) {
1682 if (!(fname = getenv(
"RAD_DEBUG_FILE")))
1683 fname =
"rad_debug.out";
1687 ADVari::debug_file = fopen(fname,
"w");
1688 ADVari::zap_gcgen1 = -1;
1699 if (ADVari::debug_file) {
1700 for(; d < de; d++) {
1701 fprintf(ADVari::debug_file,
"%d\t%d\t%g + %g * %g",
1704 fprintf(ADVari::debug_file,
" = %g\n", d->
c->
aval);
1711 if (!(mb = mb->
next))
1721 if (ADVari::debug_file)
1723 fprintf(ADVari::debug_file,
"%d\t%d\t%g + %g * %g",
1726 fprintf(ADVari::debug_file,
" = %g\n", d->
c->
aval);
1727 }
while((d = d->
next));
1731 while((d = d->
next));
1734 if (ADVari::debug_file) {
1735 fclose(ADVari::debug_file);
1736 ADVari::debug_file = 0;
1741 if (ADVari::debug_file)
1742 fflush(ADVari::debug_file);
1743 ADVari::gcgen_cur++;
1744 ADVari::last_opno = 0;
1748 template<
typename Double>
void
1763 if (!(mb = mb->
next))
1785 if (ADVari::gcgen_cur == ADVari::zap_gcgen1) {
1787 if (!(fname = getenv(
"RAD_DEBUG_FILE")))
1788 fname =
"rad_debug.out";
1792 ADVari::debug_file = fopen(fname,
"w");
1793 ADVari::zap_gcgen1 = -1;
1798 for(i = 0; i < n; i++)
1799 V[i]->cv->
aval = w[i];
1806 if (ADVari::debug_file) {
1807 for(; d < de; d++) {
1808 fprintf(ADVari::debug_file,
"%d\t%d\t%g + %g * %g",
1811 fprintf(ADVari::debug_file,
" = %g\n", d->
c->
aval);
1818 if (!(mb = mb->
next))
1826 for(i = 0; i < n; i++)
1827 V[i]->cv->
aval = w[i];
1829 if (ADVari::debug_file)
1831 fprintf(ADVari::debug_file,
"%d\t%d\t%g + %g * %g",
1834 fprintf(ADVari::debug_file,
" = %g\n", d->
c->
aval);
1835 }
while((d = d->
next));
1839 while((d = d->
next));
1842 if (ADVari::debug_file) {
1843 fclose(ADVari::debug_file);
1844 ADVari::debug_file = 0;
1849 if (ADVari::debug_file)
1850 fflush(ADVari::debug_file);
1851 ADVari::gcgen_cur++;
1852 ADVari::last_opno = 0;
1856 template<
typename Double>
void
1864 template<
typename Double>
void
1869 *(
const_cast<Double*
>(d->a)) = Double(0.0);
1871 d->b->aval = Double(0.0);
1872 d->b->Val = Double(0.0);
1875 d->c->aval = Double(0.0);
1876 d->c->Val = Double(0.0);
1881 template<
typename Double>
1886 RAD_REINIT_2(Val = d; this->gen = this->IndepADvar_root.gen;)
1889 template<
typename Double>
1894 RAD_REINIT_2(Val = i; this->gen = this->IndepADvar_root.gen;)
1897 template<
typename Double>
1902 RAD_REINIT_2(Val = i; this->gen = this->IndepADvar_root.gen;)
1905 template<
typename Double>
1910 RAD_REINIT_2(Val = i; this->gen = this->IndepADvar_root.gen;)
1913 template<
typename Double>
1918 RAD_REINIT_2(this->Val = 0.; this->gen = this->IndepADvar_root.gen;)
1921 template<
typename Double>
void
1926 RAD_REINIT_2(this->Val = d; this->gen = this->IndepADvar_root.gen;)
1929 template<
typename Double>
1936 x.
cv->adc.new_Derp(&x.adc.One, y, x.
cv);
1941 RAD_REINIT_2(this->Val = y->Val; this->gen = this->IndepADvar_root.gen;)
1944 template<
typename Double>
1951 x.
cv->adc.new_Derp(&x.
cv->adc.One, y, x.
cv);
1956 RAD_REINIT_2(this->Val = y->Val; this->gen = this->IndepADvar_root.gen;)
1959 template<
typename Double>
1965 x.
adc.new_Derp(&x.
adc.One, y, &x);
1970 RAD_REINIT_2(this->Val = y->Val; this->gen = this->IndepADvar_root.gen;)
1973 template<
typename Double>
1979 ConstADVari *ncv =
new ConstADVari(v.
val());
1980#ifdef RAD_AUTO_AD_Const
1987 template<
typename Double>
1991#ifdef RAD_ALLOW_WANTDERIV
1993 if (this->gen != this->IndepADvar_root.gen) {
1995 this->gen = this->IndepADvar_root.gen;
1998 return this->wantderiv =
cv->wantderiv = n;
2004 template<
typename Double>
2014#elif RAD_REINIT == 1
2019#ifdef RAD_AUTO_AD_Const
2021 template<
typename Double>
2024 this->ADvari_padv(x);
2028 template<
typename Double>
2031 this->ADvari_padv(x);
2035 template<
typename Double>
2037 ADVari(y.cv->Val), d((const Double*)&ADcontext<Double>::
One, (ADVari*)this, y.cv)
2039 this->ADvari_padv(x);
2042 template<
typename Double>
2046 this->ADvari_padv(x);
2051 template<
typename Double>
2057 RAD_REINIT_2(This->Val = x.
Val; This->gen = This->IndepADvar_root.gen;)
2061 template<
typename Double>
2067 RAD_REINIT_2(This->Val = x.
Val; This->gen = This->IndepADvar_root.gen;)
2074 template<
typename Double>
2078#ifdef RAD_AUTO_AD_Const
2081 this->cv =
new ADVari(
this,d);
2083 this->cv =
new ADVari(d);
2090 template<
typename Double>
2094#ifdef RAD_AUTO_AD_Const
2097 this->cv =
new ADVari(
this,d);
2103 RAD_REINIT_2(this->Val = d; this->gen = this->IndepADvar_root.gen;)
2108 template<
typename Double>
2115 template<
typename Double>
2123#ifdef RAD_AUTO_AD_Const
2124#define RAD_ACA ,this
2129 template<
typename Double>
2140 template<
typename Double>
2147 template<
typename Double>
2158 template<
typename Double>
2165 template<
typename Double>
2173 template<
typename Double>
2184 template<
typename Double>
2191 template<
typename Double>
2202 template<
typename Double>
2209 template<
typename Double>
2217 template<
typename Double>
2228 template<
typename Double>
2235 template<
typename Double>
2246 template<
typename Double>
2253 template<
typename Double>
2258 Double Lv = L.
Val, Rv =
R.Val, pL = 1. / Rv, q = Lv/Rv;
2262 template<
typename Double>
2266 Double Lv = Lcv->
Val, Rv =
R.Val, pL = 1. / Rv, q = Lv/Rv;
2274 template<
typename Double>
2281 template<
typename Double>
2285 Double recip = 1. /
R.Val;
2286 Double q = L * recip;
2290 template<
typename Double>
2301 template<
typename Double>
2309 template<
typename Double>
2313 Double t = v.
Val, t1 = std::sqrt(t*t - 1.);
2317 template<
typename Double>
2325 template<
typename Double>
2329 Double t = v.
Val, td = 1., t1 = std::sqrt(t*t + 1.);
2337 template<
typename Double>
2345 template<
typename Double>
2350 return *(
new ADvar1s<Double>(0.5*std::log((1.+t)/(1.-t)), 1./(1. - t*t), &v));
2353 template<
typename Double>
2358 Double x = L.
Val, y =
R.Val, t = x*x + y*y;
2362 template<
typename Double>
2366 Double y =
R.Val, t = x*x + y*y;
2370 template<
typename Double>
2374 Double x = L.
Val, t = x*x + y*y;
2378 template<
typename Double>
2387 template<
typename Double>
2396 template<
typename Double>
2405 template<
typename Double>
2414 template<
typename Double>
2423 template<
typename Double>
2432 template<
typename Double>
2439 template<
typename Double>
2446 template<
typename Double>
2451 Double t = std::exp(v.
Val);
2455 rcv->
d.a = &rcv->
Val;
2461 template<
typename Double>
2469 template<
typename Double>
2473 static double num = 1. / std::log(10.);
2478 template<
typename Double>
2487 template<
typename Double>
2495 template<
typename Double>
2503 template<
typename Double>
2510 template<
typename Double>
2517 template<
typename Double>
2521 Double t = std::sqrt(v.
Val);
2525 template<
typename Double>
2529 Double t = std::cos(v.
Val);
2533 template<
typename Double>
2537 Double t = 1. / std::cosh(v.
Val);
2541 template<
typename Double>
2547 if ((t = v.
Val) < 0) {
2554 template<
typename Double>
2563 if ((t = v.
Val) < 0) {
2570template<
typename Double>
2574 Double t = std::cbrt(v.
Val);
2578 template<
typename Double>
2584 template<
typename Double>
2590 template<
typename Double>
2596 template<
typename Double>
2602 template<
typename Double>
2608 template<
typename Double>
2614 template<
typename Double>
2620 template<
typename Double>
2626 template<
typename Double>
2633#define A (ADvari<Double>*)
2634#ifdef RAD_Const_WARN
2635#define C(x) (((x)->opno < 0) ? RAD_Const_Warn(x) : 0, *A x)
2639#define T template<typename Double> inline
2640#define F ADvari<Double>&
2641#define Ai const Base< ADvari<Double> >&
2642#define AI const Base< IndepADvar<Double> >&
2644#define CAI(x,y) const IndepADvar<Double> & x = y.derived()
2645#define CAi(x,y) const ADvari<Double> & x = y.derived()
2647 T r f(Ai LL, AI RR) { CAi(L,LL); CAI(R,RR); RAD_cvchk(R) return f(L, C(R.cv)); } \
2648 T r f(AI LL, Ai RR) { CAI(L,LL); CAi(R,RR); RAD_cvchk(L) return f(C(L.cv), R); }\
2649 T r f(AI LL, AI RR) { CAI(L,LL); CAI(R,RR); RAD_cvchk(L) RAD_cvchk(R) return f(C(L.cv), C(R.cv)); }\
2650 T r f(AI LL, D R) { CAI(L,LL); RAD_cvchk(L) return f(C(L.cv), R); } \
2651 T r f(D L, AI RR) { CAI(R,RR); RAD_cvchk(R) return f(L, C(R.cv)); } \
2652 T r f(Ai L, Dtype R) { return f(L, (D)R); }\
2653 T r f(AI L, Dtype R) { return f(L, (D)R); }\
2654 T r f(Ai L, Ltype R) { return f(L, (D)R); }\
2655 T r f(AI L, Ltype R) { return f(L, (D)R); }\
2656 T r f(Ai L, Itype R) { return f(L, (D)R); }\
2657 T r f(AI L, Itype R) { return f(L, (D)R); }\
2658 T r f(Dtype L, Ai R) { return f((D)L, R); }\
2659 T r f(Dtype L, AI R) {return f((D)L, R); }\
2660 T r f(Ltype L, Ai R) { return f((D)L, R); }\
2661 T r f(Ltype L, AI R) { return f((D)L, R); }\
2662 T r f(Itype L, Ai R) { return f((D)L, R); }\
2663 T r f(Itype L, AI R) { return f((D)L, R); }
2684 T F f(AI xx) { CAI(x,xx); RAD_cvchk(x) return f(C(x.cv)); }
int RAD_Const_Warn(void *v)
atan2(expr1.val(), expr2.val())
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
adouble max(const adouble &a, const adouble &b)
adouble min(const adouble &a, const adouble &b)
ADmemblock< Double > ADMemblock
static void Weighted_Gradcomp(size_t, ADVar **, Double *)
void * Memalloc(size_t len)
static void Outvar_Gradcomp(ADVar &)
void * new_ADmemblock(size_t)
static const Double negOne
ADvar1(Double val1, const Double *a1, const ADVari *c1)
ADvar1(Double val1, const ADVari *c1)
ADvar1s(Double val1, Double a1, const ADVari *c1)
ADvar2(Double val1, const ADVari *Lcv, const Double *Lc, const ADVari *Rcv, const Double *Rc)
ADvar2q(Double val1, Double Lp, Double Rp, const ADVari *Lcv, const ADVari *Rcv)
ConstADvari< U > ConstADVari
IndepADvar< U > IndepADVar
static void Outvar_Gradcomp(ADvar &v)
ADvar & operator-=(const ADVari &)
static void set_fpval_implies_const(bool newval)
ADvar & operator+=(Double)
ADvar & operator/=(Double)
ADvar & operator-=(Double)
static void Gradcomp(int wantgrad)
ADvar & operator=(const ADVari &x)
static bool get_fpval_implies_const(void)
IndepADVar::ADVari ADVari
ADvar & operator*=(const ADVari &)
ADvar & operator+=(const ADVari &)
const ADVari & ADvar(const IndepADVar &x)
static bool setget_fpval_implies_const(bool newval)
Allow_noderiv(inline ADvar(void *v, int wd):IndepADVar(v, wd) {}) friend ADvar &ADvar_operatoreq<>(ADvar *
ADvar & operator=(Double)
static void Weighted_Gradcomp(size_t n, ADvar **v, Double *w)
ADvar & operator*=(Double)
ADvar & operator/=(const ADVari &)
Allow_noderiv(mutable int wantderiv;) void *operator new(size_t len)
static ADcontext< Double > adc
IndepADvar< Double > IndepADVar
ScalarType< value_type >::type scalar_type
ADVari::IndepADVar IndepADVar
ADvarn(Double val1, int n1, const IndepADVar *x, const Double *g)
ConstADvar & operator=(Double d)
ConstADvar & operator*=(ADVari &)
ADVar::ConstADVari ConstADVari
ConstADvar & operator*=(Double)
void ConstADvar_ctr(Double)
ConstADvar & operator+=(ADVari &)
ConstADvar & operator-=(ADVari &)
ConstADvar & operator+=(Double)
ConstADvar & operator=(ADVari &d)
ConstADvar & operator-=(Double)
ADVar::IndepADVar IndepADVar
ConstADvar & operator/=(Double)
ConstADvar & operator/=(ADVari &)
static CADcontext< Double > cadc
static void aval_reset(void)
IndepADvar_base(Allow_noderiv(int wd))
IndepADvar() Allow_noderiv(
static void AD_Const(const IndepADvar &)
static void Weighted_Gradcomp(size_t n, ADVar **v, Double *w)
static void Gradcomp(int wantgrad)
IndepADvar & operator=(IndepADvar &x)
static void Outvar_Gradcomp(ADVar &v)
ADvari< Double > & atan(const Base< ADvari< Double > > &vv)
ADvari< Double > & operator*(const Base< ADvari< Double > > &LL, const Base< ADvari< Double > > &RR)
ADvari< Double > & tanh(const Base< ADvari< Double > > &vv)
int operator==(const Base< ADvari< Double > > &LL, const Base< ADvari< Double > > &RR)
void AD_Const1(Double *, const IndepADvar< Double > &)
ADvari< Double > & ADf1(Double f, Double g, const IndepADvar< Double > &x)
IndepADvar< Double > & ADvar_operatoreq(IndepADvar< Double > *, const ADvari< Double > &)
ADvari< Double > & sin(const Base< ADvari< Double > > &vv)
int operator<(const Base< ADvari< Double > > &LL, const Base< ADvari< Double > > &RR)
int operator!=(const Base< ADvari< Double > > &LL, const Base< ADvari< Double > > &RR)
ADvari< Double > & tan(const Base< ADvari< Double > > &vv)
int operator>(const Base< ADvari< Double > > &LL, const Base< ADvari< Double > > &RR)
ADvari< Double > & operator-(const Base< ADvari< Double > > &TT)
ADvari< Double > & operator+(const Base< ADvari< Double > > &TT)
ADvari< Double > & asin(const Base< ADvari< Double > > &vv)
ADvari< Double > & log10(const Base< ADvari< Double > > &vv)
ADvari< Double > & sinh(const Base< ADvari< Double > > &vv)
ADvari< Double > & cos(const Base< ADvari< Double > > &vv)
ADvari< Double > & fabs(const Base< ADvari< Double > > &vv)
ADvari< Double > & max(const Base< ADvari< Double > > &LL, const Base< ADvari< Double > > &RR)
void AD_Const(const IndepADvar< Double > &)
ADvari< Double > & ADf2(Double f, Double gx, Double gy, const IndepADvar< Double > &x, const IndepADvar< Double > &y)
ADvari< Double > & operator/(const Base< ADvari< Double > > &LL, const Base< ADvari< Double > > &RR)
ADvari< Double > & cbrt(const Base< ADvari< Double > > &vv)
const Double ADcontext< Double >::One
ADvari< Double > & log(const Base< ADvari< Double > > &vv)
ADvari< Double > & pow(const Base< ADvari< Double > > &LL, const Base< ADvari< Double > > &RR)
ADvari< Double > & acos(const Base< ADvari< Double > > &vv)
int operator<=(const Base< ADvari< Double > > &LL, const Base< ADvari< Double > > &RR)
ADvari< Double > & ADfn(Double f, int n, const IndepADvar< Double > *x, const Double *g)
ADvari< Double > & atanh(const Base< ADvari< Double > > &vv)
ADvari< Double > & min(const Base< ADvari< Double > > &LL, const Base< ADvari< Double > > &RR)
ADvari< Double > & atan2(const Base< ADvari< Double > > &LL, const Base< ADvari< Double > > &RR)
ADvari< Double > & cosh(const Base< ADvari< Double > > &vv)
ADvari< Double > & asinh(const Base< ADvari< Double > > &vv)
ADvari< Double > & acosh(const Base< ADvari< Double > > &vv)
int operator>=(const Base< ADvari< Double > > &LL, const Base< ADvari< Double > > &RR)
ADvari< Double > & sqrt(const Base< ADvari< Double > > &vv)
ADvari< Double > & abs(const Base< ADvari< Double > > &vv)
ADvari< Double > & exp(const Base< ADvari< Double > > &vv)
ACosExprType< T >::expr_type acos(const Expr< T > &expr)
PowExprType< Expr< T1 >, Expr< T2 > >::expr_type pow(const Expr< T1 > &expr1, const Expr< T2 > &expr2)
Log10ExprType< T >::expr_type log10(const Expr< T > &expr)
ATanExprType< T >::expr_type atan(const Expr< T > &expr)
TanhExprType< T >::expr_type tanh(const Expr< T > &expr)
TanExprType< T >::expr_type tan(const Expr< T > &expr)
ASinExprType< T >::expr_type asin(const Expr< T > &expr)
FloatingPoint< double > Double
Base class for Sacado types to control overload resolution.
const derived_type & derived() const
char memblk[1000 *sizeof(double)]
Turn ADvar into a meta-function class usable with mpl::apply.
Sacado::RadVec::ADvar< double > ADVar
void _uninit_f2c(void *x, int type, long len)