1 | initial version |
I think the relevant code is here: https://github.com/sagemath/sage/blob/6187d261eca3c980e575b53d1a31f580ba8cfdfd/src/sage/matrix/matrix_rational_sparse.pyx#L161
The algorithm does take into account the sparse nature, but it does have a triple-nested for-loop, enumerating all the indices. It may be that for moderate sparsity this is faster than just enumerating the non-zero entries, but especially for your example it's pretty clear a much more efficient implementation is possible.