Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce MakeIsPlistVectorRep helper #5333

Merged
merged 2 commits into from
Jan 23, 2023
Merged
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
152 changes: 152 additions & 0 deletions benchmark/matobj/bench-matelm-access.g
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
ReadGapRoot("benchmark/matobj/bench.g");


TestReadingMatrix := function(m)
local f;

PrintHeadline("m[i][j]");
MyBench(function()
local u, i, j, rows, cols, x;
rows := [1..Length(m)];
cols := [1..Length(m[1])];
for u in [1..QuoInt(100000,Length(m)*Length(m[1]))] do
for i in rows do
for j in cols do
x:=m[i][j];
od;
od;
od;
end);

PrintHeadline("m[i,j]");
MyBench(function()
local u, i, j, rows, cols, x;
rows := [1..Length(m)];
cols := [1..Length(m[1])];
for u in [1..QuoInt(100000,Length(m)*Length(m[1]))] do
for i in rows do
for j in cols do
x:=m[i,j];
od;
od;
od;
end);

PrintHeadline("MatElm(m,i,j)");
MyBench(function()
local u, i, j, rows, cols, x;
rows := [1..Length(m)];
cols := [1..Length(m[1])];
for u in [1..QuoInt(100000,Length(m)*Length(m[1]))] do
for i in rows do
for j in cols do
x:=MatElm(m,i,j);
od;
od;
od;
end);

PrintHeadline("MatElm(m,i,j) with prefetched method");
f:=ApplicableMethod(MatElm, [m,1,1]);;
MyBench(function()
local u, i, j, rows, cols, x;
rows := [1..Length(m)];
cols := [1..Length(m[1])];
for u in [1..QuoInt(100000,Length(m)*Length(m[1]))] do
for i in rows do
for j in cols do
x:=f(m,i,j);
od;
od;
od;
end);

end;

TestWritingMatrix := function(m)
local f;

PrintHeadline("m[i][j]:=elm");
MyBench(function()
local u, i, j, rows, cols, x;
x:=m[1][1];
rows := [1..Length(m)];
cols := [1..Length(m[1])];
for u in [1..QuoInt(100000,Length(m)*Length(m[1]))] do
for i in rows do
for j in cols do
m[i][j]:=x;
od;
od;
od;
end);

PrintHeadline("m[i,j]:=elm");
MyBench(function()
local u, i, j, rows, cols, x;
x:=m[1][1];
rows := [1..Length(m)];
cols := [1..Length(m[1])];
for u in [1..QuoInt(100000,Length(m)*Length(m[1]))] do
for i in rows do
for j in cols do
m[i,j]:=x;
od;
od;
od;
end);

PrintHeadline("SetMatElm(m,i,j,elm)");
MyBench(function()
local u, i, j, rows, cols, x;
x:=m[1][1];
rows := [1..Length(m)];
cols := [1..Length(m[1])];
for u in [1..QuoInt(100000,Length(m)*Length(m[1]))] do
for i in rows do
for j in cols do
SetMatElm(m,i,j,x);
od;
od;
od;
end);

PrintHeadline("SetMatElm(m,i,j,elm) with prefetched method");
f:=ApplicableMethod(SetMatElm, [m,1,1,m[1][1]]);;
MyBench(function()
local u, i, j, rows, cols, x;
x:=m[1][1];
rows := [1..Length(m)];
cols := [1..Length(m[1])];
for u in [1..QuoInt(100000,Length(m)*Length(m[1]))] do
for i in rows do
for j in cols do
f(m,i,j,x);
od;
od;
od;
end);
end;

RunMatTest := function(desc, m)
Print("\n");
PrintBoxed(Concatenation("Testing ", desc));
TestReadingMatrix(m);
Print(TextAttr.2, "...now testing write access...\n", TextAttr.reset);
TestWritingMatrix(m);
end;

m:=IdentityMat(10);;
RunMatTest("integer matrix", m);

m:=IdentityMat(10,GF(2));;
RunMatTest("GF(2) rowlist", m);

m:=IdentityMat(10,GF(2));; ConvertToMatrixRep(m);;
RunMatTest("GF(2) compressed matrix", m);

m:=IdentityMat(10,GF(7));;
RunMatTest("GF(7) rowlist", m);

m:=IdentityMat(10,GF(7));; ConvertToMatrixRep(m);;
RunMatTest("GF(7) compressed matrix", m);
108 changes: 108 additions & 0 deletions benchmark/matobj/bench-matobj-creation.g
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
ReadGapRoot("benchmark/matobj/bench.g");

# test for old-style matrix constructors, as reference
TestCreatingMatrix := function(ring)
PrintHeadline("NullMat");
MyBench(function()
local m, n, mat;
for m in [1..10] do
for n in [1..10] do
mat := NullMat(m, n, ring);
od;
od;
end);

