Skip to content

MatrixObj: improve generic ViewObj/PrintObj/Display/ViewString/PrintString/DisplayString/String methods for MatrixObj #5144

Open
@fingolfin

Description

@fingolfin

We have them (or some of them) in lib/matobj.gi, starting around line 1393:

BindGlobal( "ViewStringForVectorObj",
    v -> Concatenation( "<vector object of length ", String( Length( v ) ),
             " over ", String( BaseDomain( v ) ), ">" ) );

InstallMethod( ViewString,
    [ IsVectorObj ],
    ViewStringForVectorObj );

InstallMethod( DisplayString,
    [ IsVectorObj ],
    ViewStringForVectorObj );

InstallMethod( String,
    [ IsVectorObj ],
    v -> Concatenation( "NewVector( ",
             NameFunction( ConstructingFilter( v ) ), ", ",
             String( BaseDomain( v ) ), ", ",
             String( Unpack( v ) ), " )" ) );

BindGlobal( "ViewStringForMatrixObj",
    M -> Concatenation( "<matrix object of dimensions ",
             String( NumberRows( M ) ), "x", String( NumberColumns( M ) ),
             " over ", String( BaseDomain( M ) ), ">" ) );

InstallMethod( ViewString,
    [ IsMatrixOrMatrixObj ],
    ViewStringForMatrixObj );

InstallMethod( DisplayString,
    [ IsMatrixOrMatrixObj ],
    ViewStringForMatrixObj );

InstallMethod( String,
    [ IsMatrixObj ],
    M -> Concatenation( "NewMatrix( ",
               NameFunction( ConstructingFilter( M ) ), ", ",
               String( BaseDomain( M ) ), ", ",
               String( NumberColumns( M ) ), ", ",
               String( Unpack( M ) ), " )" ) );

Some thoughts:

  • these don't print any elements. I think it would be nice to be able to see the elements in the matrices, too. At least for Print and for Display. Perhaps it is OK if ViewObj only shows the current output, so that casually typing a matrix does not spam things... Dunnp
  • Print is meant to output code which can be read in back; I am not sure whether we can do that in general, but if we want to try it, it could start with something like NewMatrix(FILTER, BASEDOMAIN, MAT) where MAT is the result of Unpack for the original matrix
  • ViewObj and/or Display could replace zeros by . and generally produce something more for humans, e.g.
gap> some_matobj;
A 2x3 matrix over GF(5):
. 1 3
3 . 2
  • Julia has a nice feature were matrices are printed with elements; but if the number of rows and/or columns is too large, then it hides some rows/columns, and replaces them by some characters indicating this ... like in [1 2 ... 999 1000] or even using Unicode, e.g. [ 1 2 ⋯ 999 1000 ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    gapdays2022-summerIssues and PRs that arose at https://www.gapdays.de/gapdays2022-summer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions