Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00011
00012
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 dmatrix operator*(const dvar_matrix& x, const dmatrix& m)\n";
00036 ad_exit(21);
00037 }
00038 dmatrix cm1=value(m1);
00039
00040 dmatrix tmp(m1.rowmin(),m1.rowmax(), cm2.colmin(), cm2.colmax());
00041 double sum;
00042 double * temp_col=(double *) malloc(cm2.rowsize()*sizeof(double));
00043 temp_col-=cm2.rowmin();
00044
00045
00046 for (int j=cm2.colmin(); j<=cm2.colmax(); j++)
00047 {
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
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
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
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
00105 dfsum=dftmp.elem(i,j);
00106 for (int k=dfm1.colmin(); k<=dfm1.colmax(); k++)
00107 {
00108
00109 dfm1.elem(i,k)+=dfsum * cm2.elem(k,j);
00110
00111 }
00112 }
00113 }
00114 dfm1.save_dmatrix_derivatives(m1pos);
00115
00116
00117 }