Skip to content

Commit

Permalink
ENHANCE: Cache the last 5 full-GL niceomorphisms
Browse files Browse the repository at this point in the history
  • Loading branch information
hulpke committed Sep 6, 2018
1 parent 474a064 commit f4ede03
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/grpffmat.gi
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,26 @@ end );
##
#M NiceMonomorphism( <ffe-mat-grp> )
##
MakeThreadLocal("FULLGLNICOCACHE"); # avoid recreating same homom. repeatedly
FULLGLNICOCACHE:=[];
InstallGlobalFunction( NicomorphismFFMatGroupOnFullSpace, function( grp )
local field, dim, V, xset, nice;

field := FieldOfMatrixGroup( grp );
dim := DimensionOfMatrixGroup( grp );

#check cache
V:=Size(field);
nice:=First(FULLGLNICOCACHE,x->x[1]=V and x[2]=dim);
if nice<>fail then return nice[3];fi;

if not (HasIsNaturalGL(grp) and IsNaturalGL(grp)) then
grp:=GL(dim,field); # enforce map on full GL
fi;
V := field ^ dim;
xset := ExternalSet( grp, V );


# STILL: reverse the base to get point sorting compatible with lexicographic
# vector arrangement
SetBaseOfGroup( xset, One( grp ));
Expand All @@ -144,6 +156,16 @@ InstallGlobalFunction( NicomorphismFFMatGroupOnFullSpace, function( grp )
SetFilterObj(nice,IsNiceMonomorphism);
# because we act on the full space we are canonical.
SetIsCanonicalNiceMonomorphism(nice,true);
if Size(V)>10^5 then
# store only one big one and have it get thrown out quickly
FULLGLNICOCACHE[1]:=[Size(field),dim,nice];
else
if Length(FULLGLNICOCACHE)>4 then
FULLGLNICOCACHE:=FULLGLNICOCACHE{[2..5]};
fi;
Add(FULLGLNICOCACHE,[Size(field),dim,nice]);
fi;

return nice;
end );

Expand Down
5 changes: 5 additions & 0 deletions tst/testbugfix/2018-09-05-CacheGL.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
gap> g:=SL(4,3);;
gap> NiceMonomorphism(g);;
gap> g:=GL(4,3);;
gap> hom:=NiceMonomorphism(g);;
gap> List(GeneratorsOfGroup(g),x->Image(hom,x));;

0 comments on commit f4ede03

Please sign in to comment.