Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_rad2.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Sacado Package
5 // Copyright (2007) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25 // (etphipp@sandia.gov).
26 //
27 // ***********************************************************************
28 // @HEADER
29 
30 // Extension of the RAD package (Reverse Automatic Differentiation) --
31 // a package specialized for function and gradient evaluations -- to
32 // Hessian-vector products.
33 // This variant is for Hessian-vector products of "double" variables, and
34 // Sacado::Rad2d::ADvar should be equivalent to Sacado::Rad2::ADvar<double>,
35 // but this nontemplated code may easier to understand. It relies on ops
36 // implemented in Sacado_radops2.cpp.
37 // Written in 2007 by David M. Gay at Sandia National Labs, Albuquerque, NM.
38 
39 #ifndef SACADO_RAD2_H
40 #define SACADO_RAD2_H
41 
42 #include <stddef.h>
43 #include <Sacado_cmath.hpp>
44 
45 #include "Sacado_ConfigDefs.h"
46 
47 #if defined(RAD_DEBUG_BLOCKKEEP) && !defined(HAVE_SACADO_UNINIT)
48 #undef RAD_DEBUG_BLOCKKEEP
49 #endif
50 
51 #ifndef SACADO_NO_NAMESPACE
52 namespace Sacado {
53 namespace Rad2d { // "2" for 2nd derivatives, "d" for "double"
54 #endif
55 
56 // -DNO_USING_STDCC is needed, e.g., with Sun CC 5.7
57 #ifndef RAD_NO_USING_STDCC
58  // Bring math functions into scope
59  using std::exp;
60  using std::log;
61  using std::log10;
62  using std::sqrt;
63  using std::cos;
64  using std::sin;
65  using std::tan;
66  using std::acos;
67  using std::asin;
68  using std::atan;
69  using std::cosh;
70  using std::sinh;
71  using std::tanh;
72  using std::abs;
73  using std::fabs;
74  using std::atan2;
75  using std::pow;
76 #endif //NO_USING_STDCC
77 
78  class ADvar;
79  class ADvari;
80  class ADvar1;
81  class ADvar2;
82  class ConstADvar;
83  class Derp;
84  class IndepADvar;
85 
86  struct
87 ADmemblock { // We get memory in ADmemblock chunks and never give it back,
88  // but reuse it once computations start anew after call(s) on
89  // ADcontext::Gradcomp() or ADcontext::Weighted_Gradcomp().
91  double memblk[2000];
92  };
93 
94  struct
96  enum { Gulp = 1021 };
97  ADvari_block *next, *prev;
99  ADvari *pADvari[Gulp];
100  };
101 
102  class
103 ADcontext { // A singleton class: one instance in radops.c
104  ADmemblock *Busy, *Free;
105  char *Mbase;
106  size_t Mleft;
107  ADvari **Ailimit, **Ainext;
108  ADvari_block *Aibusy, *Aifree;
111  void *new_ADmemblock(size_t);
112  void new_ADvari_block();
113  public:
114  ADcontext();
115  void *Memalloc(size_t len);
116  static void Gradcomp(int);
117  static inline void Gradcomp() { Gradcomp(1); }
118  static void Hvprod(int, ADvar**, double*, double*);
119  static void Weighted_Gradcomp(int, ADvar**, double*);
120  inline void ADvari_record(ADvari *x) {
121  if (Ainext >= Ailimit)
122  new_ADvari_block();
123  *Ainext++ = x;
124  }
125  };
126 
127 inline void *ADcontext::Memalloc(size_t len) {
128  if (Mleft >= len)
129  return Mbase + (Mleft -= len);
130  return new_ADmemblock(len);
131  }
132 
133  class
134 CADcontext: public ADcontext {
135  protected:
137  public:
138  friend class ADvar;
139  CADcontext(): ADcontext() { fpval_implies_const = false; }
140  static const double One, negOne;
141  };
142 
143  class
144 Derp { // one derivative-propagation operation
145  public:
146  friend class ADvarn;
147  static Derp *LastDerp;
149  const double *a;
150  const ADvari *b;
151  mutable ADvari *c;
152  void *operator new(size_t);
153  void operator delete(void*) {} /*Should never be called.*/
154  inline Derp(){};
155  Derp(const ADvari *);
156  Derp(const double *, const ADvari *);
157  Derp(const double *, const ADvari *, const ADvari *);
158  /* c->aval += a * b->aval; */
159  };
160 
161 inline Derp::Derp(const ADvari *c1): c((ADvari*)c1) {
162  next = LastDerp;
163  LastDerp = this;
164  }
165 
166 inline Derp::Derp(const double *a1, const ADvari *c1):
167  a(a1), c((ADvari*)c1) {
168  next = LastDerp;
169  LastDerp = this;
170  }
171 
172 inline Derp::Derp(const double *a1, const ADvari *b1, const ADvari *c1):
173  a(a1), b(b1), c((ADvari*)c1) {
174  next = LastDerp;
175  LastDerp = this;
176  }
177 
190  };
191 
192  extern ADvari& ADf1(double f, double g, double h, const ADvari &x);
193  extern ADvari& ADf2(double f, double gx, double gy, double hxx,
194  double hxy, double hyy, const ADvari &x, const ADvari &y);
195  extern ADvari& ADfn(double f, int n, const ADvar *x, const double *g, const double *h);
196 
197  class
198 ADvari { // implementation of an ADvar
199  public:
200  static ADcontext adc;
202  double Val; // result of this operation
203  mutable double aval; // adjoint -- partial of final result w.r.t. this Val
204  mutable double dO; // deriv of op w.r.t. t in x + t*p
205  mutable double aO; // adjoint (in Hv computation) of op
206  mutable double adO; // adjoint (in Hv computation) of dO
207  void *operator new(size_t len) { return ADvari::adc.Memalloc(len); }
208  void operator delete(void*) {} /*Should never be called.*/
209  inline ADvari(Advari_Opclass oc, double t):
210  opclass(oc), Val(t), aval(0.), dO(0.)
211  { if (oc != Hv_const) ADvari::adc.ADvari_record(this); }
212  inline ADvari(Advari_Opclass oc, double t, double ta):
213  opclass(oc), Val(t), aval(ta), dO(0.)
214  { if (oc != Hv_const) ADvari::adc.ADvari_record(this); }
215  private:
216  inline ADvari(): Val(0.), aval(0.), dO(0.) {} // prevent construction without value (?)
217  public:
218  friend class ConstADvari;
219 #ifdef RAD_AUTO_AD_Const
220  friend class ADcontext;
221  friend class ADvar1;
222  friend class ADvar;
223  friend class ConstADvar;
224  friend class IndepADvar;
225  private:
226  ADvari *Next;
227  static ADvari *First_ADvari, **Last_ADvari;
228  protected:
229  IndepADvar *padv;
230  public:
231  ADvari(const IndepADvar *, double);
232 #endif
233 #define F friend
234 #define R ADvari&
235 #define Ai const ADvari&
236 #define T1(r,f) F r f(Ai);
237 #define T2(r,f) \
238 F r f(Ai,Ai); \
239 F r f(double,Ai); \
240 F r f(Ai,double);
241  T1(R,operator+)
242  T2(R,operator+)
243  T1(R,operator-)
244  T2(R,operator-)
245  T2(R,operator*)
246  T2(R,operator/)
247  T1(R,abs)
248  T1(R,acos)
249  T1(R,acosh)
250  T1(R,asin)
251  T1(R,asinh)
252  T1(R,atan)
253  T1(R,atanh)
254  T2(R,atan2)
255  T2(R,max)
256  T2(R,min)
257  T1(R,cos)
258  T1(R,cosh)
259  T1(R,exp)
260  T1(R,log)
261  T1(R,log10)
262  T2(R,pow)
263  T1(R,sin)
264  T1(R,sinh)
265  T1(R,sqrt)
266  T1(R,tan)
267  T1(R,tanh)
268  T1(R,fabs)
269  T1(R,copy)
270  T2(int,operator<)
271  T2(int,operator<=)
272  T2(int,operator==)
273  T2(int,operator!=)
274  T2(int,operator>=)
275  T2(int,operator>)
276 #undef T2
277 #undef T1
278 #undef Ai
279 #undef R
280 #undef F
281 
282  friend ADvari& ADf1(double f, double g, double h, const ADvari &x);
283  friend ADvari& ADf2(double f, double gx, double gy, double hxx,
284  double hxy, double hyy, const ADvari &x, const ADvari &y);
285  friend ADvari& ADfn(double f, int n, const ADvar *x, const double *g, const double *h);
286  };
287 
288  inline void* Derp::operator new(size_t len) { return ADvari::adc.Memalloc(len); }
289 
290 
291  class
292 ADvar1: public ADvari { // simplest unary ops
293  public:
295  ADvar1(Advari_Opclass oc, double val1, const double *a1, const ADvari *c1):
296  ADvari(oc,val1), d(a1,this,c1) {}
297 #ifdef RAD_AUTO_AD_Const
298  ADvar1(const IndepADvar *, const IndepADvar &);
299  ADvar1(const IndepADvar *, const ADvari &);
300 #endif
301  };
302 
303  class
304 ConstADvari: public ADvari {
305  private:
307  ConstADvari() {}; // prevent construction without value (?)
308  static ConstADvari *lastcad;
309  public:
310  static CADcontext cadc;
311  inline void *operator new(size_t len) { return ConstADvari::cadc.Memalloc(len); }
312  inline ConstADvari(double t): ADvari(Hv_copy, t) { prevcad = lastcad; lastcad = this; }
313  static void aval_reset(void);
314  };
315 
316  class
318 {
319  private:
320  inline IndepADvar& operator=(const IndepADvar &x) {
321  /* private to prevent assignment */
322 #ifdef RAD_AUTO_AD_Const
323  if (cv)
324  cv->padv = 0;
325  cv = new ADvar1(this,x);
326  return *this;
327 #else
328 #ifdef RAD_EQ_ALIAS
329  cv = x.cv;
330  return *this;
331 #else
332  return ADvar_operatoreq(this,*x.cv);
333 #endif
334 #endif /* RAD_AUTO_AD_Const */
335  }
336  protected:
337  static void AD_Const(const IndepADvar&);
339  public:
340  typedef double value_type;
341  friend class ADvar;
342  friend class ADvar1;
343  friend class ADvarn;
344  friend class ADcontext;
345  IndepADvar(double);
346  IndepADvar(int);
347  IndepADvar(long);
348  IndepADvar& operator=(double);
349 #ifdef RAD_AUTO_AD_Const
350  inline IndepADvar(const IndepADvar &x) { cv = x.cv ? new ADvar1(this, x) : 0; };
351  inline IndepADvar() { cv = 0; }
352  inline ~IndepADvar() {
353  if (cv)
354  cv->padv = 0;
355  }
356 #else
357  inline IndepADvar() {
358 #ifndef RAD_EQ_ALIAS
359  cv = 0;
360 #endif
361  }
362  inline ~IndepADvar() {}
363  friend IndepADvar& ADvar_operatoreq(IndepADvar*, const ADvari&);
364 #endif
365 
366  friend void AD_Const(const IndepADvar&);
367 
368  inline operator ADvari&() { return *cv; }
369  inline operator ADvari&() const { return *(ADvari*)cv; }
370 
371  inline double val() const { return cv->Val; }
372  inline double adj() const { return cv->aval; }
373  static inline void Gradcomp(int wantgrad)
374  { ADcontext::Gradcomp(wantgrad); }
375  static inline void Gradcomp()
376  { ADcontext::Gradcomp(1); }
377  static inline void Hvprod(int n, ADvar **vp, double *v, double *hv)
378  { ADcontext::Hvprod(n, vp, v, hv); }
379  static inline void aval_reset() { ConstADvari::aval_reset(); }
380  static inline void Weighted_Gradcomp(int n, ADvar **v, double *w)
381  { ADcontext::Weighted_Gradcomp(n, v, w); }
382 
383 
384 #define Ai const ADvari&
385 #define AI const IndepADvar&
386 #define T2(r,f) \
387  r f(AI,AI);\
388  r f(Ai,AI);\
389  r f(AI,Ai);\
390  r f(double,AI);\
391  r f(AI,double);
392 #define T1(f) friend ADvari& f(AI);
393 
394 #define F friend ADvari&
395 T2(F, operator+)
396 T2(F, operator-)
397 T2(F, operator*)
398 T2(F, operator/)
399 T2(F, atan2)
400 T2(F, max)
401 T2(F, min)
402 T2(F, pow)
403 #undef F
404 #define F friend int
405 T2(F, operator<)
406 T2(F, operator<=)
407 T2(F, operator==)
408 T2(F, operator!=)
409 T2(F, operator>=)
410 T2(F, operator>)
411 
412 T1(operator+)
413 T1(operator-)
414 T1(abs)
415 T1(acos)
416 T1(acosh)
417 T1(asin)
418 T1(asinh)
419 T1(atan)
420 T1(atanh)
421 T1(cos)
422 T1(cosh)
423 T1(exp)
424 T1(log)
425 T1(log10)
426 T1(sin)
427 T1(sinh)
428 T1(sqrt)
429 T1(tan)
430 T1(tanh)
431 T1(fabs)
432 T1(copy)
433 
434 #undef T1
435 #undef T2
436 #undef F
437 #undef Ai
438 #undef AI
439 
440  };
441 
442  class
443 ADvar: public IndepADvar { // an "active" variable
444  void ADvar_ctr(double d);
445  public:
446  inline ADvar() { /* cv = 0; */ }
447  inline ADvar(double d) { ADvar_ctr(d); }
448  inline ADvar(int i) { ADvar_ctr((double)i); }
449  inline ADvar(long i) { ADvar_ctr((double)i); }
450  inline ~ADvar() {}
451 #ifdef RAD_AUTO_AD_Const
452  friend class ADvar1;
453  inline ADvar(const IndepADvar &x) { cv = x.cv ? new ADvar1(this, x) : 0; }
454  inline ADvar(ADvari &x) { cv = &x; x.padv = this; }
455  inline ADvar& operator=(const IndepADvar &x) {
456  if (cv)
457  cv->padv = 0;
458  cv = new ADvar1(this,x);
459  return *this;
460  }
461  inline ADvar& operator=(const ADvari &x) {
462  if (cv)
463  cv->padv = 0;
464  cv = new ADvar1(this, x);
465  return *this;
466  }
467 #else
468  friend ADvar& ADvar_operatoreq(ADvar*, const ADvari&);
469 #ifdef RAD_EQ_ALIAS
470  /* allow aliasing v and w after "v = w;" */
471  inline ADvar(const IndepADvar &x) { cv = x.cv; }
472  inline ADvar(const ADvari &x) { cv = (ADvari*)&x; }
473  inline ADvar& operator=(const ADvari &x) { cv = (ADvari*)&x; return *this; }
474  inline ADvar& operator=(const IndepADvar &x) { cv = (ADvari*)x.cv; return *this; }
475 #else
476  ADvar(const IndepADvar &x) { cv = x.cv ?
477  new ADvar1(Hv_copy, x.cv->Val, &CADcontext::One, x.cv) : 0; }
478  ADvar(const ADvari &x) { cv = new ADvar1(Hv_copy, x.Val, &CADcontext::One, &x); }
479  inline ADvar& operator=(const ADvari &x) { return ADvar_operatoreq(this,x); }
480  inline ADvar& operator=(const IndepADvar &x) { return ADvar_operatoreq(this,*x.cv); }
481 #endif /* RAD_EQ_ALIAS */
482 #endif /* RAD_AUTO_AD_Const */
483  ADvar& operator=(double);
484  ADvar& operator+=(const ADvari&);
485  ADvar& operator+=(double);
486  ADvar& operator-=(const ADvari&);
487  ADvar& operator-=(double);
488  ADvar& operator*=(const ADvari&);
489  ADvar& operator*=(double);
490  ADvar& operator/=(const ADvari&);
491  ADvar& operator/=(double);
492  inline static bool get_fpval_implies_const(void)
494  inline static void set_fpval_implies_const(bool newval)
496  inline static bool setget_fpval_implies_const(bool newval) {
499  return oldval;
500  }
501  static inline void Gradcomp(int wantgrad)
502  { ADcontext::Gradcomp(wantgrad); }
503  static inline void Gradcomp()
504  { ADcontext::Gradcomp(1); }
505  static inline void Hvprod(int n, ADvar **vp, double *v, double *hv)
506  { ADcontext::Hvprod(n, vp, v, hv); }
507  static inline void aval_reset() { ConstADvari::aval_reset(); }
508  static inline void Weighted_Gradcomp(int n, ADvar **v, double *w)
509  { ADcontext::Weighted_Gradcomp(n, v, w); }
510  };
511 
512  inline void AD_Const(const IndepADvar&v) { IndepADvar::AD_Const(v); }
513 
514  class
515 ConstADvar: public ADvar {
516  private: // disable op=
517  ConstADvar& operator+=(const ADvari&);
518  ConstADvar& operator+=(double);
519  ConstADvar& operator-=(const ADvari&);
520  ConstADvar& operator-=(double);
521  ConstADvar& operator*=(const ADvari&);
522  ConstADvar& operator*=(double);
523  ConstADvar& operator/=(const ADvari&);
524  ConstADvar& operator/=(double);
525  void ConstADvar_ctr(double);
526  public:
527  inline ConstADvar(double d) { ConstADvar_ctr(d); }
528  inline ConstADvar(int i) { ConstADvar_ctr((double)i); }
529  inline ConstADvar(long i) { ConstADvar_ctr((double)i); }
530  ConstADvar(const ADvari &x);
531 #ifdef RAD_AUTO_AD_Const
532  ConstADvar(const IndepADvar &x) { cv = new ADvar1(this,x); }
533 #endif
534  inline ~ConstADvar(){}
535 #ifdef RAD_NO_CONST_UPDATE
536  private:
537 #endif
538  ConstADvar();
539  inline ConstADvar& operator=(double d) { cv->Val = d; return *this; }
540  inline ConstADvar& operator=(const IndepADvar& d) { cv->Val = d.val(); return *this; }
541  };
542 
543  class
544 ADvar1s: public ADvar1 { // unary ops with partials
545  public:
546  double pL; // deriv of op w.r.t. left operand L
547  ADvar1s(double val1, double d1, const ADvari *c1):
548  ADvar1(Hv_timesL,val1,&pL,c1), pL(d1) {}
549  };
550 
551  class
552 ADvar1g: public ADvar1 { // unary ops with partials
553  public:
554  double pL; // deriv of op w.r.t. left operand L
555  double pL2; // partial of op w.r.t. L,L
556  ADvar1g(double val1, double d1, double d2, const ADvari *c1):
557  ADvar1(Hv_unary,val1,&pL,c1), pL(d1), pL2(d2) {}
558  };
559 
560  class
561 ADvar2: public ADvari { // basic binary ops
562  public:
563  Derp dL, dR;
564  ADvar2(Advari_Opclass oc, double val1, const ADvari *Lcv, const double *Lc,
565  const ADvari *Rcv, const double *Rc): ADvari(oc,val1) {
566  dR.next = Derp::LastDerp;
567  dL.next = &dR;
568  Derp::LastDerp = &dL;
569  dL.a = Lc;
570  dL.c = (ADvari*)Lcv;
571  dR.a = Rc;
572  dR.c = (ADvari*)Rcv;
573  dL.b = dR.b = this;
574  }
575  };
576 
577  class
578 ADvar2q: public ADvar2 { // binary ops with partials
579  public:
580  double pL; // deriv of op w.r.t. left operand L
581  double pR; // deriv of op w.r.t. right operand R
582  double pLR; // second partial w.r.t. L,R
583  double pR2; // second partial w.r.t. R,R
584  ADvar2q(double val1, double Lp, double Rp, double LR, double R2,
585  const ADvari *Lcv, const ADvari *Rcv);
586  };
587 
588  class
589 ADvar2g: public ADvar2 { // general binary ops with partials
590  public:
591  double pL; // deriv of op w.r.t. left operand L
592  double pR; // deriv of op w.r.t. right operand R
593  double pL2; // second partial w.r.t. L,L
594  double pLR; // second partial w.r.t. L,R
595  double pR2; // second partial w.r.t. R,R
596  ADvar2g(double val1, double Lp, double Rp, double L2, double LR, double R2,
597  const ADvari *Lcv, const ADvari *Rcv);
598  };
599 
600  class
601 ADvarn: public ADvari { // n-ary ops with partials g and 2nd partials h (lower triangle, rowwise)
602  public:
603  int n;
604  double *G, *H;
605  Derp *D;
606  ADvarn(double val1, int n1, const ADvar *x, const double *g, const double *h);
607  };
608 
609 inline ADvari &operator+(ADvari &T) { return T; }
610 inline ADvari &operator+(const ADvari &T) { return (ADvari&) T; }
611 
612 inline int operator<(const ADvari &L, const ADvari &R) { return L.Val < R.Val; }
613 inline int operator<(const ADvari &L, double R) { return L.Val < R; }
614 inline int operator<(double L, const ADvari &R) { return L < R.Val; }
615 
616 inline int operator<=(const ADvari &L, const ADvari &R) { return L.Val <= R.Val; }
617 inline int operator<=(const ADvari &L, double R) { return L.Val <= R; }
618 inline int operator<=(double L, const ADvari &R) { return L <= R.Val; }
619 
620 inline int operator==(const ADvari &L, const ADvari &R) { return L.Val == R.Val; }
621 inline int operator==(const ADvari &L, double R) { return L.Val == R; }
622 inline int operator==(double L, const ADvari &R) { return L == R.Val; }
623 
624 inline int operator!=(const ADvari &L, const ADvari &R) { return L.Val != R.Val; }
625 inline int operator!=(const ADvari &L, double R) { return L.Val != R; }
626 inline int operator!=(double L, const ADvari &R) { return L != R.Val; }
627 
628 inline int operator>=(const ADvari &L, const ADvari &R) { return L.Val >= R.Val; }
629 inline int operator>=(const ADvari &L, double R) { return L.Val >= R; }
630 inline int operator>=(double L, const ADvari &R) { return L >= R.Val; }
631 
632 inline int operator>(const ADvari &L, const ADvari &R) { return L.Val > R.Val; }
633 inline int operator>(const ADvari &L, double R) { return L.Val > R; }
634 inline int operator>(double L, const ADvari &R) { return L > R.Val; }
635 
636 inline ADvari& copy(const IndepADvar &x)
637 { return *(new ADvar1(Hv_copy, x.cv->Val, &CADcontext::One, x.cv)); }
638 
639 inline ADvari& copy(const ADvari &x)
640 { return *(new ADvar1(Hv_copy, x.Val, &CADcontext::One, &x)); }
641 
642 inline ADvari& abs(const ADvari &x)
643 { return fabs(x); }
644 
645 #define A (ADvari*)
646 #define T inline
647 #define F ADvari&
648 #define Ai const ADvari&
649 #define AI const IndepADvar&
650 #define D double
651 #define T2(r,f) \
652  T r f(Ai L, AI R) { return f(L, *A R.cv); }\
653  T r f(AI L, Ai R) { return f(*A L.cv, R); }\
654  T r f(AI L, AI R) { return f(*A L.cv, *A R.cv); }\
655  T r f(AI L, D R) { return f(*A L.cv, R); }\
656  T r f(D L, AI R) { return f(L, *A R.cv); }
657 
658 T2(F, operator+)
659 T2(F, operator-)
660 T2(F, operator*)
661 T2(F, operator/)
662 T2(F, atan2)
663 T2(F, pow)
664 T2(F, max)
665 T2(F, min)
666 T2(int, operator<)
667 T2(int, operator<=)
668 T2(int, operator==)
669 T2(int, operator!=)
670 T2(int, operator>=)
671 T2(int, operator>)
672 
673 #undef T2
674 #undef D
675 
676 #define T1(f)\
677  T F f(AI x) { return f(*A x.cv); }
678 
679 T1(operator+)
680 T1(operator-)
681 T1(abs)
682 T1(acos)
683 T1(acosh)
684 T1(asin)
685 T1(asinh)
686 T1(atan)
687 T1(atanh)
688 T1(cos)
689 T1(cosh)
690 T1(exp)
691 T1(log)
692 T1(log10)
693 T1(sin)
694 T1(sinh)
695 T1(sqrt)
696 T1(tan)
697 T1(tanh)
698 T1(fabs)
699 
700 #undef T1
701 #undef AI
702 #undef Ai
703 #undef F
704 #undef T
705 #undef A
706 
707 #ifndef SACADO_NO_NAMESPACE
708 } // namespace Rad2d
709 } // namespace Sacado
710 #endif // SACADO_NAMESPACE
711 #endif // SACADO_RAD2_H
ADvari & cos(const ADvari &v)
void * Memalloc(size_t len)
asin(expr.val())
cosh(expr.val())
Advari_Opclass opclass
abs(expr.val())
static bool setget_fpval_implies_const(bool newval)
static void aval_reset(void)
static void Hvprod(int n, ADvar **vp, double *v, double *hv)
static void Weighted_Gradcomp(int n, ADvar **v, double *w)
const double * a
ADvari(Advari_Opclass oc, double t, double ta)
ADvar1s(double val1, double d1, const ADvari *c1)
int operator>(const ADvari &L, const ADvari &R)
ADvari & asinh(const ADvari &v)
IndepADvar & operator=(const IndepADvar &x)
static void AD_Const(const IndepADvar &)
atan(expr.val())
ADvari & acosh(const ADvari &v)
static void Weighted_Gradcomp(int n, ADvar **v, double *w)
void AD_Const(const IndepADvar &v)
ADvari & operator+(ADvari &T)
#define R
Definition: Sacado_rad.hpp:181
ADvari & sinh(const ADvari &v)
ADvari & atanh(const ADvari &v)
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)
ADvari & min(const ADvari &L, const ADvari &R)
ADvari(Advari_Opclass oc, double t)
ADvari & exp(const ADvari &v)
static void Hvprod(int n, ADvar **vp, double *v, double *hv)
ADvar1g(double val1, double d1, double d2, const ADvari *c1)
ConstADvar & operator=(const IndepADvar &d)
static void Gradcomp(int wantgrad)
ADvari & fabs(const ADvari &v)
ADvar(const ADvari &x)
tanh(expr.val())
ADvari & log10(const ADvari &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
static ADcontext adc
static const double One
#define T2(r, f)
Definition: Sacado_rad.hpp:578
ADvari & asin(const ADvari &v)
const ADvari * b
ADvari & ADf2(double f, double gx, double gy, double hxx, double hxy, double hyy, const ADvari &x, const ADvari &y)
ConstADvar & operator=(double d)
sqrt(expr.val())
static CADcontext cadc
sinh(expr.val())
tan(expr.val())
static Derp * LastDerp
ADvari & atan(const ADvari &v)
int operator>=(const ADvari &L, const ADvari &R)
ADvari & cosh(const ADvari &v)
int operator<(const ADvari &L, const ADvari &R)
#define T1(r, f)
Definition: Sacado_rad.hpp:603
ADvari & sin(const ADvari &v)
ADvari & tan(const ADvari &v)
atan2(expr1.val(), expr2.val())
static void Hvprod(int, ADvar **, double *, double *)
static void Gradcomp(int wantgrad)
int operator!=(const ADvari &L, const ADvari &R)
#define T
ADvari & abs(const ADvari &x)
sin(expr.val())
ADvar & operator=(const IndepADvar &x)
ADvari & sqrt(const ADvari &v)
void * new_ADmemblock(size_t)
static void Weighted_Gradcomp(int, ADvar **, double *)
ADvari & max(const ADvari &L, const ADvari &R)
log(expr.val())
ADvar & ADvar_operatoreq(ADvar *This, const ADvari &x)
ADvari & pow(const ADvari &L, const ADvari &R)
static bool get_fpval_implies_const(void)
int operator<=(const ADvari &L, const ADvari &R)
static void aval_reset()
ADvar1(Advari_Opclass oc, double val1, const double *a1, const ADvari *c1)
ADvari & log(const ADvari &v)
acos(expr.val())
static void set_fpval_implies_const(bool newval)
ADvari & acos(const ADvari &v)
int operator==(const ADvari &L, const ADvari &R)
ADvar & operator=(const ADvari &x)
ADvari & copy(const IndepADvar &x)
ADvar2(Advari_Opclass oc, double val1, const ADvari *Lcv, const double *Lc, const ADvari *Rcv, const double *Rc)
ADvari & atan2(const ADvari &L, const ADvari &R)
ADvari & ADf1(double f, double g, double h, const ADvari &x)
static void Gradcomp()
exp(expr.val())
fabs(expr.val())
ADvari & ADfn(double f, int n, const ADvar *x, const double *g, const double *h)
void ADvari_record(ADvari *x)
log10(expr.val())
ADvari & tanh(const ADvari &v)
cos(expr.val())
ADvar(const IndepADvar &x)