ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_a14.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  */
11 // file fvar.cpp
12 // constructors, destructors and misc functions involving class prevariable
13 
14 #include "fvar.hpp"
15 
16 #ifdef __TURBOC__
17  #pragma hdrstop
18  #include <iostream.h>
19 #endif
20 
21 #ifdef __ZTC__
22  #include <iostream.hpp>
23 #endif
24 
25 #ifdef DEBUG
26  #include <cassert>
27 #endif
28 
39 {
42 
43  int min=v1.indexmin();
44  int max=v1.indexmax();
45 #ifdef OPT_LIB
46  if (min != v2.indexmin() || max != v2.indexmax())
47  {
48  cerr << "Incompatible bounds in prevariable operator*(const dvar_vector&, const dvar_vector&)\n";
49  ad_exit(1);
50  }
51 #endif
52 
53  double tmp{0};
54  double_and_int* pva1 = v1.va + min;
55  double_and_int* pva2 = v2.va + min;
56  for (int i = min; i <= max; ++i)
57  {
58  tmp += pva1->x * pva2->x;
59  ++pva1;
60  ++pva2;
61  }
62 
63  dvariable vtmp=nograd_assign(tmp);
64 
67  // The derivative list considerations
68  //save_identifier_string("bbbb");
69  fp->save_dvar_vector_value(v1);
71  fp->save_dvar_vector_value(v2);
73  fp->save_prevariable_position(vtmp);
74  //save_identifier_string("aaaa");
75  GRAD_STACK1->set_gradient_stack(dvdv_dot);
77  return vtmp;
78 }
79 
80 /*
81  * Description not yet available.
82  * \param
83  */
84 void dvdv_dot(void)
85 {
87 
88  //verify_identifier_string("aaaa");
89  double dftmp=fp->restore_prevariable_derivative();
94  //verify_identifier_string("bbbb");
95 
96  int min = cv1.indexmin();
97  int max = cv1.indexmax();
98 
99 #ifdef DEBUG
100  assert(min == cv2.indexmin() && max == cv2.indexmax());
101 #endif
102 
103  dvector dfv1(min, max);
104  dvector dfv2(min, max);
105 
106  double* pcv1 = cv1.get_v() + min;
107  double* pcv2 = cv2.get_v() + min;
108  double* pdfv1 = dfv1.get_v() + min;
109  double* pdfv2 = dfv2.get_v() + min;
110  for (int i = min; i <= max; ++i)
111  {
112  //tmp+=cv1(i)*cv2(i);
113  *pdfv1 = dftmp * *pcv2;
114  *pdfv2 = dftmp * *pcv1;
115  ++pdfv1;
116  ++pdfv2;
117  ++pcv2;
118  ++pcv1;
119  }
120  dfv1.save_dvector_derivatives(v1pos);
121  dfv2.save_dvector_derivatives(v2pos);
122 }
123 
124 void X_dv_sum(void);
125 
132 {
133  dvariable vtmp = 0.0;
134  if (allocated(v1))
135  {
136  int min = v1.indexmin();
137  int max = v1.indexmax();
138  //dvector cv1=value(v1);
139  double_and_int* pv1 = v1.va + min;
140  double tmp=0;
141  for (int i = min; i <= max; ++i)
142  {
143  //tmp+=cv1.elem(i);
144  tmp += pv1->x;
145  ++pv1;
146  }
147 
148  vtmp = nograd_assign(tmp);
149 
152  // The derivative list considerations
153  save_identifier_string("bbbb");
155  fp->save_prevariable_position(vtmp);
156  save_identifier_string("aaaa");
157  GRAD_STACK1->set_gradient_stack(X_dv_sum);
158  }
159  return vtmp;
160 }
161 
162 /*
163  * Description not yet available.
164  *
165  */
166 void X_dv_sum(void)
167 {
169 
170  verify_identifier_string("aaaa");
171  double dftmp=fp->restore_prevariable_derivative();
173  verify_identifier_string("bbbb");
174  int min = v1pos.indexmin();
175  int max = v1pos.indexmax();
176  dvector dfv1(min, max);
177  double* pdfv1 = dfv1.get_v() + min;
178  for (int i = min; i <= max; ++i)
179  {
180  //tmp+=cv1(i)*cv2(i);
181  //dfv1(i)=dftmp;
182  *pdfv1 = dftmp;
183  ++pdfv1;
184  }
185  dfv1.save_dvector_derivatives(v1pos);
186 }
187 
195 {
198 
199  int min = m.rowmin();
200  int max = m.rowmax();
201  dvariable tmp{0.0};
202  if (min <= max)
203  {
204  const dvar_vector* pmi = &m(min);
205  for (int i = min; i <= max; ++i)
206  {
207  tmp += sum(*pmi);
208  ++pmi;
209  }
210  }
212  return tmp;
213 }
Description not yet available.
Definition: fvar.hpp:920
void X_dv_sum(void)
Definition: fvar_a14.cpp:166
int rowmax(void) const
Definition: fvar.hpp:2564
double restore_prevariable_derivative()
Definition: cmpdif8.cpp:147
int allocated(const ivector &v)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: fvar_a59.cpp:13
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Get minimum valid index.
Definition: dvector.h:199
dvar_vector nograd_assign(dvector tmp)
Description not yet available.
Definition: cmpdif6.cpp:252
double sum(const d3_array &darray)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr.cpp:21
void save_dvector_derivatives(const dvar_vector_position &pos) const
Puts the derivative values in a dvector into a dvar_vector&#39;s guts.
Definition: cmpdif5.cpp:212
Description not yet available.
Definition: fvar.hpp:4814
void dvdv_dot(void)
Definition: fvar_a14.cpp:84
int indexmin() const
Definition: fvar.hpp:4827
exitptr ad_exit
Definition: gradstrc.cpp:53
ADMB variable vector.
Definition: fvar.hpp:2172
void verify_identifier_string(const char *)
Verifies gradient stack string.
Definition: cmpdif3.cpp:149
dmatrix operator*(const d3_array &t, const dvector &v)
Description not yet available.
Definition: d3arr12.cpp:17
Holds the data for the prevariable class.
Definition: fvar.hpp:191
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
void save_prevariable_position(const prevariable &v)
Definition: cmpdif8.cpp:60
int indexmax() const
Definition: fvar.hpp:4831
void save_dvar_vector_value(const dvar_vector &v)
Definition: cmpdif4.cpp:106
dvar_vector_position restore_dvar_vector_position()
Definition: cmpdif4.cpp:69
void RETURN_ARRAYS_INCREMENT()
Definition: gradstrc.cpp:478
#define min(a, b)
Definition: cbivnorm.cpp:188
int indexmax() const
Get maximum valid index.
Definition: dvector.h:204
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
static _THREAD gradient_structure * _instance
int rowmin(void) const
Definition: fvar.hpp:2560
int save_identifier_string(const char *)
Writes a gradient stack verification string.
Definition: cmpdif2.cpp:315
dvector restore_dvar_vector_value(const dvar_vector_position &tmp)
Restores the size, address, and value information for a dvar_vector.
Definition: cmpdif4.cpp:227
int indexmin() const
Definition: fvar.hpp:2287
void save_dvar_vector_position(const dvar_vector &v)
Definition: cmpdif3.cpp:214
static _THREAD DF_FILE * fp
Class definition of matrix with derivitive information .
Definition: fvar.hpp:2480
Stores the adjoint gradient data that will be processed by gradcalc.
void RETURN_ARRAYS_DECREMENT()
Definition: gradstrc.cpp:511
double_and_int * va
Definition: fvar.hpp:2175
static _THREAD grad_stack * GRAD_STACK1
#define max(a, b)
Definition: cbivnorm.cpp:189
class for things related to the gradient structures, including dimension of arrays, size of buffers, etc.
double *& get_v(void)
Definition: dvector.h:148
int indexmax() const
Definition: fvar.hpp:2292
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518
double x
&lt; value of the variable
Definition: fvar.hpp:195