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