On Thursday, June 12, 2014 7:05:12 PM UTC-7, Nils Bruin wrote:
>
> And since the arguments get processed already in order to get hashed, it 
> would probably be quite doable to process them such that SageElement 
> instances get replaced by (elt.parent(), elt), or perhaps better: if 
> objects 
> provide a "_cache_key_" method, use its value. 
>

On second thought, doing this would come at significant cost.

I was thinking about ArgumentFixer here, but that doesn't normally 
*recurse* along the arguments (it only reorders arguments between named and 
positional arguments, based on the function signature--one reason why 
cached functions should only be defined in module or class scopes: 
producing cached closures would involve running ArgumentFixer any time a 
closure is produced.  This is going to be horribly expensive, because 
sage_getargspec will probably end up retrieving the source of the wrapped 
function. It's also unnecessary, because the closure that gets wrapped 
wouldn't normally change its signature at runtime anyway.

Of course, we can make a version of ArgumentFixer that does walk its 
arguments, recursing through tuples and replacing entries v by 
v._cache_key_(), if that method is available, but doing that will be quite 
costly (although probably comparable in cost to the computation of the hash 
value for lookup in the cache and the comparison should a hit be found in 
the cache). In practice, interesting cached functions will have fairly 
simple inputs and outputs but an expensive computation process in between, 
so the cost may well be manageable.

This is also where we see that FiniteEnumeratedSet is horrible for caching: 
its computation is totally trivial. All the complexity is in its arguments 
(which, modulo trivial wrapping, is also the result). UniqueRepresentation 
is clearly a poor fit for it. You should only use it if you absolutely must 
shoehorn the concept of a finite set into the coercion framework (it's the 
coercion framework for which the "unique parent" rule is important).

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to