mathnet / mathnet-numerics

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

Sparse MapIndexedInplace starts with incorrect indices #1045

Open jellezult opened 8 months ago

jellezult commented 8 months ago

The following test fails when using MapIndexedInplace on a sparse matrix with the Zeros.AllowSkip option. Somehow the iteration starts of with i=0, j=1 as indices.

[Test]
public void Sparse_MapIndexedInplace_AllowSkipZeros_Bug()
{

    int nRows = 3;
    int nCols = 1;
    Matrix<float> data = Matrix<float>.Build.Sparse(nRows, nCols, 42);

    data.MapIndexedInplace((i, j, v) =>
    {
        j.Should().Be(0);
        return Math.Abs(v);
    }, Zeros.AllowSkip);
}