From 0e29ceb2db977203854fe7a5d467514f9b6495f3 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 11 Jul 2019 11:29:08 +0200 Subject: [PATCH] Provide NrRows/NrCols methods for block matrices This also allows us to remove the custom DimensionsMat method. --- lib/matblock.gi | 30 ++++++++++++++++++++---------- tst/testinstall/matblock.tst | 12 ++++++++---- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/lib/matblock.gi b/lib/matblock.gi index 791745ed8a..4b00d43504 100644 --- a/lib/matblock.gi +++ b/lib/matblock.gi @@ -139,6 +139,26 @@ InstallOtherMethod( Length, blockmat -> blockmat!.nrb * blockmat!.rpb ); +############################################################################# +## +#M NrRows( ) . . . . . . . . . . . . . . . . for a block matrix +## +InstallMethod( NrRows, + "for an ordinary block matrix", + [ IsOrdinaryMatrix and IsBlockMatrixRep ], + blockmat -> blockmat!.nrb * blockmat!.rpb ); + + +############################################################################# +## +#M NrCols( ) . . . . . . . . . . . . . . . . for a block matrix +## +InstallMethod( NrCols, + "for an ordinary block matrix", + [ IsOrdinaryMatrix and IsBlockMatrixRep ], + blockmat -> blockmat!.ncb * blockmat!.cpb ); + + ############################################################################# ## #M \[\]( , ) . . . . . . . . . . . . . . . for a block matrix @@ -663,13 +683,3 @@ InstallMethod( PrintObj, Print( "BlockMatrix( ", m!.blocks, ",", m!.nrb, ",", m!.ncb, ",", m!.rpb, ",", m!.cpb, ",", m!.zero, " )" ); end ); - - -############################################################################# -## -#M DimensionsMat( ) . . . . . . . . . . . . . for a block matrix -## -InstallOtherMethod( DimensionsMat, - "for an ordinary block matrix", - [ IsOrdinaryMatrix and IsBlockMatrixRep ], - m -> [ m!.nrb * m!.rpb, m!.ncb * m!.cpb ] ); diff --git a/tst/testinstall/matblock.tst b/tst/testinstall/matblock.tst index 511ba067cc..285704c3f3 100644 --- a/tst/testinstall/matblock.tst +++ b/tst/testinstall/matblock.tst @@ -13,16 +13,20 @@ gap> m3 := AsBlockMatrix( m2, 2, 2 ); gap> z := BlockMatrix( [], 3, 3, 2, 2, 0 ); -gap> Length( m1 ); DimensionsMat( m1 ); +gap> NrRows( m1 ); NrCols( m1 ); DimensionsMat( m1 ); 6 +8 [ 6, 8 ] -gap> Length( m2 ); DimensionsMat( m2 ); +gap> NrRows( m2 ); NrCols( m2 ); DimensionsMat( m2 ); +6 6 [ 6, 6 ] -gap> Length( m3 ); DimensionsMat( m3 ); +gap> NrRows( m3 ); NrCols( m3 ); DimensionsMat( m3 ); +6 6 [ 6, 6 ] -gap> Length( z ); DimensionsMat( z ); +gap> NrRows( z ); NrCols( z ); DimensionsMat( z ); +6 6 [ 6, 6 ] gap> m1[3];