-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Must not use Pybind's implicit object-identity __hash__
#102
Comments
Does |
FWIW, isl_set_get_hash returns deterministic results as its seed is a constant. |
But then something's weird. uint32_t set_get_hash(set const &arg_self)
{
isl_ctx *islpy_ctx = nullptr;
if (!arg_self.is_valid())
throw isl::error(
"passed invalid arg to isl_set_get_hash for self");
islpy_ctx = isl_set_get_ctx(arg_self.m_data);
if (islpy_ctx) isl_ctx_reset_error(islpy_ctx);
uint32_t result = isl_set_get_hash(arg_self.m_data);
return result;
} and wrap_set.def("__hash__", isl::set_get_hash, "get_hash(self)\n\n:param self: :class:`Set`\n:return: uint32_t \n\n.. warning::\n\n This function is not part of the officially public isl API. Use at your own risk."); |
Aah I see. |
Using (py311_env) [line@line temp]$ cat understand_bset_hash.py
import islpy as isl
a1 = isl.BasicSet("{[i]: 0<=i<512}")
a2 = isl.BasicSet("{[i]: 0<=i<512}")
print(hash(a1))
print(hash(a2))
print(a1 == a2)
print({a1: "hello", a2: "world"})
(py311_env) [line@line temp]$ python understand_bset_hash.py
8766500567951
8766500487043
True
{BasicSet("{ [i] : 0 <= i <= 511 }"): 'hello', BasicSet("{ [i] : 0 <= i <= 511 }"): 'world'} I wonder if we should use the upcasting logic for such types for which ISL does not define isl_xxx_get_hash. |
__hash__
of ISLPy objects does not respect PYTHONHASHSEED
__hash__
See #103 for a first stab. I'm excited for all the ways in which this breaks loopy. 🙂 |
Not sure if this is useful, but while looking at this issue, I noticed that isl does offer Manually adding it to the header and rebuilding islpy seems to make the two examples in this PR run as expected: $ PYTHONHASHSEED=3 python islpy_hash.py
-2348628950087003433
1863046788
1863046788
$ PYTHONHASHSEED=3 python islpy_hash.py
-2348628950087003433
1863046788
1863046788
$ PYTHONHASHSEED=3 python islpy_hash.py
-2348628950087003433
1863046788
1863046788
$ PYTHONHASHSEED=3 python understand_bset_hash.py
181834274
181834274
True
{BasicSet("{ [i] : 0 <= i <= 511 }"): 'world'}
$ PYTHONHASHSEED=3 python understand_bset_hash.py
181834274
181834274
True
{BasicSet("{ [i] : 0 <= i <= 511 }"): 'world'}
$ PYTHONHASHSEED=3 python understand_bset_hash.py
181834274
181834274
True
{BasicSet("{ [i] : 0 <= i <= 511 }"): 'world'} |
To Reproduce
PYTHONHASHSEED=3 python islpy_hash.py
.Observed behavior
Expected behavior
The message printed to stdout must be the same across interpreter runs.
The text was updated successfully, but these errors were encountered: