Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fingolfin opened this issue Oct 20, 2022 · 0 comments · May be fixed by #5163
Labels
gapdays2022-summer Issues and PRs that arose at https://www.gapdays.de/gapdays2022-summer

Comments

@fingolfin
Copy link
Member

fingolfin commented Oct 20, 2022

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 ]
@fingolfin fingolfin changed the title MatrixObj: add generic ViewObj/PrintObj/Display/ViewString/PrintString/DisplayString/String methods for MatrixObj MatrixObj: improve generic ViewObj/PrintObj/Display/ViewString/PrintString/DisplayString/String methods for MatrixObj Oct 20, 2022
@fingolfin fingolfin added the gapdays2022-summer Issues and PRs that arose at https://www.gapdays.de/gapdays2022-summer label Oct 20, 2022
@danielrademacher danielrademacher linked a pull request Oct 21, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gapdays2022-summer Issues and PRs that arose at https://www.gapdays.de/gapdays2022-summer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant