ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_a46.cpp
Go to the documentation of this file.
1 
9 #include "fvar.hpp"
10 
11 #ifdef __TURBOC__
12  #pragma hdrstop
13  #include <iostream.h>
14 #endif
15 
16 #ifdef __ZTC__
17  #include <iostream.hpp>
18 #endif
19 
20 
21 void dvdv_elem_div(void);
22 
30 {
33 
34  int min = v1.indexmin();
35  int max = v1.indexmax();
36 #ifndef OPT_LIB
37  if (min != v2.indexmin() || max != v2.indexmax())
38  {
39  cerr << "Incompatible bounds in "
40  "dvar_vector elem_prod(const dvar_vector& v1, const dvar_vector& v2)"
41  << endl;
42  ad_exit(1);
43  }
44 #endif
45  dvar_vector tmp(min, max);
46  dvector tmp_inv(min, max);
47 
48  double_and_int* pv1 = v1.va + min;
49  double_and_int* pv2 = v2.va + min;
50  double* ptmp_inv = tmp_inv.get_v() + min;
51  double_and_int* ptmp = tmp.va + min;
52  for (int i = min; i <= max; ++i)
53  {
54  *ptmp_inv = 1.0 / pv2->x;
55  ptmp->x = pv1->x * *ptmp_inv;
56  ++pv2;
57  ++pv1;
58  ++ptmp_inv;
59  ++ptmp;
60  }
61 
62  // The derivative list considerations
64  save_identifier_string("bbbb");
65  fp->save_dvar_vector_value(v1);
67  save_identifier_string("wwww");
68  fp->save_dvector_value(tmp_inv);
69  fp->save_dvector_position(tmp_inv);
70  save_identifier_string("vvvv");
72  save_identifier_string("uuuu");
74  save_identifier_string("aaaa");
77  return tmp;
78 }
82 void dvdv_elem_div(void)
83 {
85 
86  // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
94  dvector tmp_div=fp->restore_dvector_value(tmp_divpos);
99 
100  int min = cv1.indexmin();
101  int max = cv1.indexmax();
102  dvector dfv1(min, max);
103  int min2 = tmp_div.indexmin();
104  int max2 = tmp_div.indexmax();
105  dvector dfv2(min2, max2);
106 
107  double* ptmp_div = tmp_div.get_v() + min;
108  double* pdftmp = dftmp.get_v() + min;
109  double* pcv1 = cv1.get_v() + min;
110  double* pdfv1 = dfv1.get_v() + min;
111  double* pdfv2 = dfv2.get_v() + min2;
112  for (int i = min; i <= max; ++i)
113  {
114  //tmp+=cv1(i)*cv2(i);
115 
116  //double& xx=tmp_div.elem(i);
117  double xx = *ptmp_div;
118  //dfv1(i)=dftmp.elem(i)*xx;
119  *pdfv1 = *pdftmp * xx;
120  //dfv2(i)=-dftmp.elem(i)*cv1.elem(i)*xx*xx;
121  *pdfv2 = -(*pdftmp) * *pcv1 * xx * xx;
122  ++ptmp_div;
123  ++pdftmp;
124  ++pcv1;
125  ++pdfv1;
126  ++pdfv2;
127  }
128  dfv1.save_dvector_derivatives(v1pos);
129  dfv2.save_dvector_derivatives(v2pos);
130  //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
131 }
132 
133 void dvcv_elem_div(void);
134 
142 {
146 
147  int min = v1.indexmin();
148  int max = v1.indexmax();
149 #ifndef OPT_LIB
150  if (min != v2.indexmin() || max != v2.indexmax())
151  {
152  cerr << "Incompatible bounds in "
153  "dvar_vector elem_prod(const dvar_vector& v1, const dvar_vector& v2)"
154  << endl;
155  ad_exit(1);
156  }
157 #endif
158  dvar_vector tmp(min, max);
159  dvector tmp_inv(min, max);
160 
161  double_and_int* pv1 = v1.va + min;
162  double* pv2 = v2.get_v() + min;
163  double* ptmp_inv = tmp_inv.get_v() + min;
164  double_and_int* ptmp = tmp.va + min;
165  for (int i = min; i <= max; ++i)
166  {
167  //tmp_inv.elem(i)=1./v2.elem(i);
168  //tmp.elem_value(i)=v1.elem_value(i)*tmp_inv.elem(i);
169  *ptmp_inv = 1.0 / *pv2;
170  ptmp->x = pv1->x * *ptmp_inv;
171  ++ptmp_inv;
172  ++ptmp;
173  ++pv1;
174  ++pv2;
175  }
176 
177  // The derivative list considerations
178  save_identifier_string("bbbb");
179  fp->save_dvar_vector_value(v1);
181  save_identifier_string("wwww");
182  fp->save_dvector_value(tmp_inv);
183  fp->save_dvector_position(tmp_inv);
184  save_identifier_string("vvvv");
185  fp->save_dvar_vector_position(tmp);
186  save_identifier_string("aaaa");
189  return tmp;
190 }
194 void dvcv_elem_div(void)
195 {
197 
198  // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
199  verify_identifier_string("aaaa");
202  verify_identifier_string("vvvv");
204  dvector tmp_div=fp->restore_dvector_value(tmp_divpos);
205  verify_identifier_string("wwww");
208  verify_identifier_string("bbbb");
209  dvector dfv1(cv1.indexmin(),cv1.indexmax());
210  for (int i=cv1.indexmin();i<=cv1.indexmax();i++)
211  {
212  dfv1(i)=dftmp.elem(i)*tmp_div.elem(i);
213  }
214  dfv1.save_dvector_derivatives(v1pos);
215  //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
216 }
217 
218 void cvdv_elem_div(void);
219 
227 {
231 
232  if (v1.indexmin()!=v2.indexmin()||v1.indexmax()!=v2.indexmax())
233  {
234  cerr << "Incompatible bounds in "
235  "dvar_vector elem_prod(const dvar_vector& v1, const dvar_vector& v2)"
236  << endl;
237  ad_exit(1);
238  }
239  dvar_vector tmp(v1.indexmin(),v1.indexmax());
240  dvector tmp_inv(v1.indexmin(),v1.indexmax());
241 
242  for (int i=v1.indexmin();i<=v1.indexmax();i++)
243  {
244  double x=1./v2.elem_value(i);
245  tmp.elem_value(i)=v1.elem(i)*x;
246  tmp_inv.elem(i)=-tmp.elem_value(i)*x;
247  }
248 
249  // The derivative list considerations
250  save_identifier_string("bbbb");
251  fp->save_dvector_value(tmp_inv);
252  fp->save_dvector_position(tmp_inv);
253  save_identifier_string("vvvv");
255  save_identifier_string("uuuu");
256  fp->save_dvar_vector_position(tmp);
257  save_identifier_string("aaaa");
260  return tmp;
261 }
265 void cvdv_elem_div(void)
266 {
268 
269  // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
270  verify_identifier_string("aaaa");
273  verify_identifier_string("uuuu");
275  verify_identifier_string("vvvv");
277  dvector tmp_div=fp->restore_dvector_value(tmp_divpos);
278  verify_identifier_string("bbbb");
279  dvector dfv2(tmp_div.indexmin(),tmp_div.indexmax());
280  for (int i=dfv2.indexmin();i<=dfv2.indexmax();i++)
281  {
282  //tmp+=cv1(i)*cv2(i);
283  dfv2(i)=dftmp.elem(i)*tmp_div.elem(i);
284  }
285  dfv2.save_dvector_derivatives(v2pos);
286  //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
287 }
double & elem(int i)
Definition: dvector.h:152
void dvdv_elem_div(void)
Adjoint gradient computation of elem_div(const dvar_vector&amp;, const dvar_vector&amp;)
Definition: fvar_a46.cpp:82
double & elem_value(int i)
Definition: fvar.hpp:2226
#define x
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Get minimum valid index.
Definition: dvector.h:199
d3_array elem_div(const d3_array &a, const d3_array &b)
Returns d3_array results with computed elements division of a(i, j, k) / b(i, j, k).
Definition: d3arr2a.cpp:112
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
exitptr ad_exit
Definition: gradstrc.cpp:53
Description not yet available.
Definition: fvar.hpp:4923
ADMB variable vector.
Definition: fvar.hpp:2172
void verify_identifier_string(const char *)
Verifies gradient stack string.
Definition: cmpdif3.cpp:149
dvector restore_dvector_value(const dvector_position &tmp)
Definition: cmpdif4.cpp:178
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_dvector_position(const dvector &v)
Definition: cmpdif4.cpp:32
prnstream & endl(prnstream &)
void save_dvector_value(const dvector &v)
Definition: cmpdif4.cpp:130
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
void cvdv_elem_div(void)
Adjoint gradient computation of elem_div(const dvector&amp;, const dvar_vector&amp;)
Definition: fvar_a46.cpp:265
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
static _THREAD gradient_structure * _instance
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
dvector_position restore_dvector_position()
Definition: cmpdif4.cpp:88
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
Stores the adjoint gradient data that will be processed by gradcalc.
dvector restore_dvar_vector_derivatives(const dvar_vector_position &tmp)
Description not yet available.
Definition: cmpdif5.cpp:150
void RETURN_ARRAYS_DECREMENT()
Definition: gradstrc.cpp:511
double_and_int * va
Definition: fvar.hpp:2175
void dvcv_elem_div(void)
Adjoint gradient computation of elem_div(const dvar_vector&amp;, const dvector&amp;)
Definition: fvar_a46.cpp:194
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
double x
&lt; value of the variable
Definition: fvar.hpp:195