Skip to content

Commit

Permalink
Fix make_hashable
Browse files Browse the repository at this point in the history
  • Loading branch information
tilk committed Feb 10, 2025
1 parent cb42874 commit 7ca844b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions transactron/utils/data_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ def layout_subset(layout: StructLayout, *, fields: set[str]) -> StructLayout:


def make_hashable(val) -> Hashable:
if isinstance(val, Mapping):
return frozenset(((k, make_hashable(v)) for k, v in val.items()))
elif isinstance(val, Iterable):
return tuple(make_hashable(v) for v in val)
else:
try:
hash(val)
return val
except TypeError:
if isinstance(val, Mapping):
return frozenset(((k, make_hashable(v)) for k, v in val.items()))
elif isinstance(val, Iterable):
return tuple(make_hashable(v) for v in val)
else:
raise


def align_to_power_of_two(num: int, power: int) -> int:
Expand Down

0 comments on commit 7ca844b

Please sign in to comment.