Fix linear indexing for triangular matrices