ginkgo-project / ginkgo

Numerical linear algebra software package
https://ginkgo-project.github.io/
BSD 3-Clause "New" or "Revised" License
384 stars 86 forks source link

MM-Format IO Checking #1627

Open MarcelKoch opened 1 week ago

MarcelKoch commented 1 week ago

Reading an MM-file doesn't check the file itself for consistency. For example, if the MM file defines a 6x4 matrix, but less then 24 lines after the size definition contain values, not all values of the created matrix/vector will be filled. IMO there should be a simple test that after a definition of a MxN dense matrix, exactly M * N lines should contain a value. This checking would not apply to the coordinate format, as missing values will be assumed to be zero anyway.

MarcelKoch commented 1 week ago

Actually, this is already checked. But the issue remains if the MM-file contains multiple values per line. Then each value in a row seems to be interpreted as being on a row by itself. Thus the value is not interpreted as the next column value, but instead as a value for the next row.

Consider this file:

%%MatrixMarket matrix array real general
4 2
1 1
2 2
3 3
4 4

Then reading and writing it again one would expect (without deeper knowledge of the MM standard) the matrix entries in a single list using column major format:

%%MatrixMarket matrix array real general
4 2
1
2
3
4
1
2
3
4

But instead one gets

%%MatrixMarket matrix array real general
4 2
1
1
2
2
3
3
4
4