Skip to content

Commit a68f125

Browse files
authored
Miscellaneous fixes concerning vector and matrix objects (#6369)
* add checks to `NewVector`, `NewMatrix` for the GF(2) and 8 bit repres. in order to catch `fail` results * add a `String` method for rings `Integers mod n` * fix the default `OneMutable` method for `IsMatrixObj` Test that the input is square, as for list-of-lists matrices. * minor fixes for `IsPlistVectorRep` - check the input list for `IsPlistRep` in `MakeIsPlistVectorRep`, let `NewVector` turn the input to `IsPlistRep` if necessary - forbid assignments into a `IsPlistVectorRep` vector beyond its length * fix `SolutionMatDestructive` Conceptually, the solution must be in the same representation as the given vector. (Let us see which other bugs will come to the surface now.) * fix `TestPositionNonZeroInRow`
1 parent f9d2d84 commit a68f125

11 files changed

Lines changed: 70 additions & 17 deletions

File tree

hpcgap/lib/vec8bit.gi

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,10 +1133,16 @@ InstallMethod( BaseField, "for a compressed 8bit vector",
11331133
InstallTagBasedMethod( NewVector,
11341134
Is8BitVectorRep,
11351135
function( filter, f, l )
1136-
if ValueOption( "check" ) <> false and not Size(f) in [3..256] then
1136+
local check, res;
1137+
check:= ValueOption( "check" ) <> false;
1138+
if check and not Size(f) in [3..256] then
11371139
Error("Is8BitVectorRep only supports base fields with 3 to 256 elements");
11381140
fi;
1139-
return CopyToVectorRep(l,Size(f));
1141+
res:= CopyToVectorRep( l, Size( f ) );
1142+
if check and res = fail then
1143+
Error( "cannot copy <l> to 'Is8BitVectorRep'" );
1144+
fi;
1145+
return res;
11401146
end );
11411147

11421148
# This is faster than the default method.
@@ -1170,7 +1176,9 @@ InstallTagBasedMethod( NewMatrix,
11701176
else
11711177
m := List(l,ShallowCopy);
11721178
fi;
1173-
ConvertToMatrixRep(m,Size(f));
1179+
if ConvertToMatrixRep( m, Size( f ) ) = fail then
1180+
Error( "cannot convert <m> to 'Is8BitMatrixRep'" );
1181+
fi;
11741182
return m;
11751183
end );
11761184

hpcgap/lib/vecmat.gi

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,8 +2555,13 @@ InstallMethod( BaseField, "for a compressed gf2 vector",
25552555
InstallTagBasedMethod( NewVector,
25562556
IsGF2VectorRep,
25572557
function( filter, f, l )
2558+
local res;
25582559
if Size(f) <> 2 then Error("IsGF2VectorRep only supported over GF(2)"); fi;
2559-
return CopyToVectorRep(l,2);
2560+
res:= CopyToVectorRep( l, 2 );
2561+
if res = fail then
2562+
Error( "cannot copy <l> to 'IsGF2VectorRep'" );
2563+
fi;
2564+
return res;
25602565
end );
25612566

25622567
InstallTagBasedMethod( NewZeroVector,
@@ -2583,7 +2588,9 @@ InstallTagBasedMethod( NewMatrix,
25832588
else
25842589
m := List(l,ShallowCopy);
25852590
fi;
2586-
ConvertToMatrixRep(m,2);
2591+
if ConvertToMatrixRep( m, 2 ) = fail then
2592+
Error( "cannot convert <m> to 'IsGF2MatrixRep'" );
2593+
fi;
25872594
return m;
25882595
end );
25892596

lib/matobj.gi

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,14 @@ InstallMethod( ZeroSameMutability,
14761476

14771477
InstallMethod( OneMutable,
14781478
[ IsMatrixObj ],
1479-
M -> IdentityMatrix( NumberRows( M ), M ) );
1479+
function( M )
1480+
local nrows;
1481+
nrows:= NrRows( M );
1482+
if nrows <> NrCols( M ) then
1483+
Error( "<M> must be square (not ", nrows, " by ", NrCols( M ), ")" );
1484+
fi;
1485+
return IdentityMatrix( nrows, M );
1486+
end );
14801487

14811488
InstallMethod( OneSameMutability,
14821489
[ IsMatrixOrMatrixObj ],

lib/matobjplist.gi

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ BindGlobal( "MakeIsPlistVectorRep",
8888
if check and ValueOption( "check" ) <> false then
8989
if not IsSubset( basedomain, list ) then
9090
Error( "the elements in <list> must lie in <basedomain>" );
91+
elif not IsPlistRep( list ) then
92+
Error( "<list> must be in 'IsPlistRep'" );
9193
fi;
9294
fi;
9395

@@ -177,7 +179,7 @@ BindGlobal( "MakeIsPlistMatrixRep",
177179
InstallTagBasedMethod( NewVector,
178180
IsPlistVectorRep,
179181
function( filter, basedomain, list )
180-
return MakeIsPlistVectorRep(basedomain, ShallowCopy(list), true);
182+
return MakeIsPlistVectorRep(basedomain, PlainListCopy( list ), true);
181183
end );
182184

183185
InstallTagBasedMethod( NewZeroVector,
@@ -343,6 +345,9 @@ InstallMethod( \[\],
343345
InstallMethod( \[\]\:\=,
344346
[ "IsPlistVectorRep", "IsPosInt", "IsObject" ],
345347
function( v, p, ob )
348+
if ValueOption( "check" ) <> false and Length( v![ELSPOS] ) < p then
349+
Error( "<p> is out of bounds" );
350+
fi;
346351
v![ELSPOS][p] := ob;
347352
end );
348353

@@ -699,7 +704,7 @@ InstallMethod( Matrix,
699704
else
700705
l := [];
701706
fi;
702-
# The result shall be mutable iff 'rows' is mutable.
707+
# The result shall be mutable iff 'list' is mutable.
703708
if not IsMutable( list ) then
704709
MakeImmutable( l );
705710
fi;

lib/matrix.gi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3040,8 +3040,7 @@ InstallOtherMethod( SolutionMatDestructive,
30403040
local i,ncols,sem, vno, z,x, sol;
30413041
ncols := Length(vec);
30423042
z := ZeroOfBaseDomain(mat);
3043-
sol := ListWithIdenticalEntries(NrRows(mat),z);
3044-
ConvertToVectorRepNC(sol);
3043+
sol:= ZeroVector( NrRows( mat ), vec );
30453044
if ncols <> NrCols(mat) then
30463045
Error("SolutionMat: matrix and vector incompatible");
30473046
fi;

lib/vec8bit.gi

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,10 +1088,16 @@ InstallMethod( BaseField, "for a compressed 8bit vector",
10881088
InstallTagBasedMethod( NewVector,
10891089
Is8BitVectorRep,
10901090
function( filter, f, l )
1091-
if ValueOption( "check" ) <> false and not Size(f) in [3..256] then
1091+
local check, res;
1092+
check:= ValueOption( "check" ) <> false;
1093+
if check and not Size(f) in [3..256] then
10921094
Error("Is8BitVectorRep only supports base fields with 3 to 256 elements");
10931095
fi;
1094-
return CopyToVectorRep(l,Size(f));
1096+
res:= CopyToVectorRep( l, Size( f ) );
1097+
if check and res = fail then
1098+
Error( "cannot copy <l> to 'Is8BitVectorRep'" );
1099+
fi;
1100+
return res;
10951101
end );
10961102

10971103
# This is faster than the default method.
@@ -1125,7 +1131,9 @@ InstallTagBasedMethod( NewMatrix,
11251131
else
11261132
m := List(l,ShallowCopy);
11271133
fi;
1128-
ConvertToMatrixRep(m,Size(f));
1134+
if ConvertToMatrixRep( m, Size( f ) ) = fail then
1135+
Error( "cannot convert <m> to 'Is8BitMatrixRep'" );
1136+
fi;
11291137
return m;
11301138
end );
11311139

lib/vecmat.gi

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,8 +2553,13 @@ InstallMethod( BaseField, "for a compressed gf2 vector",
25532553
InstallTagBasedMethod( NewVector,
25542554
IsGF2VectorRep,
25552555
function( filter, f, l )
2556+
local res;
25562557
if Size(f) <> 2 then Error("IsGF2VectorRep only supported over GF(2)"); fi;
2557-
return CopyToVectorRep(l,2);
2558+
res:= CopyToVectorRep( l, 2 );
2559+
if res = fail then
2560+
Error( "cannot copy <l> to 'IsGF2VectorRep'" );
2561+
fi;
2562+
return res;
25582563
end );
25592564

25602565
InstallTagBasedMethod( NewZeroVector,
@@ -2581,7 +2586,9 @@ InstallTagBasedMethod( NewMatrix,
25812586
else
25822587
m := List(l,ShallowCopy);
25832588
fi;
2584-
ConvertToMatrixRep(m,2);
2589+
if ConvertToMatrixRep( m, 2 ) = fail then
2590+
Error( "cannot convert <m> to 'IsGF2MatrixRep'" );
2591+
fi;
25852592
return m;
25862593
end );
25872594

lib/zmodnz.gi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@ InstallMethod( TriangulizeMat,
869869
##
870870
#M ViewObj( <R> ) . . . . . . . . . . . . . . . . method for full ring Z/nZ
871871
#M PrintObj( <R> ) . . . . . . . . . . . . . . . . method for full ring Z/nZ
872+
#M String( <R> ) . . . . . . . . . . . . . . . . . method for full ring Z/nZ
872873
##
873874
InstallMethod( ViewObj,
874875
"for full ring Z/nZ",
@@ -884,6 +885,11 @@ InstallMethod( PrintObj,
884885
Print( "(Integers mod ", Size( obj ), ")" );
885886
end );
886887

888+
InstallMethod( String,
889+
"for full ring Z/nZ",
890+
[ IsZmodnZObjNonprimeCollection and IsWholeFamily ], SUM_FLAGS,
891+
obj -> Concatenation( "(Integers mod ", String( Size( obj ) ), ")" ) );
892+
887893

888894
#############################################################################
889895
##

tst/testinstall/MatrixObj/ListOp.tst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ gap> List( v );
2323
[ ]
2424
gap> List( v, DegreeFFE );
2525
[ ]
26+
gap> v1:= Vector( IsPlistVectorRep, Rationals, [] );;
27+
gap> v1[1]:= 0;
28+
Error, <p> is out of bounds
2629
gap> STOP_TEST("ListOp.tst");

tst/testinstall/MatrixObj/matobjplist.tst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ gap> START_TEST( "matobjplist.tst" );
33

44
#
55
gap> e:= MakeIsPlistVectorRep( Integers, [], true );;
6+
gap> MakeIsPlistVectorRep( Integers, [ 1 .. 4 ], true );;
7+
Error, <list> must be in 'IsPlistRep'
68
gap> v:= MakeIsPlistVectorRep( Integers, [ 1 ], true );;
79
gap> MakeIsPlistVectorRep( Integers, [ 1/2 ], true );;
810
Error, the elements in <list> must lie in <basedomain>

0 commit comments

Comments
 (0)