Skip to content
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

Ensure hash(Key(…)) is independent of dim order #159

Closed
khaeru opened this issue Feb 12, 2025 · 0 comments · Fixed by #157
Closed

Ensure hash(Key(…)) is independent of dim order #159

khaeru opened this issue Feb 12, 2025 · 0 comments · Fixed by #157
Assignees
Labels
enh New feature or request

Comments

@khaeru
Copy link
Owner

khaeru commented Feb 12, 2025

With:

from genno import Computer, Key

# Two keys with same dimensions but different order
k1 = Key("foo", "abc")
k2 = Key("foo", "cba")

d = {k1:"bar"}
k1 in d  # True
k2 in d  # False

This is because:

hash(k1) != hash(k2)  # 5471437777101518998 != 2185684392273789077

Although the following do work:

c = Computer()
c.add(k1, None)

k2 in c  # True
k2 in c.graph  # True

To resolve: make Key.__hash__() independent of dimension order.

@khaeru khaeru added the enh New feature or request label Feb 12, 2025
@khaeru khaeru self-assigned this Feb 12, 2025
@khaeru khaeru linked a pull request Feb 13, 2025 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enh New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant