#13991: Mitigate speed regressions in symmetric function related code due to 
#12313
---------------------------------+------------------------------------------
       Reporter:  nbruin         |         Owner:  sage-combinat
           Type:  enhancement    |        Status:  new          
       Priority:  major          |     Milestone:  sage-5.8     
      Component:  combinatorics  |    Resolution:               
       Keywords:                 |   Work issues:               
Report Upstream:  N/A            |     Reviewers:               
        Authors:                 |     Merged in:               
   Dependencies:  #13605         |      Stopgaps:               
---------------------------------+------------------------------------------

Comment (by SimonKing):

 I found that the Weyl group `WeylGroup(['A',k,1])` created in
 `sage.combinat.partition.Partition.from_kbounded_to_grassmannian` gets
 garbage collected repeatedly.

 Suggestion: Store these Weyl groups via a cached method of the partition,
 so that the Weyl group will only be garbage collected if the partition is
 garbage collected, too.

 My base line is sage-5.8.beta0 with patches as stated in my previous post.
 When I add the following patch,
 {{{
 #!patch
 # HG changeset patch
 # User Simon King <[email protected]>
 # Date 1362415985 -3600
 # Node ID 0ce4256bfbbf4b601e931bcc3fab6dea898b1138
 # Parent  0140ddcd1451ed7504456a7b72e9f2dc03ec2511
 imported patch trac_13991_cache_Weyl_partitions.patch

 diff --git a/sage/combinat/partition.py b/sage/combinat/partition.py
 --- a/sage/combinat/partition.py
 +++ b/sage/combinat/partition.py
 @@ -277,6 +277,7 @@
  from sage.misc.all import prod
  from sage.misc.prandom import randrange
  from sage.misc.classcall_metaclass import ClasscallMetaclass
 +from sage.misc.cachefunc import cached_method

  from sage.categories.infinite_enumerated_sets import
 InfiniteEnumeratedSets
  from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
 @@ -295,6 +296,7 @@
  from sage.combinat.integer_vector import IntegerVectors
  from sage.combinat.cartesian_product import CartesianProduct
  from sage.combinat.integer_list import IntegerListsLex
 +from sage.combinat.root_system.weyl_group import WeylGroup

  from sage.groups.perm_gps.permgroup import PermutationGroup

 @@ -3062,6 +3064,10 @@
                  p = p.remove_cell(x[0])
          return result

 +    @cached_method
 +    def _Weyl_group_A(self, k):
 +        return WeylGroup(['A',k,1])
 +
      def from_kbounded_to_grassmannian(self, k):
          r"""
          Maps a `k`-bounded partition to a Grassmannian element in
 @@ -3083,9 +3089,7 @@
              [0 1 0]
              [0 0 1]
          """
 -        from sage.combinat.root_system.weyl_group import WeylGroup
 -        W=WeylGroup(['A',k,1])
 -        return W.from_reduced_word(self.from_kbounded_to_reduced_word(k))
 +        return
 self._Weyl_group_A(k).from_reduced_word(self.from_kbounded_to_reduced_word(k))

      def to_list(self):
          r"""
 }}}
 the time for this test
 {{{
 sage: from sage.combinat.sf.k_dual import AffineSchurFunctions
 sage: F =
 
AffineSchurFunctions(SymmetricFunctions(QQ['t']).kBoundedQuotient(Integer(4),t=Integer(1)))
 sage: %time TestSuite(F).run()
 }}}
 drops from
 {{{
 CPU times: user 10.96 s, sys: 0.15 s, total: 11.11 s
 Wall time: 11.29 s
 }}}
 to
 {{{
 CPU times: user 10.11 s, sys: 0.25 s, total: 10.36 s
 Wall time: 10.48 s
 }}}

 This is at least something, and I could imagine that one could get more
 progress by further cached methods. Note that this would not open memory
 leaks, since the cache of the data happens only in the parent that needs
 these data.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13991#comment:40>
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to