Skip to content

Commit

Permalink
Merge pull request #540 from kamalsaleh/random_matrices
Browse files Browse the repository at this point in the history
Get simpler random matrices/elements by adjusting the current hard coded parameters
  • Loading branch information
mohamed-barakat authored Oct 10, 2022
2 parents 45869a8 + f11c1fd commit 698bcb6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion MatricesForHomalg/PackageInfo.g
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SetPackageInfo( rec(

PackageName := "MatricesForHomalg",
Subtitle := "Matrices for the homalg project",
Version := "2022.10-03",
Version := "2022.10-04",
Date := Concatenation( "01/", ~.Version{[ 6, 7 ]}, "/", ~.Version{[ 1 .. 4 ]} ),
License := "GPL-2.0-or-later",

Expand Down
41 changes: 33 additions & 8 deletions MatricesForHomalg/gap/Tools.gi
Original file line number Diff line number Diff line change
Expand Up @@ -4518,6 +4518,11 @@ InstallMethod( GetRidOfRowsAndColumnsWithUnits,

end );

##
## L = [ min_deg, max_deg, zt, coeff ]
## min_deg and max_deg determine the minimal and maximal degree of the element
## zt determines the percentage of the zero terms in the element
## The non-trivial coefficients belong to the interval [ 1 .. coeffs ]
##
InstallMethod( Random,
"for a homalg ring and a list",
Expand Down Expand Up @@ -4549,21 +4554,17 @@ InstallMethod( Random,

end );

if IsPackageMarkedForLoading( "utils", ">= 0.54" ) then

##
InstallMethod( Random,
"for a homalg ring",
[ IsHomalgRing ],

function( R )

return Random( R, RandomCombination( [ 0 .. 10 ], Random( [ 1 .. 11 ] ) ) );
return Random( R, [ 0, Random( [ 0, 1, 1, 1, 2, 2, 2, 3 ] ), 80, 50 ] );

end );

fi;

##
InstallMethod( Random,
"for a homalg internal ring",
Expand Down Expand Up @@ -5087,6 +5088,30 @@ InstallMethod( RandomMatrix,

end );

##
## params = [ min_deg,max_deg,ze,zt,coeffs ]
##
## min_deg and max_deg determine the minimal and maximal degree of an entry in the matrix
## ze determines the percentage of the zero entries in the matrix (The default value is 50)
## zt determines the percentage of the zero terms in each entry in the matrix (The default value is 80)
## The non-trivial coefficients of each entry belong to the interval [ 1 .. coeffs ] (The default value is 10)
##
InstallOtherMethod( RandomMatrix,
"for two integers, a homalg ring and a list",
[ IsInt, IsInt, IsHomalgRing, IsList ],
function( r, c, R, params )
local RP;

RP := homalgTable( R );

if IsBound(RP!.RandomMat) then
return HomalgMatrix( CallFuncList( RP!.RandomMat, Concatenation( [ R, r, c ], params ) ), r, c, R );
else
TryNextMethod();
fi;

end );

##
InstallMethod( RandomMatrix,
"for two integers and a homalg ring",
Expand All @@ -5104,11 +5129,11 @@ InstallMethod( RandomMatrix,

RP := homalgTable( R );

if IsBound(RP!.RandomMat) and IsPackageMarkedForLoading( "utils", ">= 0.54" ) then
if IsBound(RP!.RandomMat) then

params := ValueGlobal( "RandomCombination" )( [ 0 .. 10 ], Random( [ 1 .. 11 ] ) );
params := [ 0, Random( [ 1, 1, 1, 2, 2, 2, 3 ] ), 50, 80, 50 ];

return HomalgMatrix( CallFuncList( RP!.RandomMat, Concatenation( [ R, r, c ], params ) ), r, c, R );
return RandomMatrix( r, c, R, params );

fi;

Expand Down

0 comments on commit 698bcb6

Please sign in to comment.