#14054: Cythoned UniqueRepresentation
-----------------------------------------------+----------------------------
       Reporter:  SimonKing                    |         Owner:  tbd            
 
           Type:  enhancement                  |        Status:  needs_review   
 
       Priority:  major                        |     Milestone:  sage-5.7       
 
      Component:  performance                  |    Resolution:                 
 
       Keywords:  cython UniqueRepresentation  |   Work issues:                 
 
Report Upstream:  N/A                          |     Reviewers:  Travis 
Scrimshaw
        Authors:  Simon King                   |     Merged in:                 
 
   Dependencies:  #14017                       |      Stopgaps:                 
 
-----------------------------------------------+----------------------------

Old description:

> `UniqueRepresentation` provides a comfortable way to create unique parent
> structures, and automatically provides a hash and certain comparison
> methods. Problem: It relies on a metaclass, namely `ClasscallMetaclass`
> and thus has to be a Python class. That's bad for speed.
>
> Here, I suggest to create a new cdef class `UniqueRepresentation_c` that
> provides hash and comparison, and let `UniqueRepresentation` inherit from
> it, just adding the classcall method.
>
> The problem is that `UniqueRepresentation` relies on cached_method, and
> this decorator had problems to work on methods defined in Cython with
> varargs and keywords arguments. That is fixed in #14017, which is thus a
> dependency.

New description:

 `UniqueRepresentation` provides a comfortable way to create unique parent
 structures, and automatically provides a hash and certain comparison
 methods.

 Problems:

 - It relies on a metaclass, namely `ClasscallMetaclass` and thus has to be
 a Python class. That's bad for speed.
 - It combines two features, namely a cache and unique instance behaviour.
 But in many some cases we want a cache so that two distinct instances can
 still be equal.

 Here, I suggest to

 1. separate the two features, by creating a new class
 `sage.unique_representation.CachedRepresentation` as one base of
 `UniqueRepresentation`.
 2. create a new cdef class `sage.misc.fast_methods.WithRichCmpById`, that
 provides hash and rich comparison, as expected for unique instance
 behaviour.

 __Apply__

 - [attachment:trac14054_fast_methods.patch]

--

Comment (by SimonKing):

 The patch should now be ready for review.

 Two questions that I'd like to have addressed:

 1. I introduce `provide_hash_by_id`, but I don't use it. Shall it be
 deleted?
 2. Is it enough to override the rich comparison methods? Currently, one
 can have `hash(a)!=hash(b)` but `cmp(a,b)==0`. Does this violate the
 contract of hash functions? Or is it enough that `hash(a)!=hash(b)`
 implies `a!=b`?

 Pathbot:

 Apply trac14054_fast_methods.patch

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