#16353: A cached_function with selective memory
-------------------------+-------------------------------------------------
Reporter: | Owner:
ncohen | Status: needs_review
Type: | Milestone: sage-6.3
enhancement | Resolution:
Priority: major | Merged in:
Component: | Reviewers:
performance | Work issues:
Keywords: | Commit:
Authors: | 7eb8f900f1a143c6cc85b9382a365b57a9c42ecc
Nathann Cohen | Stopgaps:
Report Upstream: N/A |
Branch: |
u/ncohen/16353 |
Dependencies: |
-------------------------+-------------------------------------------------
Comment (by nbruin):
Replying to [comment:35 ncohen]:
> Just adding something : unless this ticket is reviewed I will have to
implement the caching method manually in 4 different functions.
>
> I also forgot to add another reason for having a function like that :
>
> A cached function cannot (safely) return mutable answers. If you return
a list and that the user modifies the list, then it also modifies the list
stored in the function's cache.
You are right in noting that. You could of course document that the result
returned shouldn't be modified (but instead copied if modification is
needed), and that is probably the most efficient solution for an internal
routine, where the caller can then make a copy only when necessary. And
indeed, you can enforce (one level at the time) by using tuples.
If you want an always-safe-to-mutate result, you would always need to
*copy* into cache (or copy the result once it's written into the cache),
which is not what is proposed on this ticket. In fact, copying is a
complicated, data type dependent operation (think tuple of lists, for
instance -- how deep do you have to go with copying?)
It seems to me that this additional motivation for using the decorator
provides another argument *against* the utility and wisdom of the proposed
decorator for producing clear, readable, and maintainable code.
--
Ticket URL: <http://trac.sagemath.org/ticket/16353#comment:36>
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.