Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00011 #include "fvar.hpp"
00012
00017 ivector diagonal(const imatrix& m)
00018 {
00019 if (m.indexmin() != m.colmin() || m.indexmax() != m.colmax())
00020 {
00021 cerr << "Error matrix not square in function diagonal" << endl;
00022 exit(21);
00023 }
00024 int mmin=m.indexmin();
00025 int mmax=m.indexmax();
00026 ivector tmp(mmin,mmax);
00027 for (int i=mmin;i<=mmax;i++)
00028 tmp(i)=m(i,i);
00029 return tmp;
00030 }
00040 int operator*(const ivector& t1, const ivector& t2)
00041 {
00042 if (t1.indexmin() != t2.indexmin() || t1.indexmax() != t2.indexmax())
00043 {
00044 cerr << "Index bounds do not match in "
00045 "ivector operator*(const ivector&, const ivector&)\n";
00046 ad_exit(1);
00047 }
00048 int tmp = 0;
00049 #ifdef OPT_LIB
00050 const int* pt1=&t1[t1.indexmin()];
00051 const int* pt1m=&t1[t1.indexmax()];
00052 const int* pt2=&t2[t2.indexmin()];
00053 do
00054 {
00055 tmp+=*pt1++ * *pt2++;
00056 }
00057 while (pt1<=pt1m);
00058
00059 #else
00060 #ifndef USE_ASSEMBLER
00061 int min=t1.indexmin();
00062 int max=t1.indexmax();
00063 for (int i=min; i<=max; i++)
00064 {
00065 tmp+=t1[i]*t2[i];
00066 }
00067 #else
00068 int min=t1.indexmin();
00069 int n=t1.indexmax()-min+1;
00070 dp_dotproduct(&tmp,&(t1(min)),&(t2(min)),n);
00071 #endif
00072 #endif
00073
00074 return tmp;
00075 }
00076
00083 imatrix operator*(const imatrix& m1, const imatrix& m2 )
00084 {
00085 if (m1.colmin() != m2.rowmin() || m1.colmax() != m2.rowmax())
00086 {
00087 cerr << " Incompatible array bounds in "
00088 "imatrix operator * (const imatrix& x, const imatrix& m)\n";
00089 ad_exit(21);
00090 }
00091 imatrix tmp(m1.rowmin(),m1.rowmax(), m2.colmin(), m2.colmax());
00092 for (int j=m2.colmin(); j<=m2.colmax(); j++)
00093 {
00094 ivector m2col=column(m2,j);
00095 for (int i=m1.rowmin(); i<=m1.rowmax(); i++)
00096 {
00097 tmp(i,j) = m1(i) * m2col;
00098 }
00099 }
00100 return tmp;
00101 }