Skip to content

Commit

Permalink
Improve compatibility with GAP's MatrixObj project
Browse files Browse the repository at this point in the history
... by using TryNextMethod in Matrix() methods instead of raising an error
  • Loading branch information
fingolfin committed Mar 25, 2022
1 parent 37d2959 commit 7726312
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
10 changes: 5 additions & 5 deletions gap/elements/semiringmat.gi
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ function(filter, mat, threshold, period)
local checker, row;

if not IsRectangularTable(mat) or Length(mat) <> Length(mat[1]) then
ErrorNoReturn("the 2nd argument must define a square matrix");
TryNextMethod();
elif filter <> IsNTPMatrix then
ErrorNoReturn("cannot create a matrix from the given arguments");
TryNextMethod();
fi;

checker := SEMIGROUPS_MatrixOverSemiringEntryCheckerCons(filter,
Expand Down Expand Up @@ -242,13 +242,13 @@ function(filter, mat)
local row;

if not IsRectangularTable(mat) or Length(mat) <> Length(mat[1]) then
ErrorNoReturn("the 2nd argument must define a square matrix");
TryNextMethod();
elif not filter in [IsBooleanMat,
IsMaxPlusMatrix,
IsMinPlusMatrix,
IsProjectiveMaxPlusMatrix,
IsIntegerMatrix] then
ErrorNoReturn("cannot create a matrix from the given arguments");
TryNextMethod();
elif filter = IsBooleanMat then
return BooleanMat(mat);
fi;
Expand All @@ -269,7 +269,7 @@ SEMIGROUPS_MatrixForIsSemiringIsHomogenousListFunc := function(semiring, mat)

if not IsEmpty(mat)
and not ForAll(mat, x -> IsList(x) and Length(x) = Length(mat[1])) then
ErrorNoReturn("the 2nd argument <mat> does not give a rectangular table");
TryNextMethod();
elif not IsEmpty(mat) and Length(mat) <> Length(mat[1]) then
TryNextMethod();
elif IsField(semiring) and IsFinite(semiring) then
Expand Down
18 changes: 12 additions & 6 deletions tst/standard/elements/semiringmat.tst
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,17 @@ Matrix(IsTropicalMaxPlusMatrix, [[0, -infinity], [-infinity, 0]], 5)
# semiringmat: Matrix, for a filter, homogeneous list, pos int, and pos int,
# 1/3
gap> Matrix(IsNTPMatrix, [[1, 1], [2]], 3, 3);
Error, the 2nd argument must define a square matrix
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
Error, no 2nd choice method found for `Matrix' on 4 arguments
gap> Matrix(IsNTPMatrix, [[1, 1, 3], [1, 2, 3]], 3, 3);
Error, the 2nd argument must define a square matrix
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
Error, no 2nd choice method found for `Matrix' on 4 arguments

# semiringmat: Matrix, for a filter, homogeneous list, pos int, and pos int,
# 2/3
gap> Matrix(IsIntegerMatrix, [[1, 1], [2, 2]], 3, 3);
Error, cannot create a matrix from the given arguments
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
Error, no 2nd choice method found for `Matrix' on 4 arguments
# semiringmat: Matrix, for a filter, homogeneous list, pos int, and pos int,
# 3/3
Expand All @@ -123,13 +126,16 @@ alMinPlusMatrix
# semiringmat: Matrix, for a filter and homogeneous list, 1/3
gap> Matrix(IsIntegerMatrix, [[1, 1], [2]]);
Error, the 2nd argument must define a square matrix
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
Error, no 2nd choice method found for `Matrix' on 2 arguments
gap> Matrix(IsIntegerMatrix, [[1, 1, 3], [1, 2, 3]]);
Error, the 2nd argument must define a square matrix
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
Error, no 2nd choice method found for `Matrix' on 2 arguments
# semiringmat: Matrix, for a filter and homogeneous list, 2/3
gap> Matrix(IsNTPMatrix, [[1, 1], [1, 2]]);
Error, cannot create a matrix from the given arguments
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
Error, no 2nd choice method found for `Matrix' on 2 arguments

# semiringmat: Matrix, for a filter and homogeneous list, 3/3
gap> Matrix(IsIntegerMatrix, [[1, 1], [2, E(8)]]);
Expand Down

0 comments on commit 7726312

Please sign in to comment.