Skip to content

Commit 24f7f5f

Browse files
authored
[Math] Improve sparse matrix loop example
The current example only works inside the class, not for user code.
1 parent e64dcc1 commit 24f7f5f

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

math/matrix/src/TMatrixTSparse.cxx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,17 @@
3131
As an example how to access all sparse data elements:
3232
3333
~~~
34-
for (Int_t irow = 0; irow < this->fNrows; irow++) {
35-
const Int_t sIndex = fRowIndex[irow];
36-
const Int_t eIndex = fRowIndex[irow+1];
34+
TMatrixTSparse<double> M;
35+
auto rowIndex = M.GetRowIndexArray();
36+
auto colIndex = M.GetColIndexArray();
37+
auto matrix = M.GetMatrixArray();
38+
for (Int_t irow = 0; irow < M.GetNrows(); irow++) {
39+
const Int_t sIndex = rowIndex[irow];
40+
const Int_t eIndex = rowIndex[irow+1];
3741
for (Int_t index = sIndex; index < eIndex; index++) {
38-
const Int_t icol = fColIndex[index];
39-
const Element data = fElements[index];
40-
printf("data(%d,%d) = %.4e\n",irow+this->fRowLwb,icol+
41-
this->fColLwb,data);
42+
const Int_t icol = colIndex[index];
43+
const double data = matrix[index];
44+
printf("data(%d,%d) = %.4e\n", irow + M.GetRowLwb(), icol + M.GetColLwb(), data);
4245
}
4346
}
4447
~~~

0 commit comments

Comments
 (0)