Skip to content

Commit

Permalink
support consistency checks for Vector, Matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBreuer committed Oct 20, 2022
1 parent 7a41d74 commit a194209
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
14 changes: 14 additions & 0 deletions lib/matobj.gi
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ end);

# methods to create vector objects

#############################################################################
##
#O Vector( <filt>, <R>, <list> )
#O Vector( <filt>, <R>, <vec> )
#O Vector( <R>, <list> )
#O Vector( <R>, <vec> )
#O Vector( <list>, <vec> )
#O Vector( <vec1>, <vec2> )
##
## Compute the missing arguments for 'NewVector' and then call it.
##
InstallMethod( Vector,
[ IsOperation, IsSemiring, IsList ],
NewVector );
Expand Down Expand Up @@ -277,6 +288,8 @@ InstallMethod( ZeroVector,
#M Matrix( <list>, <ncols> )
#M Matrix( <list> )
##
## Compute the missing arguments for 'NewMatrix' and then call it.
##
InstallMethod( Matrix,
[ IsOperation, IsSemiring, IsList, IsInt ],
{ filt, R, list, nrCols } -> NewMatrix( filt, R, nrCols, list ) );
Expand Down Expand Up @@ -384,6 +397,7 @@ InstallMethod( Matrix,
return NewMatrix( ConstructingFilter(example), BaseDomain(example), NrCols(mat), Unpack(mat) );
end );


#
#
#
Expand Down
12 changes: 12 additions & 0 deletions lib/matobj2.gd
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ DeclareOperation( "ZeroVector", [ IsInt, IsVecOrMatObj ] );
## this list.
## <P/>
## It is <E>not</E> guaranteed that the given list of entries is copied.
## <P/>
## If the global option <C>Check</C> is set to <K>false</K> then
## <Ref Oper="Vector"/> need not perform consistency checks.
## </Description>
## </ManSection>
## <#/GAPDoc>
Expand Down Expand Up @@ -680,6 +683,9 @@ DeclareOperation( "Vector", [ IsList ] );
## and the entries in <A>list</A>.
## The list <A>list</A> is guaranteed not to be changed by this operation.
## <P/>
## If the global option <C>Check</C> is set to <K>false</K> then
## <Ref Oper="NewVector"/> need not perform consistency checks.
## <P/>
## Similarly, <Ref Constr="NewZeroVector"/> returns a mutable vector object
## of length <A>n</A> which has <A>filt</A> and <A>R</A> as
## <Ref Attr="ConstructingFilter" Label="for a vector object"/> and
Expand Down Expand Up @@ -726,6 +732,9 @@ DeclareConstructor( "NewZeroVector", [ IsVectorObj, IsSemiring, IsInt ] );
## The corresponding entries must be in or compatible with <A>R</A>.
## If <A>list</A> already contains vector objects, they are copied.
## <P/>
## If the global option <C>Check</C> is set to <K>false</K> then
## <Ref Oper="NewMatrix"/> need not perform consistency checks.
## <P/>
## Similarly, <Ref Constr="NewZeroMatrix"/> returns a mutable zero matrix
## object with <A>m</A> rows and <A>n</A> columns
## which has <A>filt</A> and <A>R</A> as
Expand Down Expand Up @@ -1222,6 +1231,9 @@ DeclareOperation( "CompanionMatrix",
## of <Ref Oper="ShallowCopy"/>.
## If <A>list</A> is a nested list then it is <E>not</E> guaranteed
## that also the entries of <A>list</A> are copied.
## <P/>
## If the global option <C>Check</C> is set to <K>false</K> then
## <Ref Oper="Matrix"/> need not perform consistency checks.
## </Description>
## </ManSection>
## <#/GAPDoc>
Expand Down
3 changes: 3 additions & 0 deletions lib/matobjnz.gi
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ InstallMethod( NewVector, "for IsZmodnZVectorRep, a ring, and a list",
l:=List(l,Int);
else
l:=ShallowCopy(l);
if ValueOption( "Check" ) <> false and not ForAll( l, IsInt ) then
Error( "<l> must be a list of integers or of elements in <basedomain>" );
fi;
fi;
v := [basedomain,l];
Objectify(typ,v);
Expand Down
3 changes: 3 additions & 0 deletions lib/matobjplist.gi
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ InstallMethod( NewVector, "for IsPlistVectorRep, a ring, and a list",
[ IsPlistVectorRep, IsRing, IsList ],
function( filter, basedomain, l )
local typ, v;
if ValueOption( "Check" ) <> false and not IsSubset( basedomain, l ) then
Error( "the elements in <l> must lie in <basedomain>" );
fi;
typ := MakePlistVectorType(basedomain,IsPlistVectorRep);
v := [basedomain,ShallowCopy(l)];
Objectify(typ,v);
Expand Down
4 changes: 2 additions & 2 deletions lib/vec8bit.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ InstallMethod( BaseField, "for a compressed 8bit vector",
InstallMethod( NewVector, "for Is8BitVectorRep, GF(q), and a list",
[ Is8BitVectorRep, IsField and IsFinite, IsList ],
function( filter, f, l )
if not Size(f) in [3..256] then
if ValueOption( "Check" ) <> false and not Size(f) in [3..256] then
Error("Is8BitVectorRep only supports base fields with 3 to 256 elements");
fi;
return CopyToVectorRep(l,Size(f));
Expand All @@ -1116,7 +1116,7 @@ InstallMethod( NewMatrix, "for Is8BitMatrixRep, GF(q), an int, and a list",
[ Is8BitMatrixRep, IsField and IsFinite, IsInt, IsList ],
function( filter, f, rl, l )
local m;
if not Size(f) in [3..256] then
if ValueOption( "Check" ) <> false and not Size(f) in [3..256] then
Error("Is8BitMatrixRep only supports base fields with 3 to 256 elements");
fi;
m := List(l,ShallowCopy);
Expand Down

0 comments on commit a194209

Please sign in to comment.