In the bug report
https://savannah.gnu.org/bugs/?53198
is an analysis of nnz for diagonal matrices, with greatly improved speed when taking into consideration how sparse the diagonal matrix is.
A similar thing can be said for sort() applied to diagonal matrices. E.g.,
It should be possible to speed up this operation by noting that we can:
1) Construct an allzeros matrix of the same size.
2) Take the diagonal vector and distribute it either to the starting or ending position of the colum (or row) of the zeros matrix. E.g.,
and the issorted() routine boils down to a series of logical statements:
1) If the matrix size is 2 or less along the direction of sort, use the full matrix sort. Not much penalty is incurred by that.
2) If the diagonal vector is all zeros, the matrix is sorted.
3) Otherwise, the matrix is not sorted.
