#15036: Speed up matrix repr for matrices larger than 20
----------------------------------+-----------------------------
       Reporter:  nbruin          |         Owner:
           Type:  defect          |        Status:  needs_review
       Priority:  major           |     Milestone:  sage-5.12
      Component:  linear algebra  |    Resolution:
       Keywords:                  |     Merged in:
        Authors:                  |     Reviewers:
Report Upstream:  N/A             |   Work issues:
         Branch:                  |  Dependencies:
       Stopgaps:                  |
----------------------------------+-----------------------------

Comment (by nbruin):

 Thanks for the feedback.

 '''UNPATCHED BEHAVIOUR:'''
 {{{
 sage: L=[matrix(20,20,[2]*400)]
 sage: L
 [20 x 20 dense matrix over Integer Ring]
 sage: A=L[0]
 sage: L
 [20 x 20 dense matrix over Integer Ring (type 'print A.str()' to see all
 of the entries)]
 sage: B=L[0]
 sage: L
 [20 x 20 dense matrix over Integer Ring (type 'print obj.str()' to see all
 of the entries)]
 }}}
 where you can see:
  - No printing tip if no direct binding is found
  - Printing of an explicit name if a unique direct binding is found
  - Printing of a generic `obj` name designator if more than one direct
 binding was found.

 This all with an excessively verbose:
 {{{
 sage: L=[matrix(20,20,[2]*400)]*10
 sage: A=L[0]
 sage: L
 [20 x 20 dense matrix over Integer Ring (type 'print A.str()' to see all
 of the entries),
  20 x 20 dense matrix over Integer Ring (type 'print A.str()' to see all
 of the entries),
  20 x 20 dense matrix over Integer Ring (type 'print A.str()' to see all
 of the entries),
  20 x 20 dense matrix over Integer Ring (type 'print A.str()' to see all
 of the entries),
  20 x 20 dense matrix over Integer Ring (type 'print A.str()' to see all
 of the entries),
  20 x 20 dense matrix over Integer Ring (type 'print A.str()' to see all
 of the entries),
  20 x 20 dense matrix over Integer Ring (type 'print A.str()' to see all
 of the entries),
  20 x 20 dense matrix over Integer Ring (type 'print A.str()' to see all
 of the entries),
  20 x 20 dense matrix over Integer Ring (type 'print A.str()' to see all
 of the entries),
  20 x 20 dense matrix over Integer Ring (type 'print A.str()' to see all
 of the entries)]
 }}}

 '''WITH THE PATCH:'''
 {{{
 sage: L=[matrix(20,20,[2]*400)]
 sage: L
 [20 x 20 dense matrix over Integer Ring]
 sage: A=L[0]
 sage: print A
 20 x 20 dense matrix over Integer Ring
 sage: A
 20 x 20 dense matrix over Integer Ring (type 'print A.str()' to see all of
 the entries)
 sage: L
 [20 x 20 dense matrix over Integer Ring]
 sage: L[0]
 20 x 20 dense matrix over Integer Ring (type 'print A.str()' to see all of
 the entries)
 sage: B=L[0]
 sage: L
 [20 x 20 dense matrix over Integer Ring]
 sage: L[0]
 20 x 20 dense matrix over Integer Ring (type 'print obj.str()' to see all
 of the entries)
 }}}

 Thus:
  - If the value returned is not a matrix itself (but for instance, a list
 with matrices in it), no tip is printed. I think that's appropriate.
  - Since the print hook of the interface is the routine that appends the
 message, a straight print statement never included the tip either
  - If the value itself is a matrix then the tip is included according to
 the rules that applied before.

 I think this is preferable to the old behaviour because
  - we're losing the inefficiency in most string productions
  - the tip is often annoying in list printing. That matrices are
 abbreviated in a list environment is understandable, I think. People will
 naturally try to look at the matrix itself if they are interested in the
 value.
  - we're still getting the tip in most cases where it's likely to be
 useful.

 We can implement Beezer's static suggestion in the displayhook, which will
 be more efficient (although that is not so important) and more
 appropriate. In that case we would get:

 {{{
 sage: L=[matrix(20,20,[2]*400)]
 sage: L
 [20 x 20 dense matrix over Integer Ring]
 sage: L[0]
 20 x 20 dense matrix over Integer Ring (use the '.str()' method to see the
 entries)
 sage: A=L[0]
 sage: L[0]
 20 x 20 dense matrix over Integer Ring (use the '.str()' method to see the
 entries)
 sage: print L[0]
 20 x 20 dense matrix over Integer Ring
 }}}

 I think this is the best solution, because:
  - It provides a useful tip consistently in a minimal case: when a matrix
 value is returned that gets printed in abbreviated form.
  - It provides a tip that's always correct, regardless of what bindings
 exist (and indeed, what bindings exist is immaterial for the problem that
 the user is facing)
  - We won't be digging around in the globals or the call stack without
 explicitly being asked to do so.

 So should we go for that then?

 Incidentally, I think `.str()` is an awful name for this method. The fact
 that `str(M)` and `M.str()` do similar but different things is a horrible
 trap. Also, `.str` and `.__str__` are too similar to both exist but be
 different. I don't have a direct alternative in mind, nor the inclination
 to follow through on the horrible deprecation process that would be
 required to remove this wart, though.

--
Ticket URL: <http://trac.sagemath.org/ticket/15036#comment:8>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to