#15862: Mutability of tableaux, for the n-th time
-------------------------------------------------+-------------------------
       Reporter:  darij                          |        Owner:
           Type:  defect                         |       Status:  new
       Priority:  major                          |    Milestone:  sage-6.2
      Component:  combinatorics                  |   Resolution:
       Keywords:  tableaux, sage-combinat,       |    Merged in:
  mutability                                     |    Reviewers:
        Authors:                                 |  Work issues:
Report Upstream:  N/A                            |       Commit:
         Branch:                                 |     Stopgaps:
   Dependencies:                                 |
-------------------------------------------------+-------------------------

Comment (by tscrim):

 Sorry, I let this one drop off my radar. Here's the block that we should
 look at IMO (lines 315-318 in `tableau.py`)
 {{{#!python
 # CombinatorialObject verifies that t is a list
 # We must verify t is a list of lists
 if not all(isinstance(row, list) for row in t):
     raise ValueError("A tableau must be a list of lists.")
 }}}
 The first part of the comment is bogus, `CombinatorialObject` verifies
 that `t` acts like a list:
 {{{
 sage: CombinatorialObject((1,2,3))
 [1, 2, 3]
 }}}
 and from it's doc:
 {{{
 - ``l`` -- a list or any object that can be convert to a list by ``list``
 }}}
 The part we need to look it is should we just do something like `t =
 map(tuple, t)` for the tableau input and let that error out?

 Overall, there will be speed regression in the printing of tableaux.
 Here's what I would do for the `_repr_()`:
 {{{#!python
 def _repr_(self):
     return repr(map(list, self._list))
 }}}
 and here are some sample timings:
 {{{
 sage: L = [(1,2)]*5
 sage: %timeit repr(L)
 100000 loops, best of 3: 14.5 us per loop
 sage: %timeit repr(map(list, L))
 10000 loops, best of 3: 17.2 us per loop
 sage: L = [(1,2)]*20
 sage: %timeit repr(L)
 10000 loops, best of 3: 48.7 us per loop
 sage: %timeit repr(map(list, L))
 10000 loops, best of 3: 62 us per loop
 sage: L = [(1,2,3,4)]*100
 sage: %timeit repr(L)
 1000 loops, best of 3: 332 us per loop
 sage: %timeit repr(map(list, L))
 1000 loops, best of 3: 401 us per loop
 }}}
 So it's about 10-20% slowdown.
 (FYI `repr(L)` seems to be ever so slightly faster than `L.__repr__()`.)
 So perhaps we should make them all `CombinatorialObject` instead of
 `tuple`...?

 The other option to this would be having `__getitem__()` and the like
 return tuples or copies of the lists. I'm worried this might also result
 in a slowdown in code that is called significantly more often.

 For point 2., that shared data comment is about creating a tableau from
 another tableau. I use `Family` when I want immutable dictionaries,
 although I would still use a list of list (type) approach to arbitrary
 shaped tableaux.

--
Ticket URL: <http://trac.sagemath.org/ticket/15862#comment:4>
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