ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_m22.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 dmdv_prod(void);
14 void cmdv_prod(void);
15 
21 {
24 
26 
27  int imin = m.rowmin();
28  int imax = m.rowmax();
29  int jmin = x.indexmin();
30  int jmax = x.indexmax();
31 #ifndef OPT_LIB
32  if (jmin != m.colmin() || jmax != m.colmax())
33  {
34  cerr << " Incompatible array bounds in "
35  "dvar_vector operator*(const dvar_matrix& m, const dvar_vector& x)\n";
36  ad_exit(21);
37  }
38 #endif
39 
40  kkludge_object kkk;
41  dvar_vector tmp(imin, imax, kkk);
42  double_and_int* ptmp = tmp.va + imin;
43  for (int i = imin; i <= imax; ++i)
44  {
45  double_and_int* px = x.va + jmin;
46  dvar_vector& mi = m.elem(i);
47  double_and_int* pmi = mi.va + jmin;
48 
49  double sum = 0.0;
50  for (int j = jmin; j <= jmax; ++j)
51  {
52  //sum+=m[i][j]*x[j];
53  sum += pmi->x * px->x;
54  ++px;
55  ++pmi;
56  }
57  ptmp->x = sum;
58  ++ptmp;
59  }
60  save_identifier_string("PLACE4");
63  save_identifier_string("PLACE3");
66  save_identifier_string("PLACE2");
68  save_identifier_string("PLACE1");
71  return(tmp);
72 }
73 
78 void dmdv_prod(void)
79 {
81 
82  verify_identifier_string("PLACE1");
84  verify_identifier_string("PLACE2");
87  verify_identifier_string("PLACE3");
90  verify_identifier_string("PLACE4");
92 
93  dmatrix dfm(m_pos);
94  dvector dfx(x_pos.indexmin(),x_pos.indexmax());
95  dfm.initialize();
96  dfx.initialize();
97 
98  int imax = m.rowmax();
99  int imin = m.rowmin();
100  int jmax = x.indexmax();
101  int jmin = x.indexmin();
102  double* pdftmp = dftmp.get_v() + imax;
103  for (int i = imax; i >= imin; --i)
104  {
105  //tmp.elem_value(i)=sum;
106  double dfsum = *pdftmp;
107  double* px = x.get_v() + jmax;
108  double* pdfx = dfx.get_v() + jmax;
109  double* pdfmi = dfm(i).get_v() + jmax;
110  double* pmi = m(i).get_v() + jmax;
111  for (int j = jmax; j >= jmin; --j)
112  {
113  //sum+=(m.elem(i)).elem_value(j)*x.elem_value(j);
114  *pdfmi += dfsum * *px;
115  *pdfx += dfsum * *pmi;
116  --px;
117  --pdfx;
118  --pdfmi;
119  --pmi;
120  }
121  //sum=0.0;
122  dfsum=0.0;
123 
124  --pdftmp;
125  }
126  dfx.save_dvector_derivatives(x_pos);
127  dfm.save_dmatrix_derivatives(m_pos);
128 }
129 
135 {
139 
140  int imin = m.rowmin();
141  int imax = m.rowmax();
142  int jmin = x.indexmin();
143  int jmax = x.indexmax();
144 
145 #ifndef OPT_LIB
146  if (jmin != m.colmin() || jmax != m.colmax())
147  {
148  cerr << " Incompatible array bounds in "
149  "dvar_vector operator*(const dvar_matrix& m, const dvar_vector& x)\n";
150  ad_exit(21);
151  }
152 #endif
153 
154  kkludge_object kkk;
155  dvar_vector tmp(imin, imax, kkk);
156 
157  double_and_int* ptmpi = tmp.va + imin;
158  const dvector* pmi = &m(imin);
159  for (int i = imin; i <= imax; ++i)
160  {
161  double sum = 0.0;
162  double_and_int* pxj = x.va + jmin;
163  double* pmij = pmi->get_v() + jmin;
164  for (int j = jmin; j <= jmax; ++j)
165  {
166  //sum+=m[i][j]*x[j];
167  sum += *pmij * pxj->x;
168 
169  ++pxj;
170  ++pmij;
171  }
172  //tmp.elem_value(i) = sum;
173  ptmpi->x = sum;
174 
175  ++ptmpi;
176  ++pmi;
177  }
178 
179  //save_identifier_string("PLACE4");
180  fp->save_dvar_vector_value(x);
182  fp->save_dmatrix_value(m);
183  fp->save_dmatrix_position(m);
184  //save_identifier_string("PLACE2");
185  fp->save_dvar_vector_position(tmp);
186  //save_identifier_string("PLACE1");
189  return tmp;
190 }
191 
196 void cmdv_prod(void)
197 {
199 
200  //verify_identifier_string("PLACE1");
202  //verify_identifier_string("PLACE2");
204  dmatrix m=fp->restore_dmatrix_value(m_pos);
207  //verify_identifier_string("PLACE4");
209 
210  int jmax = x.indexmax();
211  int jmin = x.indexmin();
212  dvector dfx(jmin, jmax);
213  dfx.initialize();
214 
215  int imax = m.rowmax();
216  int imin = m.rowmin();
217  dvector* pmi = &m(imax);
218  double* pdftmpi = dftmp.get_v() + imax;
219  for (int i = imax; i >= imin; --i)
220  {
221  // tmp.elem_value(i)=sum;
222  double dfsum = *pdftmpi;
223  double* pmij = pmi->get_v() + jmax;
224  double* pdfxj = dfx.get_v() + jmax;
225  for (int j = jmax; j >= jmin; --j)
226  {
227  //sum+=(m.elem(i)).elem(j)*x.elem_value(j);
228  *pdfxj += dfsum * *pmij;
229 
230  --pmij;
231  --pdfxj;
232  }
233  //sum=0.0;
234  dfsum = 0.0;
235 
236  --pmi;
237  --pdftmpi;
238  }
239  dfx.save_dvector_derivatives(x_pos);
240 }
Description not yet available.
Definition: fvar.hpp:4883
int rowmax(void) const
Definition: fvar.hpp:2564
dvar_vector & elem(int i)
Definition: fvar.hpp:2507
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
void cmdv_prod(void)
Description not yet available.
Definition: fvar_m22.cpp:196
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
dmatrix_position restore_dmatrix_position()
Definition: cmpdif6.cpp:147
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 restore_dmatrix_value(const dmatrix_position &mpos)
Definition: cmpdif5.cpp:100
dmatrix operator*(const d3_array &t, const dvector &v)
Description not yet available.
Definition: d3arr12.cpp:17
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
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
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
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
double_and_int * va
Definition: fvar.hpp:2175
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
double *& get_v(void)
Definition: dvector.h:148
int indexmax() const
Definition: fvar.hpp:2292
int rowmin() const
Definition: fvar.hpp:2925
double x
&lt; value of the variable
Definition: fvar.hpp:195
int colmax(void) const
Definition: fvar.hpp:2943
void dmdv_prod(void)
Description not yet available.
Definition: fvar_m22.cpp:78
int colmax(void) const
Definition: fvar.hpp:2556
Description not yet available.
Definition: fvar.hpp:4843