Ticket #11521: trac_11521-reviewer.patch

File trac_11521-reviewer.patch, 2.3 KB (added by jpflori, 9 years ago)

Reviewer patch; added doc

  • sage/categories/homset.py

    # HG changeset patch
    # User Jean-Pierre Flori <jean-pierre.flor@ssi.gouv.fr>
    # Date 1332265553 -3600
    # Node ID 6ae87d84ec503b28ab3a7240a9dd7becfe63c803
    # Parent  e7d3eef7fcfd286a6483d9daf2eafebd518b50b0
    #11521: Reviewer patch
    
    diff --git a/sage/categories/homset.py b/sage/categories/homset.py
    a b  
    1 """
     1r"""
    22Homsets
    33
     4The class :class:`Hom` is the base class used to represent sets of morphisms
     5between objects of a given category.
     6:class:`Hom` objects are usually "weakly" cached upon creation so that they
     7don't have to be generated over and over but can be garbage collected together
     8with the corresponding objects when these are are not stongly ref'ed anymore.
     9
     10EXAMPLES:
     11
     12In the following, the :class:`Hom` object is indeed cached::
     13
     14    sage: K = GF(17)
     15    sage: H = Hom(ZZ, K)
     16    sage: H
     17    Set of Homomorphisms from Integer Ring to Finite Field of size 17
     18    sage: H is Hom(ZZ, K)
     19    True
     20
     21Nonetheless, garbage collection occurs when the original references are
     22overwritten::
     23
     24    sage: for p in prime_range(200):
     25    ...     K = GF(p)
     26    ...     H = Hom(ZZ, K)
     27    ...
     28    sage: import gc
     29    sage: _ = gc.collect()
     30    sage: from sage.rings.finite_rings.finite_field_prime_modn import FiniteField_prime_modn as FF
     31    sage: L = [x for x in gc.get_objects() if isinstance(x, FF)]
     32    sage: len(L)
     33    2
     34    sage: L
     35    [Finite Field of size 2, Finite Field of size 199]
     36
    437AUTHORS:
    538
    639- David Kohel and William Stein
     
    2962#                  http://www.gnu.org/licenses/
    3063#*****************************************************************************
    3164
    32 import weakref
    33 
    3465from sage.categories.category import Category
    3566import morphism
    3667from sage.structure.parent import Parent, Set_generic
     
    81112        sage: Hom(FreeModule(QQ,1), FreeModule(ZZ,1))
    82113        Set of Morphisms from Vector space of dimension 1 over Rational Field to Ambient free module of rank 1 over the principal ideal domain Integer Ring in Category of vector spaces over Rational Field
    83114
    84     Here, we test against a memory leak that has been fixed at #11521 by using
    85     a weak cache::
     115    Here, we test against a memory leak that has been fixed at :trac:`11521` by
     116    using a weak cache::
    86117
    87118        sage: for p in prime_range(10^5):
    88119        ...    K = GF(p)