#12941: Cache should be cleared on cloning
----------------------------------------+-----------------------------------
Reporter: hivert | Owner: hivert
Type: defect | Status: new
Priority: major | Milestone: sage-5.1
Component: combinatorics | Resolution:
Keywords: Clone, cache, days38 | Work issues:
Report Upstream: N/A | Reviewers:
Authors: Florent Hivert | Merged in:
Dependencies: | Stopgaps:
----------------------------------------+-----------------------------------
Comment (by hivert):
Replying to [comment:1 mjo]:
> What cache? There are no cached methods in `ClonableIntArray`, so the
behavior within that class appears correct at first glance.
>
> Isn't the problem really that you're saying `sum()` is cacheable, when
in reality it isn't? At least under the inherited implementation of
`setitem()`.
>
> Since `Foo` is the class with the cached method, `Foo` should invalidate
the cache on `setitem()`.
In the previous code {{{f1}}} is supposed to be a mutable copy (clone) of
{{{f}}}. Therefore I think we should clear the cache during the
{{{__copy__}}}
method called by {{{clone}}}. Actually the same problem occur with
{{{Element}}}:
Using the following definition:
{{{
#!python
from sage.structure.element import Element
class Bar(Element):
def __init__(self, x):
self.x = x
Element.__init__(self, Parent())
@cached_method
def y(self):
return self.x
}}}
One gets
{{{
sage: b = Bar(4)
sage: b.y()
4
sage: c = copy(b)
sage: c.x = 25
sage: b.y()
4
sage: c.y()
4
}}}
I think that in {{{Element}}} method {{{__copy__}}} line 427 (sage 5.0rc0)
the
following line
{{{
try:
res.__dict__ = self.__dict__.copy()
except AttributeError:
pass
}}}
Should be fixed not to copy cached methods, with something as
{{{
dct = self.__dict__.copy()
for s in self.__dict__:
if isinstance(dct[s], (CachedFunction, CachedMethod)):
del dct[s]
res.__dict__ = dct
}}}
I'm CCing Simon King who designed the last version of cache. He may has
some
idea.
Cheers,
Florent
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12941#comment:3>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.