Skip to content

Commit

Permalink
Fix sympy/sympy#9326: use full symbol in evalf cache, not just symbol…
Browse files Browse the repository at this point in the history
… name

Old status: evalf_symbol used just the symbol name in its cache, this
would break if two symbols happened to use the same name.
This fix uses the full symbol instead.

// edited by skirpichev
  • Loading branch information
toolforger authored and skirpichev committed Sep 13, 2015
1 parent 6aeccf0 commit db67b00
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sympy/core/evalf.py
Expand Up @@ -1175,11 +1175,11 @@ def evalf_symbol(x, prec, options):
if '_cache' not in options:
options['_cache'] = {}
cache = options['_cache']
cached, cached_prec = cache.get(x.name, (None, MINUS_INF))
cached, cached_prec = cache.get(x, (None, MINUS_INF))
if cached_prec >= prec:
return cached
v = evalf(sympify(val), prec, options)
cache[x.name] = (v, prec)
cache[x] = (v, prec)
return v

evalf_table = None
Expand Down
8 changes: 8 additions & 0 deletions sympy/core/tests/test_evalf.py
Expand Up @@ -475,3 +475,11 @@ def test_issue_8853():
assert get_integer_part(S.Half, 1, {}, True) == (1, 0)
assert get_integer_part(-S.Half, -1, {}, True) == (-1, 0)
assert get_integer_part(-S.Half, 1, {}, True) == (0, 0)


def test_issue_9326():
from sympy import Dummy
d1 = Dummy('d')
d2 = Dummy('d')
e = d1 + d2
assert e.evalf(subs = {d1: 1, d2: 2}) == 3

0 comments on commit db67b00

Please sign in to comment.