From 32a7a19cd84fe825652488a75c09e40915e85e19 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 24 Mar 2025 01:10:05 +0100 Subject: [PATCH 1/2] WIP: Add AddMatrixRight/Left, MultMatrixRight/Left --- lib/matobj.gi | 41 +++++++++++++++++++++++++++++++++++++++++ lib/matobj2.gd | 21 +++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/lib/matobj.gi b/lib/matobj.gi index d397728233..418196dd78 100644 --- a/lib/matobj.gi +++ b/lib/matobj.gi @@ -1878,6 +1878,47 @@ InstallMethod( SwapMatrixColumns, "for a mutable matrix object, and two column n end ); +############################################################################ + +InstallMethod( AddMatrixRight, "for a mutable matrix object, a matrix object and a scalar", + [ IsMatrixOrMatrixObj and IsMutable, IsMatrixOrMatrixObj, IsObject ], + function( dstmat, srcmat, scalar ) + local i, j; +# Assert(0, NrRows(dstmat) = NrRows(srcmat)); +# Assert(0, NrCols(dstmat) = NrCols(srcmat)); + for i in [1..NrRows(dstmat)] do + for j in [1..NrCols(dstmat)] do + dstmat[i,j] := dstmat[i,j] + srcmat[i,j] * scalar; + od; + od; + end ); + +InstallEarlyMethod( AddMatrixRight, + function( dstmat, srcmat, scalar ) + local i; + if IsPlistRep(dstmat) and IsPlistRep(srcmat) then + # Assert(0, NrRows(dstmat) = NrRows(srcmat)); +# Assert(0, NrCols(dstmat) = NrCols(srcmat)); + for i in [1..NrRows(dstmat)] do + AddRowVector(dstmat[i], srcmat[i], scalar); + od; + else + TryNextMethod(); + fi; + end ); + +InstallMethod( AddMatrixRight, "for a mutable 8bit matrix, an 8bit matrix and a scalar", + [ Is8BitMatrixRep and IsMutable, Is8BitMatrixRep, IsFFE ], + function( dstmat, srcmat, scalar ) + local i, j; +# Assert(0, NrRows(dstmat) = NrRows(srcmat)); +# Assert(0, NrCols(dstmat) = NrCols(srcmat)); + for i in [1..NrRows(dstmat)] do + ADD_COEFFS_VEC8BIT_3(dstmat[i], srcmat[i], scalar); + od; + end ); + + ############################################################################ ## Fallback method for DeterminantMatrix InstallMethod(DeterminantMatrix, ["IsMatrixObj"], diff --git a/lib/matobj2.gd b/lib/matobj2.gd index fc73f88118..dafe15fbd3 100644 --- a/lib/matobj2.gd +++ b/lib/matobj2.gd @@ -2052,3 +2052,24 @@ DeclareOperationKernel( "SwapMatrixRows", [ IsMatrixOrMatrixObj and IsMutable, I ## <#/GAPDoc> ## DeclareOperationKernel( "SwapMatrixColumns", [ IsMatrixOrMatrixObj and IsMutable, IsInt, IsInt ], SWAP_MAT_COLS ); + + +############################################################################ +## +## +## +DeclareOperation( "AddMatrixRight", [ IsMatrixOrMatrixObj and IsMutable, IsMatrixOrMatrixObj, IsObject ] ); +#DeclareOperation( "AddMatrixLeft", [ IsMatrixOrMatrixObj and IsMutable, IsMatrixOrMatrixObj, IsObject ] ); + +# TODO: which default, left or right? +#DeclareSynonym( "AddMatrix", AddMatrixRowsLeft); + +############################################################################ +## +## +## +#DeclareOperation( "MultMatrixRight", [ IsMatrixOrMatrixObj and IsMutable, IsMatrixOrMatrixObj, IsObject ] ); +#DeclareOperation( "MultMatrixLeft", [ IsMatrixOrMatrixObj and IsMutable, IsMatrixOrMatrixObj, IsObject ] ); + +# TODO: which default, left or right? +#DeclareSynonym( "MultMatrix", MultMatrixLeft); From d1f06230794500221f93c4a799632231878a62c1 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 9 Apr 2025 17:34:58 +0200 Subject: [PATCH 2/2] Update lib/matobj2.gd --- lib/matobj2.gd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matobj2.gd b/lib/matobj2.gd index dafe15fbd3..5ac2e4d0fd 100644 --- a/lib/matobj2.gd +++ b/lib/matobj2.gd @@ -2068,8 +2068,8 @@ DeclareOperation( "AddMatrixRight", [ IsMatrixOrMatrixObj and IsMutable, IsMatri ## ## ## -#DeclareOperation( "MultMatrixRight", [ IsMatrixOrMatrixObj and IsMutable, IsMatrixOrMatrixObj, IsObject ] ); -#DeclareOperation( "MultMatrixLeft", [ IsMatrixOrMatrixObj and IsMutable, IsMatrixOrMatrixObj, IsObject ] ); +#DeclareOperation( "MultMatrixRight", [ IsMatrixOrMatrixObj and IsMutable, IsObject ] ); +#DeclareOperation( "MultMatrixLeft", [ IsMatrixOrMatrixObj and IsMutable, IsObject ] ); # TODO: which default, left or right? #DeclareSynonym( "MultMatrix", MultMatrixLeft);