ADMB Documentation  11.1.2178
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_m34.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: fvar_m34.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 #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 "
00026      "dvar_vector operator * (const dvar_matrix& m, const dvar_vector& x)\n";
00027      ad_exit(21);
00028    }
00029 
00030    kkludge_object kkk;
00031    dvar_vector tmp(m.rowmin(),m.rowmax(),kkk);
00032    double sum;
00033 
00034    for (int i=m.rowmin(); i<=m.rowmax(); i++)
00035    {
00036      sum=0.0;
00037      const dvar_vector& tt=m.elem(i);
00038      for (int j=x.indexmin(); j<=x.indexmax(); j++)
00039      {
00040        //sum+=m[i][j]*x[j];
00041        sum+=tt.elem_value(j)*x.elem(j);
00042      }
00043      tmp.elem_value(i)=sum;
00044    }
00045   save_identifier_string("PL4");
00046   x.save_dvector_value();
00047   x.save_dvector_position();
00048   m.save_dvar_matrix_position();
00049   tmp.save_dvar_vector_position();
00050   save_identifier_string("PLX");
00051   gradient_structure::GRAD_STACK1->
00052       set_gradient_stack(dmcv_prod);
00053    RETURN_ARRAYS_DECREMENT();
00054    return(tmp);
00055  }
00056 
00061 void dmcv_prod(void)
00062 {
00063   verify_identifier_string("PLX");
00064   dvar_vector_position tmp_pos=restore_dvar_vector_position();
00065   dvar_matrix_position m_pos=restore_dvar_matrix_position();
00066   dvar_vector_position x_pos=restore_dvar_vector_position();
00067   dvector x=restore_dvar_vector_value(x_pos);
00068   verify_identifier_string("PL4");
00069   dvector dftmp=restore_dvar_vector_derivatives(tmp_pos);
00070 
00071   dmatrix dfm(m_pos);
00072   dfm.initialize();
00073 
00074    double dfsum;
00075    int mmin=dfm.rowmin();
00076    int mmax=dfm.rowmax();
00077    for (int i=mmax; i>=mmin; i--)
00078    {
00079      // tmp.elem_value(i)=sum;
00080      dfsum=dftmp.elem(i);
00081      dvector& tt=dfm.elem(i);
00082      for (int j=x.indexmax(); j>=x.indexmin(); j--)
00083      {
00084        //sum+=(m.elem(i)).elem_value(j)*x.elem_value(j);
00085        tt.elem(j)+=dfsum*x.elem(j);
00086      }
00087      //sum=0.0;
00088      dfsum=0.0;
00089    }
00090    dfm.save_dmatrix_derivatives(m_pos);
00091 }