コード例 #1
0
ファイル: MyMat0_util.hpp プロジェクト: 10376920/pacs
 MyMat0<T,ROWMAJOR> matMulOpt(MyMat0<T,ROWMAJOR> const & m1,MyMat0<T,ROWMAJOR> const & m2)
 {
   
   MyMat0<T,ROWMAJOR> res(m1.nrow(),m2.ncol(),0.);
   std::vector<T> tmp(m2.nrow());
   for(size_type j=0; j<m2.ncol();++j)
     {
       // Store the jth column of m2
       for (size_type l=0; l<m2.nrow(); ++l)
         {
           tmp[l]=m2(l,j);
         }
       for(size_type i=0; i<m1.nrow();++i)
         {
           size_type row_starts= m1.getIndex(i,0);
           res(i,j) = std::inner_product(tmp.begin(),tmp.end(),m1.cbegin()+row_starts,T(0));
           /*
           for(size_type k=0; k<m2.nrow();++k)
             {
               res(i,j) += m1(i,k)*tmp[k];
               }
           */
         }
     }
   return res;
 }
コード例 #2
0
ファイル: MyMat0_util.hpp プロジェクト: 10376920/pacs
 MyMat0<T,ROWMAJOR> matMulOpt(MyMat0<T,ROWMAJOR> const & m1,MyMat0<T,COLUMNMAJOR> const & m2)
 {
   MyMat0<T,ROWMAJOR> res(m1.nrow(),m2.ncol(),0.);
   for(size_type i=0; i<m1.nrow();++i)
     {
       for(size_type j=0; j<m2.ncol();++j)
         {
           size_type column_start = m2.getIndex(0,j);
           size_type row_start = m1.getIndex(i,0);
           size_type row_end   = m1.getIndex(i+1,0);
           res(i,j) = std::inner_product(
                                         m1.cbegin()+row_start,
                                         m1.cbegin()+row_end,
                                         m2.cbegin()+column_start,
                                         T(0));
         }
     }
       /*
       for(size_type k=0; k<m2.nrow();++k)
       res(i,j) += m1(i,k)*m2(k,j);
       */
   return res;
 }