Skip to content
Closed
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
43 changes: 37 additions & 6 deletions hpcgap/lib/vecmat.gi
Original file line number Diff line number Diff line change
Expand Up @@ -2384,7 +2384,7 @@ InstallMethod( NumberRows, "for a gf2 matrix",
InstallMethod( NumberColumns, "for a gf2 matrix",
[ IsGF2MatrixRep ], function( m ) return Length(m[1]); end );
# FIXME: this breaks down for matrices with 0 rows
InstallMethod( Vector, "for a list of gf2 elements and a gf2 vector",
InstallOtherMethod( Vector, "for a list of gf2 elements and a gf2 vector",
[ IsList and IsFFECollection, IsGF2VectorRep ],
function( l, v )
local r;
Expand All @@ -2393,7 +2393,7 @@ InstallMethod( Vector, "for a list of gf2 elements and a gf2 vector",
return r;
end );

InstallMethodWithRandomSource( Randomize,
InstallOtherMethodWithRandomSource( Randomize,
"for a random source and a mutable gf2 vector",
[ IsRandomSource, IsGF2VectorRep and IsMutable ],
function( rs, v )
Expand Down Expand Up @@ -2450,7 +2450,7 @@ InstallMethod( ExtractSubMatrix, "for a gf2 matrix, and two lists",
return mm;
end );

InstallMethod( CopySubVector, "for two gf2 vectors, and two ranges",
InstallOtherMethod( CopySubVector, "for two gf2 vectors, and two ranges",
[IsGF2VectorRep, IsGF2VectorRep and IsMutable, IsRange, IsRange],
function( v, w, f, t )
local l;
Expand All @@ -2463,7 +2463,7 @@ InstallMethod( CopySubVector, "for two gf2 vectors, and two ranges",
fi;
end );

InstallMethod( CopySubVector, "for two gf2 vectors, and two lists",
InstallOtherMethod( CopySubVector, "for two gf2 vectors, and two lists",
[IsGF2VectorRep, IsGF2VectorRep and IsMutable, IsList, IsList],
function( v, w, f, t )
w{t} := v{f};
Expand Down Expand Up @@ -2601,14 +2601,45 @@ InstallMethod( CompatibleVectorFilter,
[ IsGF2MatrixRep ],
M -> IsGF2VectorRep );

InstallMethod( WeightOfVector, "for a gf2 vector",
InstallOtherMethod( WeightOfVector, "for a gf2 vector",
[ IsGF2VectorRep ],
function( v )
return WeightVecFFE(v);
end );

InstallMethod( DistanceOfVectors, "for two gf2 vectors",
InstallOtherMethod( DistanceOfVectors, "for two gf2 vectors",
[ IsGF2VectorRep, IsGF2VectorRep ],
function( v, w )
return DistanceVecFFE(v,w);
end );


#############################################################################
##
## What follows now are some hacks in order to get rid of
## the 'IsVectorObj' filter for 'IsGF2VectorRep' and
## the 'IsMatrixObj' filter for 'IsGF2MatrixRep'.
## Note that the objects in 'IsGF2MatrixRep' are in 'IsMatrix'
## because they get the type 'TYPE_LIST_GF2MAT' or 'TYPE_LIST_GF2MAT_IMM'.

# Without the following, the chosen 'ListOp' method would be `ShallowCopy`.
# This would in fact be better than the method below, but some test output
# would have to be adjusted.
InstallOtherMethod( ListOp,
[ IsGF2VectorRep ],
v -> List( [ 1 .. Length( v ) ], i -> v[i] ) );

# The following method is called in many tests.
# I would say it is a bad idea, one can do better by changing several
# methods on a deeper level.
# For example, 'DirectSumMat' calls 'NullMat' (not 'ZeroMatrix'),
# and this function does not create a 'GF2MatrixRep'.
# Changing 'DirectSumMat' would solve some of the problems.
InstallOtherMethod( CopySubMatrix,
[ IsGF2MatrixRep, IsPlistRep and IsMutable, IsList, IsList, IsList, IsList ],
function( M, N, srcrows, dstrows, srccols, dstcols )
local i;
for i in [ 1 .. Length( srcrows ) ] do
N[ dstrows[i] ]{ dstcols }:= M[ srcrows[i] ]{ srccols };
od;
end );
4 changes: 2 additions & 2 deletions lib/vecmat.gd
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ BIND_GLOBAL( "GF2Zero", 0*Z(2) );
## <Ref Filt="IsDataObjectRep"/>, the entries are packed into bits.
##
DeclareRepresentation( "IsGF2VectorRep",
IsDataObjectRep and IsVectorObj
IsDataObjectRep
and IsCopyable
and IsNoImmediateMethodsObject
and HasBaseDomain and HasOneOfBaseDomain and HasZeroOfBaseDomain);
Expand Down Expand Up @@ -254,7 +254,7 @@ DeclareGlobalFunction( "ConvertToMatrixRep" );
## <M>i+1</M>.
##
DeclareRepresentation( "IsGF2MatrixRep",
IsPositionalObjectRep and IsRowListMatrix
IsPositionalObjectRep
and IsCopyable
and IsNoImmediateMethodsObject
and HasNumberRows and HasNumberColumns
Expand Down
43 changes: 37 additions & 6 deletions lib/vecmat.gi
Original file line number Diff line number Diff line change
Expand Up @@ -2382,7 +2382,7 @@ InstallMethod( NumberRows, "for a gf2 matrix",
InstallMethod( NumberColumns, "for a gf2 matrix",
[ IsGF2MatrixRep ], function( m ) return Length(m[1]); end );
# FIXME: this breaks down for matrices with 0 rows
InstallMethod( Vector, "for a list of gf2 elements and a gf2 vector",
InstallOtherMethod( Vector, "for a list of gf2 elements and a gf2 vector",
[ IsList and IsFFECollection, IsGF2VectorRep ],
function( l, v )
local r;
Expand All @@ -2391,7 +2391,7 @@ InstallMethod( Vector, "for a list of gf2 elements and a gf2 vector",
return r;
end );

InstallMethodWithRandomSource( Randomize,
InstallOtherMethodWithRandomSource( Randomize,
"for a random source and a mutable gf2 vector",
[ IsRandomSource, IsGF2VectorRep and IsMutable ],
function( rs, v )
Expand Down Expand Up @@ -2448,7 +2448,7 @@ InstallMethod( ExtractSubMatrix, "for a gf2 matrix, and two lists",
return mm;
end );

InstallMethod( CopySubVector, "for two gf2 vectors, and two ranges",
InstallOtherMethod( CopySubVector, "for two gf2 vectors, and two ranges",
[IsGF2VectorRep, IsGF2VectorRep and IsMutable, IsRange, IsRange],
function( v, w, f, t )
local l;
Expand All @@ -2461,7 +2461,7 @@ InstallMethod( CopySubVector, "for two gf2 vectors, and two ranges",
fi;
end );

InstallMethod( CopySubVector, "for two gf2 vectors, and two lists",
InstallOtherMethod( CopySubVector, "for two gf2 vectors, and two lists",
[IsGF2VectorRep, IsGF2VectorRep and IsMutable, IsList, IsList],
function( v, w, f, t )
w{t} := v{f};
Expand Down Expand Up @@ -2599,14 +2599,45 @@ InstallMethod( CompatibleVectorFilter,
[ IsGF2MatrixRep ],
M -> IsGF2VectorRep );

InstallMethod( WeightOfVector, "for a gf2 vector",
InstallOtherMethod( WeightOfVector, "for a gf2 vector",
[ IsGF2VectorRep ],
function( v )
return WeightVecFFE(v);
end );

InstallMethod( DistanceOfVectors, "for two gf2 vectors",
InstallOtherMethod( DistanceOfVectors, "for two gf2 vectors",
[ IsGF2VectorRep, IsGF2VectorRep ],
function( v, w )
return DistanceVecFFE(v,w);
end );


#############################################################################
##
## What follows now are some hacks in order to get rid of
## the 'IsVectorObj' filter for 'IsGF2VectorRep' and
## the 'IsMatrixObj' filter for 'IsGF2MatrixRep'.
## Note that the objects in 'IsGF2MatrixRep' are in 'IsMatrix'
## because they get the type 'TYPE_LIST_GF2MAT' or 'TYPE_LIST_GF2MAT_IMM'.

# Without the following, the chosen 'ListOp' method would be `ShallowCopy`.
# This would in fact be better than the method below, but some test output
# would have to be adjusted.
InstallOtherMethod( ListOp,
[ IsGF2VectorRep ],
v -> List( [ 1 .. Length( v ) ], i -> v[i] ) );

# The following method is called in many tests.
# I would say it is a bad idea, one can do better by changing several
# methods on a deeper level.
# For example, 'DirectSumMat' calls 'NullMat' (not 'ZeroMatrix'),
# and this function does not create a 'GF2MatrixRep'.
# Changing 'DirectSumMat' would solve some of the problems.
InstallOtherMethod( CopySubMatrix,
[ IsGF2MatrixRep, IsPlistRep and IsMutable, IsList, IsList, IsList, IsList ],
function( M, N, srcrows, dstrows, srccols, dstcols )
local i;
for i in [ 1 .. Length( srcrows ) ] do
N[ dstrows[i] ]{ dstcols }:= M[ srcrows[i] ]{ srccols };
od;
end );
Loading