ADMB Documentation  11.1.2493
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_m19.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: fvar_m19.cpp 1919 2014-04-22 22:02:01Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 // file fvar.cpp
00012 // constructors, destructors and misc functions involving class prevariable
00013 
00014 #include "fvar.hpp"
00015 
00016 #ifdef __TURBOC__
00017   #pragma hdrstop
00018   #include <iostream.h>
00019 #endif
00020 
00021 #ifdef __ZTC__
00022   #include <iostream.hpp>
00023 #endif
00024 
00025 void dmcm_prod(void);
00026 
00031 dvar_matrix operator*(const dvar_matrix& m1, const dmatrix& cm2)
00032  {
00033    if (m1.colmin() != cm2.rowmin() || m1.colmax() != cm2.rowmax())
00034    {
00035      cerr << " Incompatible array bounds in "
00036      "dmatrix operator*(const dvar_matrix& x, const dmatrix& m)\n";
00037      ad_exit(21);
00038    }
00039    dmatrix cm1=value(m1);
00040    //dmatrix cm2=value(m2);
00041    dmatrix tmp(m1.rowmin(),m1.rowmax(), cm2.colmin(), cm2.colmax());
00042    double sum;
00043    double * temp_col=(double *) malloc(cm2.rowsize()*sizeof(double));
00044    temp_col-=cm2.rowmin();
00045 
00046 
00047    for (int j=cm2.colmin(); j<=cm2.colmax(); j++)
00048    {
00049      for (int k=cm2.rowmin(); k<=cm2.rowmax(); k++)
00050      {
00051        temp_col[k] = cm2.elem(k,j);
00052      }
00053 
00054      for (int i=cm1.rowmin(); i<=cm1.rowmax(); i++)
00055      {
00056        sum=0.0;
00057        dvector& temp_row = cm1(i);
00058        for (int k=cm1.colmin(); k<=cm1.colmax(); k++)
00059        {
00060           sum+=temp_row(k) * (temp_col[k]);
00061          // sum+=temp_row(k) * cm2(k,j);
00062        }
00063        tmp(i,j)=sum;
00064      }
00065    }
00066 
00067 
00068    temp_col+=cm2.rowmin();
00069    free ((char*)temp_col);
00070    dvar_matrix vtmp=nograd_assign(tmp);
00071    save_identifier_string("TEST1");
00072    //m1.save_dvar_matrix_value();
00073    m1.save_dvar_matrix_position();
00074    cm2.save_dmatrix_value();
00075    cm2.save_dmatrix_position();
00076    vtmp.save_dvar_matrix_position();
00077    save_identifier_string("TEST6");
00078    gradient_structure::GRAD_STACK1->
00079             set_gradient_stack(dmcm_prod);
00080    return vtmp;
00081  }
00082 
00087 void dmcm_prod(void)
00088 {
00089   verify_identifier_string("TEST6");
00090   dvar_matrix_position vpos=restore_dvar_matrix_position();
00091   dmatrix dftmp=restore_dvar_matrix_derivatives(vpos);
00092   dmatrix_position m2pos=restore_dmatrix_position();
00093   dmatrix cm2=restore_dmatrix_value(m2pos);
00094   dvar_matrix_position m1pos=restore_dvar_matrix_position();
00095   //dmatrix cm1=restore_dvar_matrix_value(m1pos);
00096   verify_identifier_string("TEST1");
00097   dmatrix dfm1(m1pos);
00098   double dfsum;
00099   dfm1.initialize();
00100   for (int j=cm2.colmin(); j<=cm2.colmax(); j++)
00101   {
00102     for (int i=dfm1.rowmin(); i<=dfm1.rowmax(); i++)
00103     {
00104       //tmp.elem(i,j)=sum;
00105       dfsum=dftmp.elem(i,j);
00106       for (int k=dfm1.colmin(); k<=dfm1.colmax(); k++)
00107       {
00108         //sum+=cm1(i,k) * cm2(k,j);
00109         dfm1.elem(i,k)+=dfsum * cm2.elem(k,j);
00110         //dfm2.elem(k,j)+=dfsum * cm1.elem(i,k);
00111       }
00112     }
00113   }
00114   dfm1.save_dmatrix_derivatives(m1pos);
00115   //dfm2.save_dmatrix_derivatives(m2pos);
00116   // cout << "leaving dmdm_prod"<<endl;
00117 }