ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_m18.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 #ifdef __TURBOC__
14  #pragma hdrstop
15  #include <iostream.h>
16 #endif
17 
18 #ifdef __ZTC__
19  #include <iostream.hpp>
20 #endif
21 
22 #ifndef OPT_LIB
23  #include <cassert>
24 #endif
25 
26 void cmdm_prod(void);
27 
32 dvar_matrix operator*(const dmatrix& cm1, const dvar_matrix& m2)
33  {
34  if (cm1.colmin() != m2.rowmin() || cm1.colmax() != m2.rowmax())
35  {
36  cerr << " Incompatible array bounds in "
37  "dmatrix operator*(const dmatrix& x, const dvar_matrix& m)\n";
38  ad_exit(21);
39  }
40  dmatrix cm2=value(m2);
41  dmatrix tmp(cm1.rowmin(),cm1.rowmax(), m2.colmin(), m2.colmax());
42 
43  const unsigned int rowsize = m2.rowsize();
44  try
45  {
46  double* temp_col = new double[rowsize];
47 
48  temp_col-=cm2.rowmin();
49 
50  for (int j=cm2.colmin(); j<=cm2.colmax(); j++)
51  {
52  for (int k=cm2.rowmin(); k<=cm2.rowmax(); k++)
53  {
54  temp_col[k] = cm2.elem(k,j);
55  }
56  for (int i=cm1.rowmin(); i<=cm1.rowmax(); i++)
57  {
58  double sum=0.0;
59  const dvector& temp_row = cm1(i);
60  for (int k=cm1.colmin(); k<=cm1.colmax(); k++)
61  {
62  sum+=temp_row(k) * (temp_col[k]);
63  // sum+=temp_row(k) * cm2(k,j);
64  }
65  tmp(i,j)=sum;
66  }
67  }
68  temp_col+=cm2.rowmin();
69  delete [] temp_col;
70  temp_col = 0;
71  }
72  catch (std::bad_alloc& e)
73  {
74  cerr << "Error[" << __FILE__ << ':' << __LINE__
75  << "]: Unable to allocate array.\n";
76  //ad_exit(21);
77  throw e;
78  }
79 
82  dvar_matrix vtmp=nograd_assign(tmp);
83  save_identifier_string("TEST1");
84  fp->save_dmatrix_value(cm1);
85  fp->save_dmatrix_position(cm1);
86  // m2.save_dvar_matrix_value();
88  fp->save_dvar_matrix_position(vtmp);
89  save_identifier_string("TEST6");
91  return vtmp;
92  }
93 
98 void cmdm_prod(void)
99 {
101 
102  verify_identifier_string("TEST6");
106  //dmatrix cm2=restore_dvar_matrix_value(m2pos);
108  dmatrix cm1=fp->restore_dmatrix_value(m1pos);
109  verify_identifier_string("TEST1");
110  //dmatrix dfm1(m1pos);
111  dmatrix dfm2(m2pos);
112  double dfsum;
113  dfm2.initialize();
114  for (int j=dfm2.colmin(); j<=dfm2.colmax(); j++)
115  {
116  for (int i=cm1.rowmin(); i<=cm1.rowmax(); i++)
117  {
118  //tmp.elem(i,j)=sum;
119  dfsum=dftmp.elem(i,j);
120  for (int k=cm1.colmin(); k<=cm1.colmax(); k++)
121  {
122  //sum+=cm1(i,k) * cm2(k,j);
123  //dfm1.elem(i,k)+=dfsum * cm2.elem(k,j);
124  dfm2.elem(k,j)+=dfsum * cm1.elem(i,k);
125  }
126  }
127  }
128  //dfm1.save_dmatrix_derivatives(m1pos);
129  dfm2.save_dmatrix_derivatives(m2pos);
130  // cout << "leaving dmdm_prod"<<endl;
131 }
Description not yet available.
Definition: fvar.hpp:4883
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
void save_dmatrix_position(const dmatrix &m)
Definition: cmpdif6.cpp:31
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
dmatrix_position restore_dmatrix_position()
Definition: cmpdif6.cpp:147
void save_dmatrix_value(const dmatrix &m)
Definition: cmpdif5.cpp:26
void verify_identifier_string(const char *)
Verifies gradient stack string.
Definition: cmpdif3.cpp:149
void cmdm_prod(void)
Description not yet available.
Definition: fvar_m18.cpp:98
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
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
int rowmax() const
Definition: fvar.hpp:2929
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
unsigned int rowsize() const
Definition: fvar.hpp:2578
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 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