Exemple #1
0
 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;
 }
Exemple #2
0
  MyMat0<T,ROWMAJOR> matMulOpt(MyMat0<T,COLUMNMAJOR> const & m1,MyMat0<T,COLUMNMAJOR> const & m2)
  {
    MyMat0<T,ROWMAJOR> res(m1.nrow(),m2.ncol(),0.);
    std::vector<T> tmp(m1.ncol());

    for(size_type i=0; i<m1.nrow();++i)
      {
        // Store the i-th row of m1
        for (size_type l=0; l<m1.ncol(); ++l)
          {
            tmp[l]=m1(i,l);
          }
        for(size_type j=0; j<m2.ncol();++j)
          {
            size_type column_start = m2.gitIndex(0,j);
            res(i,j) = std::inner_product(tmp.begin(),tmp.end(),m2.cbegin()+column_start,T(0));
            /*
              for(size_type k=0; k<m2.nrow();++k)
              {
                res(i,j) += tmp[k]*m2(k,j);
              }
            */
          }
      }
    return res;
    
  }
Exemple #3
0
 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;
 }