Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00011
00012
00013 #include "fvar.hpp"
00014
00015 #ifdef __TURBOC__
00016 #pragma hdrstop
00017 #include <iostream.h>
00018 #endif
00019
00020 #ifdef __ZTC__
00021 #include <iostream.hpp>
00022 #endif
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00083 dvar_matrix operator*(const dvar_matrix& m1, const dvar_matrix& m2)
00084 {
00085 if (m1.colmin() != m2.rowmin() || m1.colmax() != m2.rowmax())
00086 {
00087 cerr << " Incompatible array bounds in dmatrix operator*(const dmatrix& x, const dmatrix& m)\n";
00088 ad_exit(21);
00089 }
00090
00091
00092 dmatrix tmp(m1.rowmin(),m1.rowmax(), m2.colmin(), m2.colmax());
00093 double sum;
00094
00095
00096 for (int j=m2.colmin(); j<=m2.colmax(); j++)
00097 {
00098
00099 dvector m2col=column_value(m2,j);
00100
00101 for (int i=m1.rowmin(); i<=m1.rowmax(); i++)
00102 {
00103 sum=value(m1(i))*m2col;
00104 tmp(i,j)=sum;
00105 }
00106 }
00107
00108 dvar_matrix vtmp=nograd_assign(tmp);
00109 save_identifier_string("TEST1");
00110 m1.save_dvar_matrix_value();
00111 m1.save_dvar_matrix_position();
00112 m2.save_dvar_matrix_value();
00113 m2.save_dvar_matrix_position();
00114 vtmp.save_dvar_matrix_position();
00115 save_identifier_string("TEST6");
00116 gradient_structure::GRAD_STACK1->
00117 set_gradient_stack(dmdm_prod);
00118 return vtmp;
00119 }
00120
00125 void dmdm_prod(void)
00126 {
00127 verify_identifier_string("TEST6");
00128 dvar_matrix_position vpos=restore_dvar_matrix_position();
00129 dmatrix dftmp=restore_dvar_matrix_derivatives(vpos);
00130 dvar_matrix_position m2pos=restore_dvar_matrix_position();
00131 dmatrix cm2=restore_dvar_matrix_value(m2pos);
00132 dvar_matrix_position m1pos=restore_dvar_matrix_position();
00133 dmatrix cm1=restore_dvar_matrix_value(m1pos);
00134 verify_identifier_string("TEST1");
00135 dmatrix dfm1(m1pos);
00136 dmatrix dfm2(m2pos);
00137 double dfsum;
00138 dfm1.initialize();
00139 dfm2.initialize();
00140 for (int j=cm2.colmin(); j<=cm2.colmax(); j++)
00141 {
00142 for (int i=cm1.rowmin(); i<=cm1.rowmax(); i++)
00143 {
00144
00145 dfsum=dftmp.elem(i,j);
00146 for (int k=cm1.colmin(); k<=cm1.colmax(); k++)
00147 {
00148
00149 dfm1.elem(i,k)+=dfsum * cm2.elem(k,j);
00150 dfm2.elem(k,j)+=dfsum * cm1.elem(i,k);
00151 }
00152 }
00153 }
00154 dfm1.save_dmatrix_derivatives(m1pos);
00155 dfm2.save_dmatrix_derivatives(m2pos);
00156
00157 }