Fix inv for triangular and diagonal matrices

Ensure that the methods return `SingularException` when the input matrices are singular