Search code examples
data-structuresfortransparse-matrixmatrix-multiplication

Details of the "New Yale" sparse matrix format?


There's some Netlib code written in Fortran which performs transposes and multiplication on sparse matrices. The library works with Bank-Smith (sort of), "old Yale", and "new Yale" formats.

Unfortunately, I haven't been able to find much detail on "new Yale." I implemented what I think matches the description given in the paper, and I can get and set entries appropriately.

But the results are not correct, leading me to wonder if I've implemented something which matches the description in the paper but is not what the Fortran code expects.

So a couple of questions:

Should row lengths include diagonal entries? e.g., if you have M=[1,1;0,1], it seems that it should look like this:

IJA = [3,4,4,1]
A   = [1,1,X,1] // where X=NULL

It seems that if diagonal entries are included in row lengths, you'd get something like this:

IJA = [3,5,6,1]
A   = [1,1,X,1]

That doesn't make much sense because IJA[2]=6 should be the size of the IJA/A arrays, but it is what the paper seems to say.

Should the matrices use 1-based indexing?

It is Fortran code after all. Perhaps instead my IJA and A should look like this:

IJA = [4,5,5,2]
A   = [1,1,X,1] // still X=NULL

Is there anything else I'm missing?

Yes, that's vague, but I throw that out there in case someone who has messed with this code before would like to volunteer any additional information. Anyone else can feel free to ignore this last question.

I know these questions may seem rather trivial, but I thought perhaps some Fortran folks could provide me with some insight. I'm not used to thinking in a one-based system, and though I've converted the code to C using f2c, it's still written like Fortran.


Solution

  • So, first of all, the reference given in the SMMP paper is possibly not the correct one. I checked it out (the ref) from the library last night. It appears to give the "old Yale" format. It does mention, on pp. 49-50, that the diagonal can be separated out from the rest of the matrix -- but doesn't so much as mention an IJA vector.

    I was able to find the format described in the 1992 edition of Numerical Recipes in C on pp. 78-79.

    Of course, there is no guarantee that this is the format accepted by the SMMP library from Netlib.

    NR seems to have IA giving positions relative to IJA, not relative to JA. The last position in the IA portion gives not the size of the IJA and A vectors, but size-1, because the vectors are indexed starting at 1 (per Fortran standard).

    Row lengths do not include non-zero diagonal entries.