Ticket #13184: trac_13184_sage_5.9.beta.patch

File trac_13184_sage_5.9.beta.patch, 4.2 KB (added by chapoton, 7 years ago)
  • sage/categories/homset.py

    # HG changeset patch
    # User Xavier Caruso <xavier.caruso@normalesup.org>
    # Date 1341738209 -7200
    # Node ID b510f107752e0babcad7e1e2845cd1148d30dc49
    # Parent  6fdfbac91d70604e701510fd469df37f860bbedb
    Trac #13184: Unique parent assumption for homset
    
    diff --git a/sage/categories/homset.py b/sage/categories/homset.py
    a b from sage.categories.category import Cat 
    6868import morphism
    6969from sage.structure.parent import Parent, Set_generic
    7070from sage.misc.lazy_attribute import lazy_attribute
    71 from sage.misc.cachefunc import cached_function
    7271import types
    7372
    7473###################################
    def Hom(X, Y, category=None): 
    157156
    158157    TESTS:
    159158
     159    Homset are unique parents::
     160
     161        sage: k = GF(5)
     162        sage: H1 = Hom(k,k)
     163        sage: H2 = Hom(k,k)
     164        sage: H1 is H2
     165        True
     166
    160167    Some doc tests in :mod:`sage.rings` (need to) break the unique parent
    161168    assumption. But if domain or codomain are not unique parents, then the hom
    162     set won't fit. That's to say, the hom set found in the cache will have a
     169    set will not fit. That is to say, the hom set found in the cache will have a
    163170    (co)domain that is equal to, but not identic with, the given (co)domain.
    164171
    165172    By :trac:`9138`, we abandon the uniqueness of hom sets, if the domain or
    def Hom(X, Y, category=None): 
    227234
    228235    try:
    229236        # Apparently X._Hom_ is supposed to be cached
    230         return X._Hom_(Y, category)
     237        # but it is not in some cases (e.g. X is a finite field)
     238        # To be investigated
     239        H = X._Hom_(Y,category)
     240        _cache[key] = H
     241        return H
    231242    except (AttributeError, TypeError):
    232243        pass
    233244
  • sage/modules/vector_space_homspace.py

    diff --git a/sage/modules/vector_space_homspace.py b/sage/modules/vector_space_homspace.py
    a b TESTS:: 
    193193import inspect
    194194import sage.matrix.all as matrix
    195195import sage.modules.free_module_homspace
    196 import vector_space_morphism
    197196
    198197# This module initially overrides just the minimum functionality necessary
    199198# from  sage.modules.free_module_homspace.FreeModuleHomSpace.
    class VectorSpaceHomspace(sage.modules.f 
    333332
    334333            sage: U = QQ^3
    335334            sage: V = QQ^4
    336             sage: W = QQ^3
     335            sage: W = FreeModule(QQ,3,sparse=True)
    337336            sage: X = QQ^4
    338337            sage: H = Hom(U, V)
    339338            sage: K = Hom(W, X)
     339            sage: H is K
     340            False
    340341
    341342            sage: A = matrix(QQ, 3, 4, [0]*12)
    342343            sage: f = H(A)
    343344            sage: B = matrix(QQ, 3, 4, range(12))
    344345            sage: g = K(B)
    345             sage: f.parent() is g.parent()
    346             False
     346            sage: f.parent() is H and g.parent() is K
     347            True
    347348
    348349            sage: h = H(g)
    349350            sage: f.parent() is h.parent()
    class VectorSpaceHomspace(sage.modules.f 
    362363        Previously the above code resulted in a TypeError because the
    363364        dimensions of the matrix were incorrect.
    364365        """
    365         import vector_space_morphism
     366        from vector_space_morphism import is_VectorSpaceMorphism, VectorSpaceMorphism
    366367        D = self.domain()
    367368        C = self.codomain()
    368369        if matrix.is_Matrix(A):
    369370            pass
    370         elif vector_space_morphism.is_VectorSpaceMorphism(A):
     371        elif is_VectorSpaceMorphism(A):
    371372            A = A.matrix()
    372373        elif inspect.isfunction(A):
    373374            try:
    class VectorSpaceHomspace(sage.modules.f 
    393394        else:
    394395            msg = 'vector space homspace can only coerce matrices, vector space morphisms, functions or lists, not {0}'
    395396            raise TypeError(msg.format(A))
    396         return vector_space_morphism.VectorSpaceMorphism(self, A)
     397        return VectorSpaceMorphism(self, A)
    397398
    398399    def _repr_(self):
    399400        r"""
    class VectorSpaceHomspace(sage.modules.f 
    409410            'dimension', '3', 'over', 'Rational', 'Field']
    410411        """
    411412        msg = 'Set of Morphisms (Linear Transformations) from {0} to {1}'
    412         return msg.format(self.domain(), self.codomain())
    413  No newline at end of file
     413        return msg.format(self.domain(), self.codomain())