#16316: cached_function and cached_method for unhashable elements
-------------------------------------+-------------------------------------
Reporter: saraedum | Owner:
Type: enhancement | Status: needs_review
Priority: minor | Milestone: sage-6.3
Component: misc | Resolution:
Keywords: | Merged in:
Authors: Julian Rueth | Reviewers: Peter Bruin
Report Upstream: N/A | Work issues:
Branch: | Commit:
u/pbruin/16316-cache_key | c0a7fb816bff291f99053b623bf07468190eb49c
Dependencies: #16251 | Stopgaps:
-------------------------------------+-------------------------------------
Comment (by tscrim):
It's about ''how'' we are implementing our caching, in that we require a
well-defined `__hash__()` method. The reason why we require elements to be
immutable is because the hash value often depends on the object's state
(ex, the elements in a list) in order to find the object in the cache.
Formally all we need is a function to the integers to do caching in order
to find out where in the cache an element should go. Our current
implementations of caching requires the object to have this function
called `__hash__()`. So all we require is objects to never change their
key, so generally the objects can still be mutable.
As for `@cached_function`, the input is the key and the output is the
value of the cache, and the ''input'' needs to be hashable because of this
(as the ticket description demonstrates). What this ticket does is create
an intermediate function from our input to an object which does have a
well-defined hash to create the key for the cache. Okay, perhaps I'm
overreaching in saying that it is incorrect, but it is misleading. I'm
just asking for a more detailed explanation for the doctests.
Actually...why not just implement a custom `__hash__` function for the
required elements? This seems like overkill and a custom `__hash__` would
also allow you to use this as a key for dictionaries, sets,
`UniqueRepresentation`, etc.
--
Ticket URL: <http://trac.sagemath.org/ticket/16316#comment:18>
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/d/optout.