Fix inv for triangular and diagonal matrices