ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_op5.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
7 
13 #include "fvar.hpp"
14 
15 #ifdef __TURBOC__
16  #pragma hdrstop
17  #include <iostream.h>
18 #endif
19 
20 #ifdef __ZTC__
21  #include <iostream.hpp>
22 #endif
23 
24 #include <stdio.h>
25 #include <math.h>
26 #if !defined(OPT_LIB)
27 
32 void grad_stack::set_gradient_stack(void (* func)(void), double * dep_addr,
33  double * ind_addr1, double mult1, double * ind_addr2, double mult2)
34 {
35 #ifdef NO_DERIVS
37  {
38 #endif
39 #if defined(MYDEBUG)
40  int wrote_buffer=0;
41  if (ptr < ptr_first)
42  {
43  cerr << "Illegal ptr value" << endl;
44  ad_exit(1);
45  }
46 #endif
47  if (ptr > ptr_last)
48  {
49  // current buffer is full -- write it to disk and reset pointer
50  // and counter
52 #if defined(MYDEBUG)
53  wrote_buffer=1;
54 #endif
55  }
56  ptr->func = func;
57  ptr->dep_addr = dep_addr;
58  ptr->ind_addr1 = ind_addr1;
59  ptr->mult1=mult1;
60  ptr->ind_addr2 = ind_addr2;
61  ptr->mult2=mult2;
62  ptr++;
63 #ifdef NO_DERIVS
64  }
65 #endif
66 }
67 #endif
68 
72 prevariable& operator*(double x, const prevariable& v2)
73 {
75 
76  RETURN_PTR->v->x = x * v2.v->x;
78  &(RETURN_PTR->v->x),&(v2.v->x),x);
79 
80  return *RETURN_PTR;
81 }
86 prevariable& operator*(const prevariable& v1, double x)
87 {
89 
90  RETURN_PTR->v->x = v1.v->x * x;
92  &(RETURN_PTR->v->x),&(v1.v->x),x);
93 
94  return *RETURN_PTR;
95 }
101 {
102  double tmp=1./(v1.v->x);
103  v->x *= tmp;
105  default_evaluation,&(v->x), &(v->x), tmp,&(v1.v->x), -(v->x)*tmp);
106 }
111 void prevariable::operator/=(double v1)
112 {
113  double tmp=1./v1;
114  v->x *= tmp;
116  default_evaluation,&(v->x), &(v->x), tmp);
117 }
123 {
124  double* tmp=&((v1.v)->x);
126  default_evaluation,&(v->x), &(v->x), *tmp, tmp, v->x);
127  v->x *= *tmp;
128 }
133 void prevariable::operator*=(double v1)
134 {
136  default_evaluation,&(v->x), &(v->x), v1);
137  v->x *= v1;
138 }
void default_evaluation2(void)
Description not yet available.
Definition: def_eval.cpp:136
Base class for dvariable.
Definition: fvar.hpp:1315
double * ind_addr1
Pointer to first independent variable.
Definition: fvar.hpp:900
double mult2
Second mutiplicand in chain rule multipication.
Definition: fvar.hpp:903
void operator/=(const prevariable &v1)
Description not yet available.
Definition: fvar_op5.cpp:100
#define x
void write_grad_stack_buffer()
Definition: fvar.hpp:976
exitptr ad_exit
Definition: gradstrc.cpp:53
double * ind_addr2
Pointer to second independent variable.
Definition: fvar.hpp:902
dmatrix operator*(const d3_array &t, const dvector &v)
Description not yet available.
Definition: d3arr12.cpp:17
void set_gradient_stack(void(*func)(void), double *dep_addr, double *ind_addr1=NULL, double mult1=0, double *ind_addr2=NULL, double mult2=0)
Description not yet available.
Definition: fvar.hpp:1045
prnstream & endl(prnstream &)
static dvariable * next_RETURN_PTR()
Definition: gradstrc.cpp:457
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void default_evaluation(void)
Description not yet available.
Definition: def_eval.cpp:61
grad_stack_entry * ptr_first
Definition: fvar.hpp:924
double_and_int * v
pointer to the data
Definition: fvar.hpp:1333
double mult1
First mutiplicand in chain rule multipication.
Definition: fvar.hpp:901
grad_stack_entry * ptr
Definition: fvar.hpp:934
void operator*=(const prevariable &v1)
Description not yet available.
Definition: fvar_op5.cpp:122
static _THREAD grad_stack * GRAD_STACK1
grad_stack_entry * ptr_last
Definition: fvar.hpp:925
void(* func)(void)
&lt; Pointer to function (if any) to be used for derivative calculation
Definition: fvar.hpp:898
double * dep_addr
Pointer to dependent variable.
Definition: fvar.hpp:899
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518
double x
&lt; value of the variable
Definition: fvar.hpp:195