ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_m23.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 #include "fvar.hpp"
12 
13 void dvdm_prod(void);
14 void dvcm_prod(void);
15 
21  {
25 
26  if (x.indexmin() != m.rowmin() || x.indexmax() != m.rowmax())
27  {
28  cerr << " Incompatible array bounds in "
29  "dvar_vector operator*(const dvar_matrix& m, const dvar_vector& x)\n";
30  ad_exit(21);
31  }
32 
33  kkludge_object kkk;
34  dvar_vector tmp(m.colmin(),m.colmax(),kkk);
35  double sum;
36  for (int j=m.colmin(); j<=m.colmax(); j++)
37  {
38  sum=0.0;
39  for (int i=x.indexmin(); i<=x.indexmax(); i++)
40  {
41  //sum+=x[i]*m[i][j];
42  sum+=x.elem_value(i)*(m.elem(i)).elem_value(j);
43  }
44  tmp.elem_value(j)=sum;
45  }
46 
47  save_identifier_string("PLACE4");
50  save_identifier_string("PLACE3");
53  save_identifier_string("PLACE2");
55  save_identifier_string("PLACE1");
58  return(tmp);
59  }
60 
65 void dvdm_prod(void)
66 {
68 
69  verify_identifier_string("PLACE1");
71  verify_identifier_string("PLACE2");
74  verify_identifier_string("PLACE3");
77  verify_identifier_string("PLACE4");
79 
80  dmatrix dfm(m_pos);
81  dvector dfx(x_pos.indexmin(),x_pos.indexmax());
82  dfm.initialize();
83  dfx.initialize();
84 
85  double dfsum;
86  for (int j=m.colmax(); j>=m.colmin(); j--)
87  {
88  //tmp.elem_value(j)=sum;
89  dfsum=dftmp.elem(j);
90  for (int i=x.indexmax(); i>=x.indexmin(); i--)
91  {
92  //sum+=x[i]*m[i][j];
93  //sum+=x.elem_value(i)*(m.elem(i)).elem_value(j);
94  dfm.elem(i,j)+=dfsum*x.elem(i);
95  dfx.elem(i)+=dfsum*m.elem(i,j);
96  }
97  //sum=0.0;
98  dfsum=0.0;
99  }
100  dfx.save_dvector_derivatives(x_pos);
101  dfm.save_dmatrix_derivatives(m_pos);
102 }
103 
109  {
113 
114  if (x.indexmin() != m.rowmin() || x.indexmax() != m.rowmax())
115  {
116  cerr << " Incompatible array bounds in "
117  "dvar_vector operator*(const dvar_matrix& m, const dvar_vector& x)\n";
118  ad_exit(21);
119  }
120 
121  kkludge_object kkk;
122  dvar_vector tmp(m.colmin(),m.colmax(),kkk);
123  double sum;
124  for (int j=m.colmin(); j<=m.colmax(); j++)
125  {
126  sum=0.0;
127  for (int i=x.indexmin(); i<=x.indexmax(); i++)
128  {
129  //sum+=x[i]*m[i][j];
130  sum+=x.elem_value(i)*(m.elem(i)).elem(j);
131  }
132  tmp.elem_value(j)=sum;
133  }
134 
137  save_identifier_string("PLACE3");
138  fp->save_dmatrix_value(m);
139  fp->save_dmatrix_position(m);
140  save_identifier_string("PLACE2");
141  fp->save_dvar_vector_position(tmp);
142  save_identifier_string("PLACE1");
145  return(tmp);
146  }
147 
152 void dvcm_prod(void)
153 {
155 
156  verify_identifier_string("PLACE1");
158  verify_identifier_string("PLACE2");
160  dmatrix m=fp->restore_dvar_matrix_value(m_pos);
161  verify_identifier_string("PLACE3");
165 
166  dvector dfx(x_pos.indexmin(),x_pos.indexmax());
167  dfx.initialize();
168 
169  double dfsum;
170  int imax=dfx.indexmax();
171  int imin=dfx.indexmin();
172  for (int j=m.colmax(); j>=m.colmin(); j--)
173  {
174  //tmp.elem_value(j)=sum;
175  dfsum=dftmp.elem(j);
176  for (int i=imax; i>=imin; i--)
177  {
178  //sum+=x[i]*m[i][j];
179  //sum+=x.elem_value(i)*(m.elem(i)).elem_value(j);
180  dfx.elem(i)+=dfsum*m.elem(i,j);
181  }
182  //sum=0.0;
183  dfsum=0.0;
184  }
185  dfx.save_dvector_derivatives(x_pos);
186 }
int rowmax(void) const
Definition: fvar.hpp:2564
dvar_vector & elem(int i)
Definition: fvar.hpp:2507
double & elem(int i)
Definition: dvector.h:152
double & elem_value(int i)
Definition: fvar.hpp:2226
int colmin(void) const
Definition: fvar.hpp:2552
#define x
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Get minimum valid index.
Definition: dvector.h:199
void save_dmatrix_position(const dmatrix &m)
Definition: cmpdif6.cpp:31
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
int indexmin() const
Definition: fvar.hpp:4827
exitptr ad_exit
Definition: gradstrc.cpp:53
void save_dmatrix_value(const dmatrix &m)
Definition: cmpdif5.cpp:26
Null class to allow specialized function overloads.
Definition: fvar.hpp:469
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
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
dmatrix restore_dvar_matrix_value(const dvar_matrix_position &mpos)
Definition: cmpdif5.cpp:74
int rowmax() const
Definition: fvar.hpp:2929
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
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 save_dmatrix_derivatives(const dvar_matrix_position &pos) const
Description not yet available.
Definition: cmpdif5.cpp:285
static _THREAD gradient_structure * _instance
int colmin(void) const
Definition: fvar.hpp:2939
int rowmin(void) const
Definition: fvar.hpp:2560
Description not yet available.
Definition: fvar.hpp:2819
void initialize(void)
Initialze all elements of dvector to zero.
Definition: dvect5.cpp:10
dvector & elem(int i)
Definition: fvar.hpp:3011
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
dvar_matrix_position restore_dvar_matrix_position()
Definition: cmpdif6.cpp:114
static _THREAD DF_FILE * fp
void save_dvar_matrix_position(const dvar_matrix &m)
Definition: cmpdif5.cpp:345
void dvcm_prod(void)
Description not yet available.
Definition: fvar_m23.cpp:152
Class definition of matrix with derivitive information .
Definition: fvar.hpp:2480
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 save_dvar_matrix_value(const dvar_matrix &m)
Definition: cmpdif4.cpp:252
void RETURN_ARRAYS_DECREMENT()
Definition: gradstrc.cpp:511
static _THREAD grad_stack * GRAD_STACK1
class for things related to the gradient structures, including dimension of arrays, size of buffers, etc.
void initialize(void)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: dmat7.cpp:12
int indexmax() const
Definition: fvar.hpp:2292
int rowmin() const
Definition: fvar.hpp:2925
void dvdm_prod(void)
Description not yet available.
Definition: fvar_m23.cpp:65
int colmax(void) const
Definition: fvar.hpp:2943
int colmax(void) const
Definition: fvar.hpp:2556
Description not yet available.
Definition: fvar.hpp:4843