Note that there are some explanatory texts on larger screens.

plurals
  1. POSparse matrix storage in C
    primarykey
    data
    text
    <p>I have a sparse matrix that is not symmetric I.E. the sparsity is somewhat random, and I can't count on all the values being a set distance away from the diagonal.</p> <p>However, it is still sparse, and I want to reduce the storage requirement on the matrix. Therefore, I am trying to figure out how to store each row starting at the first non-zero, in order, until I get to the last non-zero. </p> <p>That is, if the first non-zero of row m occurs at column 2, and the last non-zero is at column 89, I want to store in A[m] rows 2-> 89.</p> <p>Since each row does not have the same number of non-zeros, I will make all the rows of A have the same number of elements, and pad zeros to the end of the row for rows that have a smaller number of non-zero elements.</p> <p>How do I do this translation in C? I do not actually have an original, full matrix to just copy the values from (the original matrix is coming to me in CSR form). If I was doing this in fortran, I could just define my array to be two dimensional and just have each row be variable length by tracking the start/stop values of non-zero columns and store it like that. </p> <p>I will try to demonstrate below:</p> <p>This is a matrix representation of the values I know - and for each value, I know the row and column location</p> <pre><code> [1 2 3 4 ] [ 5 6 7 8 ] [ 10 11 12 13 ] m[ 14 15 16 17 18 ] [ 19 20 21 22 ] </code></pre> <p>Now for this one row <code>m</code> has the largest "span" between the first non-zero and last non-zero so my new matrix is going to be <code>5x[span of row m]</code></p> <pre><code> [1 2 3 4 ] [5 6 7 8 ] [10 11 12 13 ] m[14 15 16 17 18] [19 20 21 22 ] </code></pre> <p>As you can see, row <code>m</code> needs no zero padding since it was the longest "span" anyway</p> <p>The other rows now all have row zero as the first non-zero, and maintain the spacing of zeros columns between each non-zero.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload