Skip to content

Commit

Permalink
Provide NrRows/NrCols methods for block matrices
Browse files Browse the repository at this point in the history
This also allows us to remove the custom DimensionsMat method.
  • Loading branch information
fingolfin committed Jul 11, 2019
1 parent 507da64 commit 0e29ceb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
30 changes: 20 additions & 10 deletions lib/matblock.gi
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ InstallOtherMethod( Length,
blockmat -> blockmat!.nrb * blockmat!.rpb );


#############################################################################
##
#M NrRows( <blockmat> ) . . . . . . . . . . . . . . . . for a block matrix
##
InstallMethod( NrRows,
"for an ordinary block matrix",
[ IsOrdinaryMatrix and IsBlockMatrixRep ],
blockmat -> blockmat!.nrb * blockmat!.rpb );


#############################################################################
##
#M NrCols( <blockmat> ) . . . . . . . . . . . . . . . . for a block matrix
##
InstallMethod( NrCols,
"for an ordinary block matrix",
[ IsOrdinaryMatrix and IsBlockMatrixRep ],
blockmat -> blockmat!.ncb * blockmat!.cpb );


#############################################################################
##
#M \[\]( <blockmat>, <n> ) . . . . . . . . . . . . . . . for a block matrix
Expand Down Expand Up @@ -663,13 +683,3 @@ InstallMethod( PrintObj,
Print( "BlockMatrix( ", m!.blocks, ",", m!.nrb, ",", m!.ncb,
",", m!.rpb, ",", m!.cpb, ",", m!.zero, " )" );
end );


#############################################################################
##
#M DimensionsMat( <blockmat> ) . . . . . . . . . . . . . for a block matrix
##
InstallOtherMethod( DimensionsMat,
"for an ordinary block matrix",
[ IsOrdinaryMatrix and IsBlockMatrixRep ],
m -> [ m!.nrb * m!.rpb, m!.ncb * m!.cpb ] );
12 changes: 8 additions & 4 deletions tst/testinstall/matblock.tst
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@ gap> m3 := AsBlockMatrix( m2, 2, 2 );
<block matrix of dimensions (2*3)x(2*3)>
gap> z := BlockMatrix( [], 3, 3, 2, 2, 0 );
<block matrix of dimensions (3*2)x(3*2)>
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];
Expand Down

0 comments on commit 0e29ceb

Please sign in to comment.