Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better input validation for GModuleByMats #5813

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/meataxe.gi
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,29 @@

InstallGlobalFunction(GModuleByMats,function(arg)
local l,f,dim,m;
l:=arg[1];
if Length(arg)=1 then
if Length(arg)<>2 and Length(arg)<>3 then
Error("Usage: GModuleByMats(<mats>,[<dim>,]<field>)");
fi;
l:=arg[1];
f:=arg[Length(arg)];
if Length(l)>0 and Characteristic(l[1])<>Characteristic(f) then
Error("matrices and field do not fit together");
fi;
l:=List(l,i->ImmutableMatrix(f,i));

if ForAny(l,i->Length(i)<>Length(i[1])) or
Length(Set(l,Length))>1 then
if ForAny(l,i->NrRows(i)<>NrCols(i)) or
Length(Set(l,NrRows))>1 then
Error("<l> must be a list of square matrices of the same dimension");
fi;
m:=rec(field:=f,
isMTXModule:=true);
if Length(l)>0 then
dim:=Length(l[1][1]);
dim:=NrRows(l[1]);
if Length(arg) = 3 then
if dim <> arg[2] then
Error("matrices and dim do not fit together");
fi;
fi;
elif Length(arg)=2 then
Error("if no generators are given the dimension must be given explicitly");
else
Expand Down
20 changes: 20 additions & 0 deletions tst/testinstall/meataxe.tst
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
#@local G,M,M2,M3,M4,M5,V,bf,bo,cf,homs,m,mat,qf,randM,res,sf,subs,mats,Q,orig,S
gap> START_TEST("meataxe.tst");

#
# GModuleByMats input validation
#
gap> GModuleByMats();
Error, Usage: GModuleByMats(<mats>,[<dim>,]<field>)
gap> GModuleByMats([], 2, GF(2), "extra");
Error, Usage: GModuleByMats(<mats>,[<dim>,]<field>)
gap> GModuleByMats([[[Z(2)]]], 2, GF(2));
Error, matrices and dim do not fit together
gap> GModuleByMats([[[Z(2),Z(2)]]], GF(2));
Error, <l> must be a list of square matrices of the same dimension
gap> GModuleByMats([[[Z(2)]], [[Z(2),Z(2)],[Z(2),0*Z(2)]]], GF(2));
Error, <l> must be a list of square matrices of the same dimension

# module with no generators
gap> GModuleByMats([], 2, GF(2));
rec( IsOverFiniteField := true, dimension := 2, field := GF(2),
generators := [ <an immutable 2x2 matrix over GF2> ], isMTXModule := true,
smashMeataxe := rec( isZeroGens := true ) )

#
#
#
Expand Down
Loading