From b5faae0637da8cffb9b0835e8daab0747ee789b6 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 11 Jul 2019 21:04:06 +0200 Subject: [PATCH] Fix IsUpperTriangularMat for non-square matrices; add tests --- lib/matrix.gi | 4 ++-- tst/testinstall/matrix.tst | 47 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 tst/testinstall/matrix.tst diff --git a/lib/matrix.gi b/lib/matrix.gi index 5223cc1889..00534f0a42 100644 --- a/lib/matrix.gi +++ b/lib/matrix.gi @@ -189,8 +189,8 @@ InstallMethod( IsUpperTriangularMat, function( mat ) local i, j, z; z:=ZeroOfBaseDomain(mat); - for i in [ 1 .. NrRows( mat ) ] do - for j in [ 1 .. i-1] do + for j in [ 1 .. NrCols( mat ) ] do + for i in [ j+1 .. NrRows( mat ) ] do if mat[i,j] <> z then return false; fi; diff --git a/tst/testinstall/matrix.tst b/tst/testinstall/matrix.tst new file mode 100644 index 0000000000..195bcb49f8 --- /dev/null +++ b/tst/testinstall/matrix.tst @@ -0,0 +1,47 @@ +# +gap> IsDiagonalMat(NullMat(3, 3)); +true +gap> IsDiagonalMat(NullMat(1, 3)); +true +gap> IsDiagonalMat(NullMat(3, 1)); +true +gap> IsDiagonalMat(IdentityMat(3)); +true +gap> IsDiagonalMat([[1,1],[1,1]]); +false +gap> IsDiagonalMat([[1,0],[1,1]]); +false +gap> IsDiagonalMat([[1,1],[0,1]]); +false + +# +gap> IsUpperTriangularMat(NullMat(3, 3)); +true +gap> IsUpperTriangularMat(NullMat(1, 3)); +true +gap> IsUpperTriangularMat(NullMat(3, 1)); +true +gap> IsUpperTriangularMat(IdentityMat(3)); +true +gap> IsUpperTriangularMat([[1,1],[1,1]]); +false +gap> IsUpperTriangularMat([[1,0],[1,1]]); +false +gap> IsUpperTriangularMat([[1,1],[0,1]]); +true + +# +gap> IsLowerTriangularMat(NullMat(3, 3)); +true +gap> IsLowerTriangularMat(NullMat(1, 3)); +true +gap> IsLowerTriangularMat(NullMat(3, 1)); +true +gap> IsLowerTriangularMat(IdentityMat(3)); +true +gap> IsLowerTriangularMat([[1,1],[1,1]]); +false +gap> IsLowerTriangularMat([[1,0],[1,1]]); +true +gap> IsLowerTriangularMat([[1,1],[0,1]]); +false