You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our custom memoize function is mapping inputs to their hashes, then those hashes are mapped to cached values, and, because the inputs and the hashes' original values aren't compared, a simple hash collision will cause memoize to return the wrong values.
Here's a simple example:
importpymc3aspmclassBad1:
def__hash__(self):
return329classBad2:
def__hash__(self):
return329b1=Bad1()
b2=Bad2()
# Here's what we expect:d= {}
d[b1] =1d[b2] =2asserthash(b1) ==hash(b2)
assertd[b1] !=d[b2]
# Because `memoize` doesn't use the inputs as keys in the `dict`-based# cache, we don't get the expected post-hash-lookup equality checks that# prevent errors when faced with hash collisions@pm.memoize.memoizedeftest_func(x):
returnxassertb1!=b2asserttest_func(b1) !=test_func(b2)
The last assert will currently fail, although it should be equivalent to the assert preceding it.
The text was updated successfully, but these errors were encountered:
Our custom
memoize
function is mapping inputs to their hashes, then those hashes are mapped to cached values, and, because the inputs and the hashes' original values aren't compared, a simple hash collision will causememoize
to return the wrong values.Here's a simple example:
The last
assert
will currently fail, although it should be equivalent to theassert
preceding it.The text was updated successfully, but these errors were encountered: