That is a massive bug in the initialization of a sparse matrix with a row index not starting at 0 ! This bug was able to bypass a very long list of stress tests on the matrix package in test/stressLinear.cxx

Thank you for pointing that out and debugging the problem.

Here a small reproducer code:

void testSparse(Int_t msize=5)
{
TMatrixDSparse m1(1,4,0,msize-1);
{
Int_t nr = 4*msize;
Int_t *irow = new Int_t[nr];
Int_t *icol = new Int_t[nr];
Double_t *val = new Double_t[nr];
Int_t n = 0;
for (UInt_t i = m1.GetRowLwb(); i <= m1.GetRowUpb(); i++) {
for (UInt_t j = m1.GetColLwb(); j <= m1.GetColUpb(); j++) {
irow[n] = i;
icol[n] = j;
val[n] = TMath::Pi()*i+TMath::E()*j;
n++;
}
}
m1.SetMatrixArray(nr,irow,icol,val);
delete [] irow;
delete [] icol;
delete [] val;
}
m1.Print();
TMatrixD m2(1,4,0,msize-1);
for (UInt_t i = m2.GetRowLwb(); i <= m2.GetRowUpb(); i++)
for (UInt_t j = m2.GetColLwb(); j <= m2.GetColUpb(); j++)
m2(i,j) = TMath::Pi()*i+TMath::E()*j;
m2.Print();
std::cout << "matrices identical " << ((m1 == m2) ? "OK" : "FAILED") << std::endl;
}