#14793: Unique representation for homsets
-------------------------------+--------------------------------------------
       Reporter:  nthiery      |         Owner:  nthiery     
           Type:  enhancement  |        Status:  needs_review
       Priority:  major        |     Milestone:  sage-5.12   
      Component:  categories   |    Resolution:              
       Keywords:               |   Work issues:              
Report Upstream:  N/A          |     Reviewers:              
        Authors:  Simon King   |     Merged in:              
   Dependencies:               |      Stopgaps:              
-------------------------------+--------------------------------------------
Changes (by SimonKing):

  * status:  new => needs_review


Old description:

> The unique representation of homsets is taken care of by ``Hom``. What's
> missing is:
>
> - Fast hash and comparison by id. This can be implemented by having
> Homset inherit from WithEqualityById
> - Pickling by construction, calling back Hom(domain, codomain, category)

New description:

 The unique representation of homsets is taken care of by ``Hom``. What's
 missing is:

 - Fast hash and comparison by id. This can be implemented by having Homset
 inherit from WithEqualityById
 - Pickling by construction, calling back Hom(domain, codomain, category)

 __Apply__

 * [attachment:trac14793-homset_default_pickling.patch]

--

Comment:

 I think I have solved all remaining problems. I needed to modify the
 suggested logic of "relaxing the category test when there is reason to
 believe that Hom is called on a domain that is in the process of being
 unpickled".

 It now reads like this:
 {{{
 #!python
     # Determines the category
     if category is None:
         category = X.category()._meet_(Y.category())
         # Recurse to make sure that Hom(X, Y) and Hom(X, Y, category) are
 identical
         H = Hom(X, Y, category)
     else:
         if not isinstance(category, Category):
             raise TypeError, "Argument category (= %s) must be a
 category."%category
         # See trac #14793: It can happen, that Hom(X,X) is called during
         # unpickling of an instance X of a Python class at a time when
         # X.__dict__ is empty.  In some of these cases, X.category() would
         # raise a error or would return a too large category (Sets(), for
         # example) and (worse!) would assign this larger category to the
         # X._category cdef attribute, so that it would subsequently seem
 that
         # X's category was properly initialised.

         # However, if the above scenario happens, then *before* calling
         # X.category(), X._is_category_initialised() will correctly say
 that
         # it is not initialised. Moreover, since X.__class__ is a Python
         # class, we will find that `isinstance(X, category.parent_class)`.
 If
         # this is the case, then we trust that we indeed are in the
 process of
         # unpickling X.  Hence, we will trust that `category` has the
 correct
         # value, and we will thus skip the test whether `X in category`.
         try:
             unpickle_X = (not X._is_category_initialized()) and
 isinstance(X,category.parent_class)
         except AttributeError: # this happens for simplicial complexes
             unpickle_X = False
         try:
             unpickle_Y = (not Y._is_category_initialized()) and
 isinstance(Y,category.parent_class)
         except AttributeError:
             unpickle_Y = False
         if unpickle_X:
             cat_X = category
         else:
             try:
                 cat_X = X.category()
             except BaseException:
                 raise TypeError, "%s is not in %s"%(X, category)
         if unpickle_Y:
             cat_Y = category
         else:
             try:
                 cat_Y = Y.category()
             except BaseException:
                 raise TypeError, "%s is not in %s"%(Y, category)
 }}}

 Note the comment on simplicial complexes: They do have a `.category()`
 method, but they do not derive from `CategoryObject` and thus have no
 `._is_category_initialized()` method. Shame on them.

 In addition, some changes needed to be done for `SchemeHomsets` and the
 like. I think one can now start with reviewing.

 Apply trac14793-homset_default_pickling.patch

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