ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_a16.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 void dvcv_dot(void);
26 
31 dvariable operator*(const dvar_vector& v2, const dvector& cv1)
32 {
33  if (cv1.indexmin()!=v2.indexmin()||cv1.indexmax()!=v2.indexmax())
34  {
35  cerr << "Incompatible bounds in "
36  "prevariable operator*(const dvar_vector& v1, const dvar_vector& v2)"
37  << endl;
38  ad_exit(1);
39  }
40  //dvector cv1;
41  //dvector cv2=value(v2);
42  double tmp=0;
43 
44 #ifdef OPT_LIB
45  int mmin=cv1.indexmin();
46  int mmax=cv1.indexmax();
47  const double * pt1=&cv1.elem(mmin);
48  const double * pt1m=&cv1.elem(mmax);
49  const double * pt2=&v2.elem_value(mmin);
50  do
51  {
52  tmp+= *pt1++ * *pt2++;
53  }
54  while (pt1<=pt1m);
55 #else
56  #ifndef USE_ASSEMBLER
57  int mmin=cv1.indexmin();
58  int mmax=cv1.indexmax();
59  for (int i=mmin;i<=mmax;i++)
60  {
61  tmp+=cv1.elem(i)*v2.elem_value(i);
62  }
63  #else
64  int min=cv1.indexmin();
65  int n=cv1.indexmax()-min+1;
66  dp_dotproduct(&tmp,&(cv1.elem(min)),&(v2.elem_value(min)),n);
67  #endif
68 #endif
69 
70  dvariable vtmp=nograd_assign(tmp);
71 
74 
75  // The derivative list considerations
76  save_identifier_string("yyyy");
77  fp->save_dvector_value(cv1);
78  fp->save_dvector_position(cv1);
80  fp->save_prevariable_position(vtmp);
81  save_identifier_string("uuuu");
83  return vtmp;
84 }
85 
90 void dvcv_dot(void)
91 {
93 
95  double dftmp=fp->restore_prevariable_derivative();
98  dvector cv1=fp->restore_dvector_value(dpos);
100 
101  dvector dfv2(cv1.indexmin(),cv1.indexmax());
102 
103 #ifdef OPT_LIB
104  double * pc1=&cv1.elem(cv1.indexmin());
105  double * pc1m=&cv1(cv1.indexmax());
106  double * pdf=&dfv2.elem(cv1.indexmin());
107  do
108  {
109  *pdf++=dftmp* *pc1++;
110  }
111  while (pc1 <=pc1m);
112 #else
113  for (int i=cv1.indexmin();i<=cv1.indexmax();i++)
114  {
115  //tmp+=cv1(i)*cv2(i);
116  dfv2.elem(i)=dftmp*cv1.elem(i);
117  }
118 #endif
119  dfv2.save_dvector_derivatives(v2pos);
120 }
double & elem(int i)
Definition: dvector.h:152
double restore_prevariable_derivative()
Definition: cmpdif8.cpp:147
double & elem_value(int i)
Definition: fvar.hpp:2226
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
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
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
void save_dvector_position(const dvector &v)
Definition: cmpdif4.cpp:32
prnstream & endl(prnstream &)
void save_prevariable_position(const prevariable &v)
Definition: cmpdif8.cpp:60
void save_dvector_value(const dvector &v)
Definition: cmpdif4.cpp:130
dvar_vector_position restore_dvar_vector_position()
Definition: cmpdif4.cpp:69
#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 save_identifier_string(const char *)
Writes a gradient stack verification string.
Definition: cmpdif2.cpp:315
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
void dvcv_dot(void)
Description not yet available.
Definition: fvar_a16.cpp:90
Stores the adjoint gradient data that will be processed by gradcalc.
static _THREAD grad_stack * GRAD_STACK1
class for things related to the gradient structures, including dimension of arrays, size of buffers, etc.
int indexmax() const
Definition: fvar.hpp:2292
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518