ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_a45.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 
26 void dvdv_elem_prod(void);
27 
33 {
36 
37  int min = v1.indexmin();
38  int max = v1.indexmax();
39 #ifndef OPT_LIB
40  if (min != v2.indexmin() || max != v2.indexmax())
41  {
42  cerr << "Incompatible bounds in "
43  "dvar_vector elem_prod(const dvar_vector& v1, const dvar_vector& v2)"
44  << endl;
45  ad_exit(1);
46  }
47 #endif
48  dvar_vector tmp(min, max);
49 
50  double_and_int* ptmpi = tmp.va + min;
51  const double_and_int* pv1i = v1.va + min;
52  const double_and_int* pv2i = v2.va + min;
53  for (int i = min; i <= max; ++i)
54  {
55  ptmpi->x = pv1i->x * pv2i->x;
56  ++ptmpi;
57  ++pv1i;
58  ++pv2i;
59  }
60 
61  // The derivative list considerations
64  fp->save_dvar_vector_value(v1);
66  fp->save_dvar_vector_value(v2);
72  return tmp;
73 }
74 
79 void dvdv_elem_prod(void)
80 {
82 
83  // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
92  int min = cv1.indexmin();
93  int max = cv2.indexmax();
94  dvector dfv1(min, max);
95  dvector dfv2(min, max);
96 
97  double* pdfv1i = dfv1.get_v() + min;
98  double* pdfv2i = dfv2.get_v() + min;
99  double* pdftmpi = dftmp.get_v() + min;
100  double* pcv1i = cv1.get_v() + min;
101  double* pcv2i = cv2.get_v() + min;
102  for (int i = min; i <= max; ++i)
103  {
104  //tmp+=cv1(i)*cv2(i);
105  *pdfv1i = *pdftmpi * *pcv2i;
106  *pdfv2i = *pdftmpi * *pcv1i;
107 
108  ++pdfv1i;
109  ++pdfv2i;
110  ++pdftmpi;
111  ++pcv1i;
112  ++pcv2i;
113  }
114  dfv1.save_dvector_derivatives(v1pos);
115  dfv2.save_dvector_derivatives(v2pos);
116  //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
117 }
118 
119 void cvdv_elem_prod(void);
120 
126 {
130 
131  int min = v1.indexmin();
132  int max = v1.indexmax();
133 #ifndef OPT_LIB
134  if (min != v2.indexmin() || max != v2.indexmax())
135  {
136  cerr << "Incompatible bounds in dvar_vector elem_prod(const dvector&, const dvar_vector&)\n";
137  ad_exit(1);
138  }
139 #endif
140 
141  dvar_vector tmp(min, max);
142 
143  double_and_int* ptmpi = tmp.va + min;
144  double* pv1i = v1.get_v() + min;
145  double_and_int* pv2i = v2.va + min;
146  for (int i = min; i <= max; ++i)
147  {
148  ptmpi->x = *pv1i * pv2i->x;
149 
150  ++ptmpi;
151  ++pv1i;
152  ++pv2i;
153  }
154 
155  // The derivative list considerations
157  fp->save_dvector_value(v1);
158  fp->save_dvector_position(v1);
160  fp->save_dvar_vector_position(tmp);
164 
165  return tmp;
166 }
167 
172 void cvdv_elem_prod(void)
173 {
175 
176  // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
182  dvector cv1=fp->restore_dvector_value(v1pos);
184 
185  int min = cv1.indexmin();
186  int max = cv1.indexmax();
187  dvector dfv2(min, max);
188 
189  double* pdfv2i = dfv2.get_v() + min;
190  double* pdftmpi = dftmp.get_v() + min;
191  double* pcv1i = cv1.get_v() + min;
192  for (int i = min; i <= max; ++i)
193  {
194  //tmp+=cv1(i)*cv2(i);
195  *pdfv2i = *pdftmpi * *pcv1i;
196 
197  ++pdfv2i;
198  ++pdftmpi;
199  ++pcv1i;
200  }
201  dfv2.save_dvector_derivatives(v2pos);
202  //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
203 }
204 
205 void dvcv_elem_prod(void);
206 
212 {
216 
217  int min = v1.indexmin();
218  int max = v1.indexmax();
219 #ifndef OPT_LIB
220  if (min != v2.indexmin() || max != v2.indexmax())
221  {
222  cerr << "Incompatible bounds in dvar_vector elem_prod(const dvar_vector&, const dvector&)\n";
223  ad_exit(1);
224  }
225 #endif
226  dvar_vector tmp(min, max);
227 
228  double_and_int* ptmpi = tmp.va + min;
229  double_and_int* pv1i = v1.va + min;
230  double* pv2i = v2.get_v() + min;
231  for (int i = min; i <= max; ++i)
232  {
233  ptmpi->x = pv1i->x * *pv2i;
234 
235  ++ptmpi;
236  ++pv1i;
237  ++pv2i;
238  }
239 
240  // The derivative list considerations
243  fp->save_dvector_value(v2);
244  fp->save_dvector_position(v2);
245  fp->save_dvar_vector_position(tmp);
249  return tmp;
250 }
251 
256 void dvcv_elem_prod(void)
257 {
259 
260  // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
265  dvector cv2=fp->restore_dvector_value(v2pos);
268 
269  int min = cv2.indexmin();
270  int max = cv2.indexmax();
271  dvector dfv1(min, max);
272  double* pdfv1i = dfv1.get_v() + min;
273  double* pdftmpi = dftmp.get_v() + min;
274  double* pcv2i = cv2.get_v() + min;
275  for (int i = min; i <= max; ++i)
276  {
277  //tmp+=cv1(i)*cv2(i);
278  *pdfv1i = *pdftmpi * *pcv2i;
279 
280  ++pdfv1i;
281  ++pdftmpi;
282  ++pcv2i;
283  }
284  dfv1.save_dvector_derivatives(v1pos);
285  //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
286 }
d3_array elem_prod(const d3_array &a, const d3_array &b)
Returns d3_array results with computed elements product of a(i, j, k) * b(i, j, k).
Definition: d3arr2a.cpp:92
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Get minimum valid index.
Definition: dvector.h:199
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 dvdv_elem_prod(void)
Description not yet available.
Definition: fvar_a45.cpp:79
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
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void dvcv_elem_prod(void)
Description not yet available.
Definition: fvar_a45.cpp:256
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
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
void cvdv_elem_prod(void)
Description not yet available.
Definition: fvar_a45.cpp:172
double x
&lt; value of the variable
Definition: fvar.hpp:195