Algorithm to matrix product MSR format

  • Thread starter drudox
  • Start date
  • Tags
    c++
  • #1
drudox
2
0
Hi everybody,
I'm writing some algebra classes in C++ , Now I'm implementing the modified sparse row matrix , I wrote all most all of the class, but I didn't find the way saving computing time to perform the product of two Modified sparse row matrix .. if you don't know it you can read in the link : http://www.iue.tuwien.ac.at/phd/wagner/node83.html

by the way .. the matrix constructor is written as follow :
Code:
template <typename T>
constexpr MCSRmatrix<T>::MCSRmatrix( std::initializer_list<std::initializer_list<T>> rows)
{
      this->dim  = rows.size();
      auto _rows = *(rows.begin());

      aa_.resize(dim+1);
      ja_.resize(dim+1);

      if(dim != _rows.size())
      {
          throw std::runtime_error("Error in costructor! MCSR format require square matrix!");
      }

      itype w = 0 ;
      ja_.at(w) = dim+2 ;
      for(auto ii = rows.begin(), i=1; ii != rows.end() ; ++ii, i++)
      {
          for(auto ij = ii->begin(), j=1, elemCount = 0 ; ij != ii->end() ; ++ij, j++ )  
          {
              if(i==j)
                 aa_[i-1] = *ij ;
              else if( i != j && *ij != 0 )
              {  
                 ja_.push_back(j);
                 aa_.push_back(*ij);
                 elemCount++ ;
              }
              ja_[i] = ja_[i-1] + elemCount;          
          }
      }    
      printMCSR();
}
if you know C++ you got the way the matrix works .. if this question is not well explained please let me know !
 
Last edited:

Answers and Replies

  • #4
haruspex
Science Advisor
Homework Helper
Insights Author
Gold Member
2022 Award
39,540
8,806
This being a homework forum, you need to post an attempt, or at the least, some thoughts on approaches.
 

Suggested for: Algorithm to matrix product MSR format

  • Last Post
Replies
11
Views
347
Replies
22
Views
373
Replies
5
Views
333
Replies
17
Views
297
Replies
8
Views
596
  • Last Post
Replies
12
Views
682
Replies
2
Views
303
Replies
20
Views
804
  • Last Post
Replies
34
Views
703
  • Last Post
Replies
8
Views
527
Top