On Wed, Aug 28, 2013 at 7:29 AM, Prasoon Shukla
<[email protected]> wrote:
> I have ran into a caching problem while working on my project for the vector
> calcculus module. This occurred while I was debugging the express method on
> vector (this isn't really relevant though).
>
> So, I have a symbol theta and another symbol phi.
>
>>>> cs.theta
> cs.theta
>
>>>> cs.phi
> cs.phi
>
> cs is an instance of the CoordSysSph class (again, not really relevant to
> the problem at hand).

Can you reproduce this without using CoordSysSph, though? If not, then
it probably is relevant.

If you can, can you give complete code to reproduce it in master?

>
> The problem:
>>>> sin(cs.theta) * sin(cs.phi)
> sin(cs.theta) ** 2
>
> Well, in the definition for the cacheit decorator, the dicitionary
> func_cache_it_cache exists. Now, when sin(cs.theta) is called, a key, value
> pair gets added to the dictionary:
>
> ((sin, <class 'sympy.core.function.FunctionClass'>), (cs.theta, <class
> 'sympy.vector.vector.BaseScalar'>))  : sin(cs.theta)
>
> Now, when SymPy needs to calculate sin(cs.phi), the cacheit decorator is
> called again. The lookup key for sin(cs.phi) is generated as:
> ((sin, <class 'sympy.core.function.FunctionClass'>), (cs.phi, <class
> 'sympy.vector.vector.BaseScalar'>))
>
> At this point, the func_cache_it_cache does not have the key correspondind
> to sin(cs.phi), as it shouldn't. But, here's the catch: running the has_key
> method on func_cache_it_cache for this second key (for sin(cs.phi)) returns
> True. That means, the cache returns sin(cs.theta). And that is what is
> causing the problem.

has_key uses the hash (I believe) to check this, though it should fall
back to equality comparison on a collision. Did you override __hash__,
_hashable_content, or __eq__ anywhere?

Aaron Meurer

>
> What can I possibly do here? For the time being, I am going to proceed with
> the debugging. When there is a solution for this problem, we can go ahead
> and fix this.
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" 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/sympy.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" 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/sympy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to