ADMB Documentation  11.1.1015
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_m34.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: fvar_m34.cpp 542 2012-07-10 21:04:06Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California 
00006  */
00011 #include "fvar.hpp"
00012 
00013 void dmcv_prod(void);
00014 
00019 dvar_vector operator*(const dvar_matrix& m, const dvector& x)
00020  {
00021    RETURN_ARRAYS_INCREMENT();
00022 
00023    if (x.indexmin() != m.colmin() || x.indexmax() != m.colmax())
00024    {
00025      cerr << " Incompatible array bounds in dvar_vector  operator * (const dvar_matrix& m, const dvar_vector& x)\n";
00026      ad_exit(21);
00027    }
00028 
00029    kkludge_object kkk;
00030    dvar_vector tmp(m.rowmin(),m.rowmax(),kkk);
00031    double sum;
00032 
00033    for (int i=m.rowmin(); i<=m.rowmax(); i++)
00034    {
00035      sum=0.0;
00036      const dvar_vector& tt=m.elem(i);
00037      for (int j=x.indexmin(); j<=x.indexmax(); j++)
00038      {
00039        //sum+=m[i][j]*x[j];
00040        sum+=tt.elem_value(j)*x.elem(j);
00041      }
00042      tmp.elem_value(i)=sum;
00043    }
00044   save_identifier_string("PL4");
00045   x.save_dvector_value();
00046   x.save_dvector_position();
00047   m.save_dvar_matrix_position();
00048   tmp.save_dvar_vector_position();
00049   save_identifier_string("PLX");
00050   gradient_structure::GRAD_STACK1->
00051       set_gradient_stack(dmcv_prod);
00052    RETURN_ARRAYS_DECREMENT();
00053    return(tmp);
00054  }
00055 
00060 void dmcv_prod(void)
00061 {
00062   verify_identifier_string("PLX");
00063   dvar_vector_position tmp_pos=restore_dvar_vector_position();
00064   dvar_matrix_position m_pos=restore_dvar_matrix_position();
00065   dvar_vector_position x_pos=restore_dvar_vector_position();
00066   dvector x=restore_dvar_vector_value(x_pos);
00067   verify_identifier_string("PL4");
00068   dvector dftmp=restore_dvar_vector_derivatives(tmp_pos);
00069   
00070   dmatrix dfm(m_pos);
00071   dfm.initialize();
00072   
00073    double dfsum;
00074    int mmin=dfm.rowmin(); 
00075    int mmax=dfm.rowmax();
00076    for (int i=mmax; i>=mmin; i--)
00077    {
00078      // tmp.elem_value(i)=sum;
00079      dfsum=dftmp.elem(i);
00080      dvector& tt=dfm.elem(i);
00081      for (int j=x.indexmax(); j>=x.indexmin(); j--)
00082      {
00083        //sum+=(m.elem(i)).elem_value(j)*x.elem_value(j);
00084        tt.elem(j)+=dfsum*x.elem(j);
00085      }
00086      //sum=0.0;
00087      dfsum=0.0;
00088    }
00089    dfm.save_dmatrix_derivatives(m_pos);
00090 }