#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:
-----------------------------------------------+----------------------------
Comment (by nbruin):
Replying to [comment:12 SimonKing]:
> 1. I introduce `provide_hash_by_id`, but I don't use it. Shall it be
deleted?
Yes, you should. I'm pretty sure changing `type->tp_hash` after calling
`PyType_Ready()` is not supported by the Python C-API (see the inheritance
problems we saw).
> 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`?
I think Python requires `hash(a)!=hash(b)` implies `not(a==b)`, which
Python does not enforce to be the same thing. In any case, I'm pretty sure
that "rich comparison" is fully exhausted before trying to use `__cmp__`,
which is only there because of backward compatibility.
There's another peculiarity for membership and lookup in python:
{{{
sage: class neq(object):
....: def __eq__(self,other):
....: return False
....: def __ne__(self,other):
....: return True
....:
sage: a=neq()
sage: V={a}
sage: a in V
True
sage: sage: [a == v for v in V]
[False]
}}}
They explicitly mention this in the documentation: because hash collisions
are rare, they first test "is" for dict lookup before trying "==" (it's
cheaper).
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14054#comment:14>
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.