35 #ifndef SACADO_TRADVEC_H
36 #define SACADO_TRADVEC_H
44 #if defined(RAD_DEBUG_BLOCKKEEP) && !defined(HAVE_SACADO_UNINIT)
45 #undef RAD_DEBUG_BLOCKKEEP
48 #ifdef RAD_Const_WARN //{ ==> RAD_AUTO_AD_Const and RAD_DEBUG
49 #ifndef RAD_AUTO_AD_Const
50 #define RAD_AUTO_AD_Const
57 #endif //} RAD_Const_WARN
64 #ifndef RAD_AUTO_AD_Const
65 #ifdef RAD_DEBUG_BLOCKKEEP
73 #ifdef RAD_AUTO_AD_Const
74 #undef RAD_DEBUG_BLOCKKEEP
75 #define Padvinit ,padv(0)
78 #ifdef RAD_DEBUG_BLOCKKEEP
79 #if !(RAD_DEBUG_BLOCKKEEP > 0)
80 #undef RAD_DEBUG_BLOCKKEEP
82 extern "C" void _uninit_f2c(
void *x,
int type,
long len);
88 struct UninitType<float> {
89 static const int utype = 4;
93 struct UninitType<double> {
94 static const int utype = 5;
98 struct UninitType< std::complex<T> > {
99 static const int utype = UninitType<T>::utype + 2;
108 template<
typename T>
class
121 #define Dtype typename DoubleAvoid<Double>::dtype
122 #define Ttype typename DoubleAvoid<Double>::ttype
127 template<
typename Double>
class ADvar;
134 template<
typename Double>
class Derp;
136 template<
typename Double>
struct
144 template<
typename Double>
class
156 #ifdef RAD_DEBUG_BLOCKKEEP
158 ADMemblock *rad_Oldcurmb;
160 void *new_ADmemblock(
size_t);
161 void derp_init(
size_t);
163 static const Double
One, negOne;
165 void *Memalloc(
size_t len);
166 static void Gradcomp();
167 static void aval_reset(
void);
168 static void Weighted_Gradcomp(
size_t, ADVar**, Double*);
169 static void Weighted_GradcompVec(
size_t,
size_t*, ADVar***, Double**);
170 static void Outvar_Gradcomp(ADVar&);
173 template<
typename Double>
class
182 template<
typename Double>
class
193 Derp(
const ADVari *);
194 Derp(
const Double *,
const ADVari *);
195 Derp(
const Double *,
const ADVari *,
const ADVari *);
196 inline void *
operator new(
size_t len) {
return (
Derp*)ADVari::adc.Memalloc(len); }
202 #define Ai const ADvari<Double>&
203 #define AI const IndepADvar<Double>&
204 #define T template<typename Double>
231 #define F ADvari<Double>&
278 template<
typename Double>ADvari<Double>&
ADf1(Double f, Double g,
const IndepADvar<Double> &x);
279 template<
typename Double>ADvari<Double>&
ADf2(Double f, Double gx, Double gy,
280 const IndepADvar<Double> &x,
const IndepADvar<Double> &y);
281 template<
typename Double>ADvari<Double>&
ADfn(Double f,
int n,
282 const IndepADvar<Double> *x,
const Double *g);
284 template<
typename Double> IndepADvar<Double>&
ADvar_operatoreq(IndepADvar<Double>*,
285 const ADvari<Double>&);
286 template<
typename Double> ADvar<Double>&
ADvar_operatoreq(ADvar<Double>*,
const ADvari<Double>&);
287 template<
typename Double>
void AD_Const(
const IndepADvar<Double>&);
288 template<
typename Double>
void AD_Const1(Double*,
const IndepADvar<Double>&);
289 template<
typename Double> ADvari<Double>&
ADf1(Double, Double,
const ADvari<Double>&);
290 template<
typename Double> ADvari<Double>&
ADf2(Double, Double, Double,
291 const ADvari<Double>&,
const ADvari<Double>&);
292 template<
typename Double> ADvari<Double>&
ADf2(Double, Double, Double,
293 const IndepADvar<Double>&,
const ADvari<Double>&);
294 template<
typename Double> ADvari<Double>&
ADf2(Double, Double, Double,
295 const ADvari<Double>&,
const IndepADvar<Double>&);
296 template<
typename Double> Double
val(
const ADvari<Double>&);
298 template<
typename Double>
class
304 #ifdef RAD_AUTO_AD_Const
306 #ifdef RAD_Const_WARN
307 mutable const IndepADVar *padv;
310 mutable const IndepADVar *padv;
311 #endif //RAD_Const_WARN
313 inline void ADvari_padv(
const IndepADVar *v) {
316 #endif //RAD_AUTO_AD_Const
320 static int gcgen_cur, last_opno, zap_gcgen, zap_gcgen1, zap_opno;
321 static FILE *debug_file;
330 Last_ADvari = &this->Next;
333 void *
operator new(
size_t len) {
336 rv->gcgen = gcgen_cur;
337 rv->opno = ++last_opno;
338 if (last_opno == zap_opno && gcgen_cur == zap_gcgen)
339 printf(
"Got to opno %d\n", last_opno);
345 void operator delete(
void*) {}
347 inline ADvari(): Val(0.), aval(0)
Padvinit { Linkup(); }
348 #ifdef RAD_AUTO_AD_Const
349 friend class ADcontext<Double>;
350 friend class ADvar<Double>;
351 friend class ADvar1<Double>;
352 friend class ADvar1s<Double>;
353 friend class ADvar2<Double>;
354 friend class ADvar2q<Double>;
355 friend class ConstADvar<Double>;
356 ADvari(
const IndepADVar *, Double);
360 #define Ai const ADvari&
361 #define T1(r,f) F r f <>(Ai);
364 F r f <>(Ttype,Ai); \
365 F r f <>(Ai,Ttype); \
366 F r f <>(double,Ai); \
367 F r f <>(Ai,double); \
413 friend ADvari& ADf1<>(Double
f, Double
g,
const ADvari &x);
414 friend ADvari& ADf2<>(Double f, Double gx, Double gy,
const ADvari &x,
const ADvari &y);
415 friend ADvari& ADfn<>(Double f,
int n,
const IndepADVar *x,
const Double *g);
417 inline operator Double() {
return this->Val; }
418 inline operator Double()
const {
return this->Val; }
423 template<
typename Double>
class
429 ADvar1(Double val1,
const ADVari *c1): ADVari(val1), d(c1) {}
430 ADvar1(Double val1,
const Double *a1,
const ADVari *c1):
431 ADVari(val1), d(a1,this,c1) {}
432 #ifdef RAD_AUTO_AD_Const
433 typedef typename ADVari::IndepADVar IndepADVar;
435 ADvar1(
const IndepADVar*,
const IndepADVar&);
436 ADvar1(
const IndepADVar*,
const ADVari&);
437 ADvar1(
const Double val1,
const Double *a1,
const ADVari *c1,
const ADVar *v):
438 ADVari(val1), d(a1,this,c1) {
440 this->ADvari_padv(v);
446 template<
typename Double>
class
447 ConstADvari:
public ADvari<Double> {
458 inline ConstADvari(Double t): ADVari(t) { prevcad = lastcad; lastcad =
this; }
459 static void aval_reset(
void);
462 template<
typename Double>
class
465 static void AD_Const(
const IndepADvar&);
470 #ifdef RAD_AUTO_AD_Const
475 #elif defined(RAD_EQ_ALIAS)
480 #endif //RAD_AUTO_AD_Const
497 #ifdef RAD_AUTO_AD_Const //{
499 inline IndepADvar() { cv = 0; }
500 inline ~IndepADvar() {
514 #ifdef RAD_Const_WARN
515 inline operator ADVari&()
const {
516 ADVari *tcv = this->cv;
521 inline operator ADVari*()
const {
522 ADVari *tcv = this->cv;
527 #else //RAD_Const_WARN
528 inline operator ADVari&()
const {
return *this->cv; }
529 inline operator ADVari*()
const {
return this->cv; }
530 #endif //RAD_Const_WARN
532 inline Double
val()
const {
535 inline Double
adj()
const {
538 inline Double
adj(
int n)
const {
542 friend void AD_Const1<>(Double*,
const IndepADvar&);
544 friend ADVari& ADf1<>(Double, Double,
const IndepADvar&);
545 friend ADVari& ADf2<>(Double, Double, Double,
const IndepADvar&,
const IndepADvar&);
546 friend ADVari& ADf2<>(Double, Double, Double,
const ADVari&,
const IndepADvar&);
547 friend ADVari& ADf2<>(Double, Double, Double,
const IndepADvar&,
const ADVari&);
562 #define Ai const ADVari&
563 #define AI const IndepADvar&
577 #define T1(f) friend ADVari& f<> (AI);
579 #define F friend ADVari&
628 template<
typename Double>
class
629 ADvar:
public IndepADvar<Double> {
640 if (ConstADVari::cadc.fpval_implies_const)
641 x =
new ConstADVari(d);
643 #ifdef RAD_AUTO_AD_Const //{
644 x =
new ADVari((IndepADVar*)
this, d);
645 x->ADvari_padv(
this);
657 inline ADvar(
double i) { ADvar_ctr(Double(i)); }
658 inline ADvar(
int i) { ADvar_ctr(Double(i)); }
659 inline ADvar(
long i) { ADvar_ctr(Double(i)); }
661 #ifdef RAD_AUTO_AD_Const //{{
662 inline ADvar(IndepADVar &x) {
663 this->cv = x.cv ?
new ADVar1(
this, x) : 0;
665 inline ADvar(ADVari &x) { this->cv = &x; x.ADvari_padv(
this); }
666 inline ADvar& operator=(IndepADVar &x) {
669 this->cv =
new ADVar1(
this,x);
672 inline ADvar& operator=(ADVari &x) {
675 this->cv =
new ADVar1(
this, x);
679 friend ADvar& ADvar_operatoreq<>(ADvar*,
const ADVari&);
682 inline ADvar(
const IndepADVar &x) {
683 this->cv = (ADVari*)x.cv;
685 inline ADvar(
const ADVari &x) { this->cv = (ADVari*)&x; }
686 inline ADvar& operator=(IndepADVar &x) {
687 this->cv = (ADVari*)x.cv;
return *
this;
689 inline ADvar& operator=(
const ADVari &x) { this->cv = (ADVari*)&x;
return *
this; }
691 ADvar(const IndepADVar &x) {
693 this->cv =
new ADVar1(x.cv->Val, &this->cv->adc.One, x.cv);
700 this->cv =
new ADVar1(x.
cv->Val, &this->cv->adc.One, (ADVari*)x.
cv);
706 this->cv =
new ADVar1(x.
Val, &this->cv->adc.One, &x);
711 ADvar& operator=(Double);
712 ADvar& operator+=(
const ADVari&);
713 ADvar& operator+=(Double);
714 ADvar& operator-=(
const ADVari&);
715 ADvar& operator-=(Double);
716 ADvar& operator*=(
const ADVari&);
717 ADvar& operator*=(Double);
718 ADvar& operator/=(
const ADVari&);
719 ADvar& operator/=(Double);
721 {
return ConstADVari::cadc.fpval_implies_const; }
723 { ConstADVari::cadc.fpval_implies_const = newval; }
725 bool oldval = ConstADVari::cadc.fpval_implies_const;
726 ConstADVari::cadc.fpval_implies_const = newval;
730 static inline void aval_reset() { ConstADVari::aval_reset(); }
739 template<
typename Double>
743 template<
typename Double>
746 template<
typename Double>
class
747 ConstADvar:
public ADvar<Double> {
764 void ConstADvar_ctr(Double);
774 #ifdef RAD_NO_CONST_UPDATE
788 #define ADvar_nd ADvar
790 template<
typename Double>
class
791 ADvar1s:
public ADvar1<Double> {
796 ADvar1s(Double val1, Double a1,
const ADVari *c1): ADVar1(val1,&a,c1), a(a1) {}
797 #ifdef RAD_AUTO_AD_Const
799 ADvar1s(Double val1, Double a1,
const ADVari *c1,
const ADVar *v):
800 ADVar1(val1,&a,c1,v), a(a1) {}
804 template<
typename Double>
class
805 ADvar2:
public ADvari<Double> {
811 ADvar2(Double val1,
const ADVari *Lcv,
const Double *Lc,
812 const ADVari *Rcv,
const Double *Rc):
814 dR.
next = DErp::LastDerp;
816 DErp::LastDerp = &dL;
823 #ifdef RAD_AUTO_AD_Const
825 ADvar2(Double val1,
const ADVari *Lcv,
const Double *Lc,
826 const ADVari *Rcv,
const Double *Rc, ADVar *v):
828 dR.
next = DErp::LastDerp;
830 DErp::LastDerp = &dL;
837 this->ADvari_padv(v);
842 template<
typename Double>
class
843 ADvar2q:
public ADvar2<Double> {
849 ADvar2q(Double val1, Double Lp, Double Rp,
const ADVari *Lcv,
const ADVari *Rcv):
850 ADVar2(val1), a(Lp), b(Rp) {
851 this->dR.next = DErp::LastDerp;
852 this->dL.next = &this->dR;
853 DErp::LastDerp = &this->dL;
858 this->dL.b = this->dR.b =
this;
860 #ifdef RAD_AUTO_AD_Const
862 ADvar2q(Double val1, Double Lp, Double Rp,
const ADVari *Lcv,
863 const ADVari *Rcv,
const ADVar *v):
864 ADVar2(val1), a(Lp), b(Rp) {
865 this->dR.next = DErp::LastDerp;
866 this->dL.next = &this->dR;
867 DErp::LastDerp = &this->dL;
872 this->dL.b = this->dR.b =
this;
874 this->ADvari_padv(v);
879 template<
typename Double>
class
880 ADvarn:
public ADvari<Double> {
888 ADvarn(Double val1,
int n1,
const IndepADVar *x,
const Double *g):
889 ADVari(val1), n(n1) {
894 a1 = a = (Double*)ADVari::adc.Memalloc(n*
sizeof(*a));
895 d1 = Da = (DErp*)ADVari::adc.Memalloc(n*
sizeof(DErp));
896 dlast = DErp::LastDerp;
897 for(i = 0; i < n1; i++, d1++) {
905 DErp::LastDerp = dlast;
909 template<
typename Double>
912 template<
typename Double>
913 inline int operator<(const ADvari<Double> &L,
const ADvari<Double> &
R) {
return L.Val <
R.Val; }
914 template<
typename Double>
915 inline int operator<(const ADvari<Double> &L, Double
R) {
return L.Val <
R; }
916 template<
typename Double>
917 inline int operator<(Double L, const ADvari<Double> &
R) {
return L <
R.Val; }
919 template<
typename Double>
920 inline int operator<=(const ADvari<Double> &L,
const ADvari<Double> &
R) {
return L.Val <=
R.Val; }
921 template<
typename Double>
922 inline int operator<=(const ADvari<Double> &L, Double
R) {
return L.Val <=
R; }
923 template<
typename Double>
924 inline int operator<=(Double L, const ADvari<Double> &
R) {
return L <=
R.Val; }
926 template<
typename Double>
928 template<
typename Double>
930 template<
typename Double>
933 template<
typename Double>
935 template<
typename Double>
937 template<
typename Double>
940 template<
typename Double>
942 template<
typename Double>
944 template<
typename Double>
947 template<
typename Double>
949 template<
typename Double>
951 template<
typename Double>
954 template<
typename Double>
957 return Mbase + (Mleft -= len);
958 return new_ADmemblock(len);
961 template<
typename Double>
967 template<
typename Double>
974 template<
typename Double>
993 #ifndef RAD_DEBUG_gcgen1
994 #define RAD_DEBUG_gcgen1 -1
1011 Mbase = (
char*)First->
memblk;
1012 Mleft =
sizeof(First->memblk);
1014 #ifdef RAD_DEBUG_BLOCKKEEP
1015 rad_busy_blocks = 0;
1021 template<
typename Double>
void*
1025 #ifdef RAD_AUTO_AD_Const
1028 #ifdef RAD_Const_WARN
1038 ADVari::Last_ADvari = &ADVari::First_ADvari;
1039 #ifdef RAD_DEBUG_BLOCKKEEP
1040 Mleft = rad_mleft_save;
1041 if (Mleft <
sizeof(First->memblk))
1042 _uninit_f2c(Mbase + Mleft,
1043 UninitType<Double>::utype,
1044 (
sizeof(First->memblk) - Mleft)
1046 if ((mb = Busy->
next)) {
1048 for(;; mb = mb->
next) {
1050 UninitType<Double>::utype,
1051 sizeof(First->memblk)
1057 rad_Oldcurmb = Busy;
1058 if (rad_busy_blocks >= RAD_DEBUG_BLOCKKEEP) {
1059 rad_busy_blocks = 0;
1063 for(mb = Busy; mb != mb0; mb = mb1) {
1070 Mbase = (
char*)First->
memblk;
1071 Mleft =
sizeof(First->memblk);
1078 for(mb = Busy; mb != mb0; mb = mb1) {
1085 Mbase = (
char*)First->
memblk;
1086 Mleft =
sizeof(First->memblk);
1088 #ifdef RAD_AUTO_AD_Const // {
1089 if ((a = ADVari::First_ADvari)) {
1093 #ifdef RAD_Const_WARN
1094 if ((i = a->opno) > 0)
1097 v->
cv = cv =
new ADVari(v, a->
Val);
1101 v->
cv =
new ADVari(v, a->
Val);
1107 #endif // } RAD_AUTO_AD_Const
1109 return Mbase + (Mleft -= len);
1116 #ifdef RAD_DEBUG_BLOCKKEEP
1121 return (Mbase = (
char*)x->
memblk) +
1122 (Mleft =
sizeof(First->memblk) - len);
1125 template<
typename Double>
void
1135 rad_mleft_save = Mleft;
1138 len = n *
sizeof(Double);
1144 else if (n > nmax) {
1158 Mleft = rad_mleft_save;
1163 *ADVari::Last_ADvari = 0;
1164 for(a = ADVari::First_ADvari;
a; a = a->
Next) {
1165 d = a->
aval = (Double*)Memalloc(len);
1167 do *d = 0.;
while(++d < de);
1170 d = c->
aval = (Double*)Memalloc(len);
1172 do *d = 0.;
while(++d < de);
1177 for(a = ADVari::First_ADvari;
a; a = a->
Next)
1180 else for(a = ADVari::First_ADvari;
a; a = a->
Next) {
1183 do *d = 0.;
while(++d < de);
1188 if (ADVari::gcgen_cur == ADVari::zap_gcgen1) {
1190 if (!(fname = getenv(
"RAD_DEBUG_FILE")))
1191 fname =
"rad_debug.out";
1195 ADVari::debug_file = fopen(fname,
"w");
1196 ADVari::zap_gcgen1 = -1;
1201 template<
typename Double>
void
1205 #ifdef RAD_AUTO_AD_Const
1208 #ifdef RAD_Const_WARN
1214 ADVari::adc.derp_init(1);
1215 if ((d = DErp::LastDerp) != 0) {
1218 if (ADVari::debug_file)
1220 fprintf(ADVari::debug_file,
"%d\t%d\t%g + %g * %g",
1223 fprintf(ADVari::debug_file,
" = %g\n", *d->
c->
aval);
1224 }
while((d = d->
next));
1228 while((d = d->
next));
1231 if (ADVari::debug_file) {
1232 fclose(ADVari::debug_file);
1233 ADVari::debug_file = 0;
1235 ADVari::gcgen_cur++;
1236 ADVari::last_opno = 0;
1240 template<
typename Double>
void
1245 #ifdef RAD_AUTO_AD_Const
1248 #ifdef RAD_Const_WARN
1254 ADVari::adc.derp_init(1);
1256 if ((d = DErp::LastDerp) != 0) {
1257 for(i = 0; i < n; i++)
1258 *V[i]->cv->
aval = w[i];
1260 if (ADVari::debug_file)
1262 fprintf(ADVari::debug_file,
"%d\t%d\t%g + %g * %g",
1265 fprintf(ADVari::debug_file,
" = %g\n", *d->
c->
aval);
1266 }
while((d = d->
next));
1270 while((d = d->
next));
1273 if (ADVari::debug_file) {
1274 fclose(ADVari::debug_file);
1275 ADVari::debug_file = 0;
1277 if (ADVari::debug_file)
1278 fflush(ADVari::debug_file);
1279 ADVari::gcgen_cur++;
1280 ADVari::last_opno = 0;
1284 template<
typename Double>
void
1290 Double
A, *
D, *D1, *De, *wi;
1291 #ifdef RAD_AUTO_AD_Const
1294 #ifdef RAD_Const_WARN
1300 ADVari::adc.derp_init(n);
1304 if ((d = DErp::LastDerp) != 0) {
1305 for(i = 0; i < n; i++) {
1309 for(ii = 0; ii < ni; ++ii)
1310 Vi[ii]->cv->
aval[i] = wi[ii];
1313 if (ADVari::debug_file)
1319 for(i = 0; i < n; ++i, ++
D, ++D1) {
1320 fprintf(ADVari::debug_file,
"%d:\t%d\t%d\t%g + %g * %g",
1321 i, d->
c->opno, d->
b->opno, *D, A, *D1);
1323 fprintf(ADVari::debug_file,
" = %g\n", *D);
1325 }
while((d = d->
next));
1333 do *D++ += A * *D1++;
while(D < De);
1335 while((d = d->
next));
1338 if (ADVari::debug_file) {
1339 fclose(ADVari::debug_file);
1340 ADVari::debug_file = 0;
1342 if (ADVari::debug_file)
1343 fflush(ADVari::debug_file);
1344 ADVari::gcgen_cur++;
1345 ADVari::last_opno = 0;
1349 template<
typename Double>
void
1357 template<
typename Double>
1363 template<
typename Double>
1366 cv =
new ADVari(Double(i));
1369 template<
typename Double>
1372 cv =
new ADVari(Double(i));
1375 template<
typename Double>
1378 cv =
new ADVari(Double(i));
1381 template<
typename Double>
1384 this->cv =
new ConstADVari(0.);
1387 template<
typename Double>
void
1390 this->cv =
new ConstADVari(d);
1393 template<
typename Double>
1396 ConstADVari *y =
new ConstADVari(x.
cv->Val);
1401 template<
typename Double>
1404 ConstADVari *y =
new ConstADVari(x.
cv->Val);
1409 template<
typename Double>
1412 ConstADVari *y =
new ConstADVari(x.
Val);
1417 template<
typename Double>
1423 ConstADVari *ncv =
new ConstADVari(v.
val());
1424 #ifdef RAD_AUTO_AD_Const
1430 template<
typename Double>
1437 template<
typename Double>
1448 #ifdef RAD_AUTO_AD_Const
1450 template<
typename Double>
1453 this->ADvari_padv(x);
1457 template<
typename Double>
1459 ADVari(y.cv->Val), d((const Double*)&ADcontext<Double>::One, (ADVari*)this, y.cv)
1461 this->ADvari_padv(x);
1464 template<
typename Double>
1466 ADVari(y.Val), d((const Double*)&ADcontext<Double>::One, this, &y)
1468 this->ADvari_padv(x);
1473 template<
typename Double>
1481 template<
typename Double>
1492 template<
typename Double>
1496 #ifdef RAD_AUTO_AD_Const
1499 this->cv =
new ADVari(
this,d);
1501 this->cv =
new ADVari(d);
1506 template<
typename Double>
1510 #ifdef RAD_AUTO_AD_Const
1513 this->cv =
new ADVari(
this,d);
1515 this->cv = ConstADVari::cadc.fpval_implies_const
1516 ?
new ConstADVari(d)
1522 template<
typename Double>
1528 template<
typename Double>
1534 #ifdef RAD_AUTO_AD_Const
1535 #define RAD_ACA ,this
1540 template<
typename Double>
1543 ADVari *Lcv = this->cv;
1548 template<
typename Double>
1554 template<
typename Double>
1557 ADVari *tcv = this->cv;
1558 this->cv =
new ADVar1(tcv->
Val + R, &tcv->
adc.One, tcv
RAD_ACA);
1562 template<
typename Double>
1568 template<
typename Double>
1574 template<
typename Double>
1577 ADVari *Lcv = this->cv;
1582 template<
typename Double>
1588 template<
typename Double>
1591 ADVari *tcv = this->cv;
1592 this->cv =
new ADVar1(tcv->
Val - R, &tcv->
adc.One, tcv
RAD_ACA);
1596 template<
typename Double>
1602 template<
typename Double>
1608 template<
typename Double>
1611 ADVari *Lcv = this->cv;
1616 template<
typename Double>
1622 template<
typename Double>
1625 ADVari *Lcv = this->cv;
1630 template<
typename Double>
1636 template<
typename Double>
1639 Double Lv = L.
Val, Rv = R.
Val, pL = 1. / Rv, q = Lv/Rv;
1643 template<
typename Double>
1646 ADVari *Lcv = this->cv;
1647 Double Lv = Lcv->
Val, Rv = R.
Val, pL = 1. / Rv, q = Lv/Rv;
1652 template<
typename Double>
1658 template<
typename Double>
1661 Double recip = 1. / R.
Val;
1662 Double q = L * recip;
1666 template<
typename Double>
1669 ADVari *Lcv = this->cv;
1674 template<
typename Double>
1681 template<
typename Double>
1688 template<
typename Double>
1695 template<
typename Double>
1706 template<
typename Double>
1713 template<
typename Double>
1720 template<
typename Double>
1723 Double x = L.
Val, y = R.
Val, t = x*x + y*y;
1727 template<
typename Double>
1730 Double y = R.
Val, t = x*x + y*y;
1734 template<
typename Double>
1737 Double x = L.
Val, t = x*x + y*y;
1741 template<
typename Double>
1748 template<
typename Double>
1756 template<
typename Double>
1764 template<
typename Double>
1771 template<
typename Double>
1779 template<
typename Double>
1787 template<
typename Double>
1793 template<
typename Double>
1799 template<
typename Double>
1803 rcv->
d.a = &rcv->
Val;
1808 template<
typename Double>
1815 template<
typename Double>
1818 static double num = 1. /
std::log(10.);
1823 template<
typename Double>
1830 template<
typename Double>
1837 template<
typename Double>
1844 template<
typename Double>
1850 template<
typename Double>
1856 template<
typename Double>
1863 template<
typename Double>
1870 template<
typename Double>
1877 template<
typename Double>
1882 if ((t = v.
Val) < 0) {
1889 template<
typename Double>
1896 if ((t = v.
Val) < 0) {
1903 template<
typename Double>
1909 template<
typename Double>
1910 inline ADvari<Double>&
1915 template<
typename Double>
1921 template<
typename Double>
1927 template<
typename Double>
1933 template<
typename Double>
1939 template<
typename Double>
1945 template<
typename Double>
1946 inline ADvari<Double>&
1951 template<
typename Double>
1958 #define A (ADvari<Double>*)
1959 #ifdef RAD_Const_WARN
1960 #define C(x) (((x)->opno < 0) ? RAD_Const_Warn(x) : 0, *A x)
1964 #define T template<typename Double> inline
1965 #define F ADvari<Double>&
1966 #define Ai const ADvari<Double>&
1967 #define AI const IndepADvar<Double>&
1970 T r f(Ai L, AI R) { return f(L, C(R.cv)); }\
1971 T r f(AI L, Ai R) { return f(C(L.cv), R); }\
1972 T r f(AI L, AI R) { return f(C(L.cv), C(R.cv)); }\
1973 T r f(AI L, D R) { return f(C(L.cv), R); }\
1974 T r f(Ai L, Dtype R) { return f(L, (D)R); }\
1975 T r f(AI L, Dtype R) { return f(C(L.cv), (D)R); }\
1976 T r f(Ai L, long R) { return f(L, (D)R); }\
1977 T r f(AI L, long R) { return f(C(L.cv), (D)R); }\
1978 T r f(Ai L, int R) { return f(L, (D)R); }\
1979 T r f(AI L, int R) { return f(C(L.cv), (D)R); }\
1980 T r f(D L, AI R) { return f(L, C(R.cv)); }\
1981 T r f(Dtype L, Ai R) { return f((D)L, R); }\
1982 T r f(Dtype L, AI R) { return f((D)L, C(R.cv)); }\
1983 T r f(long L, Ai R) { return f((D)L, R); }\
1984 T r f(long L, AI R) { return f((D)L, C(R.cv)); }\
1985 T r f(int L, Ai R) { return f((D)L, R); }\
1986 T r f(int L, AI R) { return f((D)L, C(R.cv)); }
2007 T F f(AI x) { return f(C(x.cv)); }
ADvar & operator+=(const ADVari &)
ADT_RAD ADvari< double > Ai
Double val(const ADvari< Double > &)
ADvari< Double > & operator-(const ADvari< Double > &T)
ADvari< Double > & max(const ADvari< Double > &L, const ADvari< Double > &R)
ADvari< Double > & operator/(const ADvari< Double > &L, const ADvari< Double > &R)
BigUInt< n > operator+(BigUInt< n > const &a, BigUInt< n > const &b)
ADvari< Double > & atan(const ADvari< Double > &v)
ConstADvar & operator=(ADVari &d)
void AD_Const1(Double *, const IndepADvar< Double > &)
ADT_RAD IndepADvar< double > AI
ADvarn(Double val1, int n1, const IndepADVar *x, const Double *g)
ADvari< Double > & ADf1(Double f, Double g, const IndepADvar< Double > &x)
Sacado::RadVec::ADvar< double > ADVar
ADvari< Double > & log(const ADvari< Double > &v)
IndepADvar & operator=(IndepADvar &x)
static CADcontext< Double > cadc
ADVari::IndepADVar IndepADVar
IndepADvar< Double > IndepADVar
ADmemblock< Double > ADMemblock
static bool setget_fpval_implies_const(bool newval)
ADvari< Double > & ADfn(Double f, int n, const IndepADvar< Double > *x, const Double *g)
void AD_Const1(Double *, const IndepADvar< Double > &)
void AD_Const(const IndepADvar< Double > &)
KOKKOS_INLINE_FUNCTION mpl::enable_if_c< ExprLevel< Expr< T1 > >::value==ExprLevel< Expr< T2 > >::value, Expr< PowerOp< Expr< T1 >, Expr< T2 > > > >::type pow(const Expr< T1 > &expr1, const Expr< T2 > &expr2)
static void Weighted_Gradcomp(size_t, ADVar **, Double *)
ADvari< Double > & ADf2(Double f, Double gx, Double gy, const IndepADvar< Double > &x, const IndepADvar< Double > &y)
bool operator!=(const Allocator< T > &a_t, const Allocator< U > &a_u)
ADvar & operator/=(const ADVari &)
ADvari< Double > & sinh(const ADvari< Double > &v)
ADvari< Double > & exp(const ADvari< Double > &v)
ADvari< Double > & acos(const ADvari< Double > &v)
ConstADvari< Double > ConstADVari
ADvar1(Double val1, const Double *a1, const ADVari *c1)
static void Outvar_Gradcomp(ADVar &v)
ADvari< Double > & cosh(const ADvari< Double > &v)
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
ADVar::IndepADVar IndepADVar
void ConstADvar_ctr(Double)
static void aval_reset(void)
bool operator>(BigUInt< n > const &a, BigUInt< n > const &b)
ADvar & operator-=(const ADVari &)
IndepADvar< Double > & ADvar_operatoreq(IndepADvar< Double > *, const ADvari< Double > &)
static int rad_need_reinit
ADvar & operator=(const ADVari &x)
bool operator>=(BigUInt< n > const &a, BigUInt< n > const &b)
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)
static void Weighted_Gradcomp(size_t n, ADVar **v, Double *w)
static void Outvar_Gradcomp(ADvar &v)
void * new_ADmemblock(size_t)
int RAD_Const_Warn(void *v)
static void Weighted_Gradcomp(size_t n, ADvar **v, Double *w)
static void Weighted_GradcompVec(size_t, size_t *, ADVar ***, Double **)
ADvari< Double > & tan(const ADvari< Double > &v)
ADvari< Double > & fabs(const ADvari< Double > &v)
ADvari< Double > & asin(const ADvari< Double > &v)
static void AD_Const(const IndepADvar &)
ADvari< Double > & abs(const ADvari< Double > &v)
ADvari< Double > & atanh(const ADvari< Double > &v)
ADvari< Double > & pow(const ADvari< Double > &L, const ADvari< Double > &R)
IndepADvar< Double > IndepADVar
IndepADVar::ADVari ADVari
atan2(expr1.val(), expr2.val())
ADvar & operator*=(const ADVari &)
static void set_fpval_implies_const(bool newval)
ADVar::ConstADVari ConstADVari
ADvari< Double > & operator+(const ADvari< Double > &T)
bool operator==(const Handle< T > &h1, const Handle< T > &h2)
Compare two handles.
ADvari< Double > & log10(const ADvari< Double > &v)
ADvari< Double > & acosh(const ADvari< Double > &v)
ADvari< Double > & sqrt(const ADvari< Double > &v)
ADvari< Double > & atan2(const ADvari< Double > &L, const ADvari< Double > &R)
ConstADvar & operator=(Double d)
ADvari< Double > & sin(const ADvari< Double > &v)
Turn ADvar into a meta-function class usable with mpl::apply.
static ADcontext< Double > adc
static bool get_fpval_implies_const(void)
ADvari< Double > & tanh(const ADvari< Double > &v)
ADvari< Double > & operator*(const ADvari< Double > &L, const ADvari< Double > &R)
static ConstADvari * lastcad
ADvari< Double > & asinh(const ADvari< Double > &v)
ADvari< Double > & min(const ADvari< Double > &L, const ADvari< Double > &R)
ScalarType< value_type >::type scalar_type
static void Outvar_Gradcomp(ADVar &)
void AD_Const(const IndepADvar &v)
ADvari< Double > & cos(const ADvari< Double > &v)
static void Weighted_GradcompVec(size_t n, size_t *np, ADvar ***v, Double **w)
ADvar1s(Double val1, Double a1, const ADVari *c1)
ADvar1(Double val1, const ADVari *c1)
static void Weighted_GradcompVec(size_t n, size_t *np, ADVar ***v, Double **w)
static ADvari ** Last_ADvari