mathnet / mathnet-numerics

Math.NET Numerics
http://numerics.mathdotnet.com
MIT License
3.5k stars 896 forks source link

1-based and 0-based array indexing in SparseCompressedRowMatrixStorage #217

Open shabadan opened 10 years ago

shabadan commented 10 years ago

Some algorithms for sparse matrix in MKL need a 1-base indexing (e.g. PARDISO). It could be convenient and very easy add a bool flag to the constructor static functions, e.g. SparseCompressedRowMatrixStorage OfIndexedEnumerable(int rows, int columns, IEnumerable<Tuple<int, int, T>> data) can be modified as SparseCompressedRowMatrixStorage OfIndexedEnumerable(int rows, int columns, IEnumerable<Tuple<int, int, T>> data, bool indexing) if indexing == false then 0-based else 1-based if 1-based, the rowPointers and columnIndices arrays need to start from 1, the values array is left untouched. A clever approach would check if the input IEnumerable is 0/1-based.

Question: Does the SparseCompressedRowMatrixStorage skip 0 values even if they are on the diagonal of the sparse matrix?

MattHeffron commented 9 years ago

I am working on a full one-based indexing set of LinearAlgebra functionality. It includes one-based indexing storage implementations. (I have it under namespace MathNet.Numerics.LinearAlgebra.OneBased. ...) So far I have the code changes and I'm about to start with modifying the 0-based unit tests for 1-based. My motivation was porting from Matlab. Having done this in the past, converting to the RogueWave C++ library, was very error prone, because of the 0/1- based indexing difference.