Ticket #12876: trac_12876-fix-homset-cache-nt.patch

File trac_12876-fix-homset-cache-nt.patch, 3.7 KB (added by nthiery, 6 years ago)
  • sage/categories/homset.py

    # HG changeset patch
    # User Nicolas M. Thiery <nthiery@users.sf.net>
    # Date 1369403187 14400
    # Node ID 6e7e39dfc184f1f9f3d93f2f0db13118d18a5b3a
    # Parent  0bcd6cdb3fb0d7be672be0856c90e55da73dc635
    [mq]: trac_12876-fix-homset-cache-nt.patch
    
    diff --git a/sage/categories/homset.py b/sage/categories/homset.py
    a b def Hom(X, Y, category=None): 
    262262
    263263    """
    264264    # This should use cache_function instead
    265     # However it breaks somehow the coercion (see e.g. sage -t sage.rings.real_mpfr)
    266     # To be investigated.
     265    # However some special handling is currently needed for
     266    # domains/docomains that break the unique parent condition. Also,
     267    # at some point, it somehow broke the coercion (see e.g. sage -t
     268    # sage.rings.real_mpfr). To be investigated.
    267269    global _cache
    268270    key = (X,Y,category)
    269271    try:
    def Hom(X, Y, category=None): 
    271273    except KeyError:
    272274        H = None
    273275    if H is not None:
    274         # Are domain or codomain breaking the unique parent condition?
     276        # Return H unless the domain or codomain breaks the unique parent condition
    275277        if H.domain() is X and H.codomain() is Y:
    276278            return H
    277279
    def Hom(X, Y, category=None): 
    279281    cat_X = X.category()
    280282    cat_Y = Y.category()
    281283    if category is None:
    282         return Hom(X,Y,category=cat_X._meet_(cat_Y))
    283     if not isinstance(category, Category):
    284         raise TypeError, "Argument category (= %s) must be a category."%category
    285     if not cat_X.is_subcategory(category):
    286         raise TypeError, "%s is not in %s"%(X, category)
    287     if not cat_Y.is_subcategory(category):
    288         raise TypeError, "%s is not in %s"%(Y, category)
     284        category = cat_X._meet_(cat_Y)
     285        # Recurse to make sure that Hom(X, Y) and Hom(X, Y, category) are identical
     286        H = Hom(X, Y, category)
     287    else:
     288        if not isinstance(category, Category):
     289            raise TypeError, "Argument category (= %s) must be a category."%category
     290        if not cat_X.is_subcategory(category):
     291            raise TypeError, "%s is not in %s"%(X, category)
     292        if not cat_Y.is_subcategory(category):
     293            raise TypeError, "%s is not in %s"%(Y, category)
    289294
    290     # Construct H
    291     try: # _Hom_ hook from the parent
    292         H = X._Hom_(Y, category)
    293     except (AttributeError, TypeError):
    294         try:
    295             # Workaround in case the above fails, but the category
    296             # also provides a _Hom_ hook.
    297             # FIXME:
    298             # - If X._Hom_ actually comes from category and fails, it
    299             #   will be called twice.
    300             # - This is bound to fail if X is an extension type and
    301             #   does not actually inherit from category.parent_class
    302             H = category.parent_class._Hom_(X, Y, category = category)
     295        # Construct H
     296        try: # _Hom_ hook from the parent
     297            H = X._Hom_(Y, category)
    303298        except (AttributeError, TypeError):
    304             # By default, construct a plain homset.
    305             H = Homset(X, Y, category = category)
     299            try:
     300                # Workaround in case the above fails, but the category
     301                # also provides a _Hom_ hook.
     302                # FIXME:
     303                # - If X._Hom_ actually comes from category and fails, it
     304                #   will be called twice.
     305                # - This is bound to fail if X is an extension type and
     306                #   does not actually inherit from category.parent_class
     307                H = category.parent_class._Hom_(X, Y, category = category)
     308            except (AttributeError, TypeError):
     309                # By default, construct a plain homset.
     310                H = Homset(X, Y, category = category)
    306311    _cache[key] = H
    307312    return H
    308313