ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_m14.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 // constructors, destructors and misc functions involving class prevariable
12 
13 #include "fvar.hpp"
14 
15 #ifdef __TURBOC__
16  #pragma hdrstop
17  #include <iostream.h>
18 #endif
19 
20 #ifdef __ZTC__
21  #include <iostream.hpp>
22 #endif
23 
24 /*
25  dvar_matrix operator*(const dvar_matrix& m1, const dvar_matrix& m2 )
26  {
27  if (m1.colmin() != m2.rowmin() || m1.colmax() != m2.rowmax())
28  {
29  cerr << " Incompatible array bounds in dmatrix operator * (const dmatrix& x, const dmatrix& m)\n";
30  ad_exit(21);
31  }
32  //dmatrix cm1=value(m1);
33  //dmatrix cm2=value(m2);
34  dmatrix tmp(m1.rowmin(),m1.rowmax(), m2.colmin(), m2.colmax());
35  double sum;
36  double ** temp_col=(double **) malloc(m2.rowsize()*sizeof(double*));
37  temp_col-=m2.rowmin();
38 
39 
40  for (int j=m2.colmin(); j<=m2.colmax(); j++)
41  {
42 
43  for (int k=m2.rowmin(); k<=m2.rowmax(); k++)
44  {
45  temp_col[k] = (double*) &m2.elem_value(k,j);
46  }
47 
48  for (int i=m1.rowmin(); i<=m1.rowmax(); i++)
49  {
50  sum=0.0;
51  const dvar_vector& temp_row = m1(i);
52  for (int k=m1.colmin(); k<=m1.colmax(); k++)
53  {
54  sum+=temp_row.elem_value(k) * (*temp_col[k]);
55  // sum+=temp_row(k) * cm2(k,j);
56  }
57  tmp(i,j)=sum;
58  }
59  }
60 
61 
62  temp_col+=m2.rowmin();
63  free ((char*)temp_col);
64  dvar_matrix vtmp=nograd_assign(tmp);
65  gradient_structure* gs = gradient_structure::get();
66  DF_FILE* fp = gs->fp;
67  save_identifier_string("TEST1");
68  m1.save_dvar_matrix_value(fp);
69  m1.save_dvar_matrix_position(fp);
70  m2.save_dvar_matrix_value(fp);
71  m2.save_dvar_matrix_position(fp);
72  vtmp.save_dvar_matrix_position(fp);
73  save_identifier_string("TEST6");
74  gs->GRAD_STACK1->set_gradient_stack(dmdm_prod);
75  return vtmp;
76  }
77 */
78 
84  {
85  if (m1.colmin() != m2.rowmin() || m1.colmax() != m2.rowmax())
86  {
87  cerr << " Incompatible array bounds in "
88  "dmatrix operator*(const dmatrix& x, const dmatrix& m)\n";
89  ad_exit(21);
90  }
91  //dmatrix cm1=value(m1);
92  //dmatrix cm2=value(m2);
93  dmatrix tmp(m1.rowmin(),m1.rowmax(), m2.colmin(), m2.colmax());
94  double sum;
95 
96 
97  for (int j=m2.colmin(); j<=m2.colmax(); j++)
98  {
99  dvector m2col=column_value(m2,j);
100 
101  for (int i=m1.rowmin(); i<=m1.rowmax(); i++)
102  {
103  sum=value(m1(i))*m2col;
104  tmp(i,j)=sum;
105  }
106  }
107 
108  dvar_matrix vtmp=nograd_assign(tmp);
111  save_identifier_string("TEST1");
112  fp->save_dvar_matrix_value(m1);
114  fp->save_dvar_matrix_value(m2);
116  fp->save_dvar_matrix_position(vtmp);
117  save_identifier_string("TEST6");
119  return vtmp;
120  }
121 
126 void dmdm_prod(void)
127 {
129 
130  verify_identifier_string("TEST6");
134  dmatrix cm2=fp->restore_dvar_matrix_value(m2pos);
136  dmatrix cm1=fp->restore_dvar_matrix_value(m1pos);
137  verify_identifier_string("TEST1");
138  dmatrix dfm1(m1pos);
139  dmatrix dfm2(m2pos);
140  double dfsum;
141  dfm1.initialize();
142  dfm2.initialize();
143  for (int j=cm2.colmin(); j<=cm2.colmax(); j++)
144  {
145  for (int i=cm1.rowmin(); i<=cm1.rowmax(); i++)
146  {
147  //tmp.elem(i,j)=sum;
148  dfsum=dftmp.elem(i,j);
149  for (int k=cm1.colmin(); k<=cm1.colmax(); k++)
150  {
151  //sum+=cm1(i,k) * cm2(k,j);
152  dfm1.elem(i,k)+=dfsum * cm2.elem(k,j);
153  dfm2.elem(k,j)+=dfsum * cm1.elem(i,k);
154  }
155  }
156  }
157  dfm1.save_dmatrix_derivatives(m1pos);
158  dfm2.save_dmatrix_derivatives(m2pos);
159  // cout << "leaving dmdm_prod"<<endl;
160 }
int rowmax(void) const
Definition: fvar.hpp:2564
int colmin(void) const
Definition: fvar.hpp:2552
Vector of double precision numbers.
Definition: dvector.h:50
dmatrix restore_dvar_matrix_derivatives(const dvar_matrix_position &_pos)
Description not yet available.
Definition: cmpdif6.cpp:178
dvar_vector nograd_assign(dvector tmp)
Description not yet available.
Definition: cmpdif6.cpp:252
double sum(const d3_array &darray)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr.cpp:21
exitptr ad_exit
Definition: gradstrc.cpp:53
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
void dmdm_prod(void)
Description not yet available.
Definition: fvar_m14.cpp:126
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
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 column_value(const dvar_matrix &m, int i)
Description not yet available.
Definition: fvar_ar7.cpp:57
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.
void save_dvar_matrix_value(const dvar_matrix &m)
Definition: cmpdif4.cpp:252
dvector value(const df1_one_vector &v)
Definition: df11fun.cpp:69
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 rowmin() const
Definition: fvar.hpp:2925
int colmax(void) const
Definition: fvar.hpp:2943
int colmax(void) const
Definition: fvar.hpp:2556
Description not yet available.
Definition: fvar.hpp:4843