Matrix multiplication using pairs

Posted by sc_ray on Stack Overflow See other posts from Stack Overflow or by sc_ray
Published on 2010-04-06T04:26:39Z Indexed on 2010/04/06 4:33 UTC
Read the original article Hit count: 208

Hi,

I am looking into alternate ways to do a Matrix Multiplication. Instead of storing my matrix as a two-dimensional array, I am using a vector such as

vector<pair<pair<int,int >,int > > 

to store my matrix. The pair within my pair (pair) stores my indices (i,j) and the other int stores the value for the given (i,j) pair. I thought I might have some luck implementing my sparse array this way.

The problem is when I try to multiply this matrix with itself.

If this was a 2-d array implementation, I would have multiplied the matrix as follows:

   for(i=0; i<row1; i++)
    {
        for(j=0; j<col1; j++)
        {
          C[i][j] = 0;
         for(k=0; k<col2; k++) 
           C[i][j] += A[i][j] * A[j][k];
      }
    }

Can somebody point out a way to achieve the same result using my vector of 'pair of pairs'?

Thanks

© Stack Overflow or respective owner

Related posts about c++

Related posts about data-structures