ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_a15.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 cvdv_dot(void);
27 
32 dvariable operator*(const dvector& cv1, const dvar_vector& v2)
33 {
34 #ifndef OPT_LIB
35  if (cv1.indexmin()!=v2.indexmin()||cv1.indexmax()!=v2.indexmax())
36  {
37  cerr << "Incompatible bounds in "
38  "prevariable operator * (const dvar_vector& v1, const dvar_vector& v2)"
39  << endl;
40  ad_exit(1);
41  }
42 #endif
43  double tmp=0;
44  int mmin=cv1.indexmin();
45  int mmax=cv1.indexmax();
46 #ifdef OPT_LIB
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  for (int i=mmin;i<=mmax;i++)
58  {
59  tmp+=cv1.elem(i)*v2.elem_value(i);
60  }
61  #else
62  int min=cv1.indexmin();
63  int n=cv1.indexmax()-min+1;
64  dp_dotproduct(&tmp,&(cv1.elem(min)),&(v2.elem_value(min)),n);
65  #endif
66 #endif
67  dvariable vtmp=nograd_assign(tmp);
68 
71 
72  // The derivative list considerations
73  save_identifier_string("bbbb");
74  fp->save_dvector_value(cv1);
75  fp->save_dvector_position(cv1);
77  fp->save_prevariable_position(vtmp);
78  save_identifier_string("aaaa");
80  return vtmp;
81 }
82 
87 void cvdv_dot(void)
88 {
90 
92  double dftmp=fp->restore_prevariable_derivative();
95  dvector cv1=fp->restore_dvector_value(dpos);
96  dvector dfv2(cv1.indexmin(),cv1.indexmax());
98 #ifdef OPT_LIB
99  double * pc1=&cv1.elem(cv1.indexmin());
100  double * pc1m=&cv1(cv1.indexmax());
101  double * pdf=&dfv2.elem(cv1.indexmin());
102  do
103  {
104  *pdf++=dftmp* *pc1++;
105  }
106  while (pc1 <=pc1m);
107 #else
108  for (int i=cv1.indexmin();i<=cv1.indexmax();i++)
109  {
110  //tmp+=cv1(i)*cv2(i);
111  //dfv1(i)=dftmp*cv2(i);
112  dfv2.elem(i)=dftmp*cv1.elem(i);
113  }
114 #endif
115  //dfv1.save_dvector_derivatives(v1pos);
116  dfv2.save_dvector_derivatives(v2pos);
117 }
void cvdv_dot(void)
Description not yet available.
Definition: fvar_a15.cpp:87
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
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