uestla / Sparse-Matrix

C++ implementation of sparse matrix using CRS (Compressed Row Storage) format

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

start index from 0 instead of 1

BinWang0213 opened this issue · comments

Is there any possible to add a "button" to switch the index from 0 instead of 1?
Or Can you provide a version of it? The natural selection of C/C++ index is from 0, this will be very convenient to use it directly.

Now I had to use it like MatA.get(i+1,j+1) etc

The implementation follows the CRS format described at http://netlib.org/linalg/html_templates/node91.html where the indexing starts from 1.

But I have to say I also struggled a bit with this since in programming base 0 is much more common.

The struggle will be even more real after the operator[][] is added.

I guess this decision has been made according to the mathematical notation where a_11 means element on 1st row in 1st column.


Some documents however define CRS with base 0. I think it would be much more intuitive and easier to use and would simplify internal algorithms as well (since now I have to subtract 1 when accessing elements and it's a bit confusing).

I'll think about this and probably would change the base in the future (although it'll be a big BC break).

I'll try to create separate branch base0 later today.

Thanks very much for your consideration and time. I'm really looking forward to see this branch.

I've just added branch base0. All tests seem to be passing.

Could you please test it that it works for you, @BinWang0213 ?

Thx for your help. It works so good!