PrintHeadline("IdentityMat");
MyBench(function()
local n, mat;
for n in [1..100] do
mat := IdentityMat(n, ring);
od;
end);
end;

# test for matriobj constructors
TestCreatingMatrixObj := function(filter, ring)
local example_mat;

example_mat := NewZeroMatrix(filter, ring, 1, 1);

PrintHeadline("NewZeroMatrix");
MyBench(function()
local m, n, mat;
for m in [1..10] do
for n in [1..10] do
mat := NewZeroMatrix(filter, ring, m, n);
od;
od;
end);

PrintHeadline("ZeroMatrix( filt, R, m, n )");
MyBench(function()
local m, n, mat;
for m in [1..10] do
for n in [1..10] do
mat := ZeroMatrix(filter, ring, m, n);
od;
od;
end);

PrintHeadline("ZeroMatrix( m, n, M )");
MyBench(function()
local m, n, mat;
for m in [1..10] do
for n in [1..10] do
mat := ZeroMatrix(m, n, example_mat);
od;
od;
end);

PrintHeadline("NewIdentityMatrix");
MyBench(function()
local n, mat;
for n in [1..100] do
mat := NewIdentityMatrix(filter, ring, n);
od;
end);

PrintHeadline("IdentityMatrix( filt, R, n )");
MyBench(function()
local n, mat;
for n in [1..100] do
mat := IdentityMatrix(filter, ring, n);
od;
end);

PrintHeadline("IdentityMatrix( n, M )");
MyBench(function()
local n, mat;
for n in [1..100] do
mat := IdentityMatrix(n, example_mat);
od;
end);

# TODO: NewMatrix
# TODO: Matrix
end;

RunMatTest := function(desc, ring)
Print("\n");
PrintBoxed(Concatenation("Testing ", desc));
TestCreatingMatrix(ring);
end;

RunMatTest("GF(2)", GF(2));
RunMatTest("Rationals", Rationals);

RunMatObjTest := function(desc, filter, ring)
Print("\n");
PrintBoxed(Concatenation("Testing ", desc));
TestCreatingMatrixObj(filter, ring);
end;

RunMatObjTest("GF(2) IsPlistMatrixRep", IsPlistMatrixRep, GF(2));
RunMatObjTest("integer IsPlistMatrixRep", IsPlistMatrixRep, Integers);
RunMatObjTest("rational IsPlistMatrixRep", IsPlistMatrixRep, Rationals);

# TODO: other reps
# TODO: other compare with creating plist-of-plist
82 changes: 82 additions & 0 deletions benchmark/matobj/bench-vecobj-creation.g
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
ReadGapRoot("benchmark/matobj/bench.g");


TestCreatingVector := function(v)
Error("TODO");
end;

# test for old-style vector constructors, as reference
TestCreatingVector := function(ring)
PrintHeadline("ListWithIdenticalEntries");
MyBench(function()
local n, vec;
for n in [1..10] do
vec := ListWithIdenticalEntries(n, Zero(ring));
od;
end);

PrintHeadline("ListWithIdenticalEntries + ConvertToVectorRepNC");
MyBench(function()
local n, vec;
for n in [1..10] do
vec := ListWithIdenticalEntries(n, Zero(ring));
ConvertToVectorRepNC(vec, ring);
od;
end);
end;

# test for VectorObj constructors
TestCreatingVectorObj := function(filter, ring)
local example_vec;

example_vec := NewZeroVector(filter, ring, 1);

PrintHeadline("NewZeroVector( filt, R, n )");
MyBench(function()
local n, vec;
for n in [1..10] do
vec := NewZeroVector(filter, ring, n);
od;
end);

PrintHeadline("ZeroVector( filt, R, n )");
MyBench(function()
local n, vec;
for n in [1..10] do
vec := ZeroVector(filter, ring, n);
od;
end);

PrintHeadline("ZeroVector( n, M )");
MyBench(function()
local n, vec;
for n in [1..10] do
vec := ZeroVector(n, example_vec);
od;
end);

# TODO: NewVector
# TODO: Vector
end;

RunMatTest := function(desc, ring)
Print("\n");
PrintBoxed(Concatenation("Testing ", desc));
TestCreatingVector(ring);
end;

RunMatTest("GF(2)", GF(2));
RunMatTest("Rationals", Rationals);

RunMatObjTest := function(desc, filter, ring)
Print("\n");
PrintBoxed(Concatenation("Testing ", desc));
TestCreatingVectorObj(filter, ring);
end;

RunMatObjTest("GF(2) IsPlistVectorRep", IsPlistVectorRep, GF(2));
RunMatObjTest("integer IsPlistVectorRep", IsPlistVectorRep, Integers);
RunMatObjTest("rational IsPlistVectorRep", IsPlistVectorRep, Rationals);

# TODO: other reps
# TODO: other compare with creating plist-of-plist
Loading