gap icon indicating copy to clipboard operation
gap copied to clipboard

kernel: add some kernel dispatchers for matrix manipulation

Open fingolfin opened this issue 3 years ago • 0 comments

Yet another commit from an unfinished branch/PR that might be considered useful on its own: faster "early methods" for SwapRows/SwapCols using kernel methods. It is not tested thoroughly and I am not even sure we want to go in this direction, but we could e.g. use this as basis for discussions during the GAP Days


This speeds up swap operations for plain list matrices a lot, and even for "real" matrix objs, as the overhead of a GAP early method is much higher than the overhead of one written in the kernel.

Now whether this gain is worth the extra complexity is another question; though of course when doing heavy linear algebra, these row and column can add up.

Before:

gap> mat:=IdentityMat(10,Integers);;
gap> for i in [1..1000000] do SwapMatrixColumns(mat,1,2); od; time;
326
gap> for i in [1..1000000] do SwapMatrixRows(mat,1,2); od; time;
90
gap> for i in [1..1000000] do tmp:=mat[1];mat[1]:=mat[2];mat[2]:=tmp; od; time;
37

gap> mat:=IdentityMat(10,GF(2));; ConvertToMatrixRep(mat);; mat;
<a 10x10 matrix over GF2>
gap> for i in [1..1000000] do SwapMatrixRows(mat,1,2); od; time;
146
gap> for i in [1..1000000] do tmp:=mat[1];mat[1]:=mat[2];mat[2]:=tmp; od; time;
84

After:

gap> mat:=IdentityMat(10,Integers);;
gap> for i in [1..1000000] do SwapMatrixColumns(mat,1,2); od; time;
153
gap> for i in [1..1000000] do SwapMatrixRows(mat,1,2); od; time;
19
gap> for i in [1..1000000] do tmp:=mat[1];mat[1]:=mat[2];mat[2]:=tmp; od; time;
45

gap> mat:=IdentityMat(10,GF(2));; ConvertToMatrixRep(mat);; mat;
<a 10x10 matrix over GF2>
gap> for i in [1..1000000] do SwapMatrixRows(mat,1,2); od; time;
116
gap> for i in [1..1000000] do tmp:=mat[1];mat[1]:=mat[2];mat[2]:=tmp; od; time;
83

fingolfin avatar Jul 15 '22 12:07 fingolfin