Skip to content

Commit

Permalink
changing hash strategy to eliminate errors
Browse files Browse the repository at this point in the history
  • Loading branch information
m-rauen committed Dec 10, 2024
1 parent 1dfe929 commit 6870dab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions overreact/_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
import overreact as rx
from overreact import _constants as constants

def make_hashable(obj):
if isinstance(obj, np.ndarray):
return tuple(obj.ravel())
elif isinstance(obj, (list, set)):
return tuple(map(make_hashable, obj))
else:
return obj

def copy_unhashable(maxsize=128, typed=False):
"""Creates a copy of the arrays received by lru_cache and make them hashable, therefore maintaining the arrays to be passed and caching prototypes of those arrays.
Expand Down
2 changes: 1 addition & 1 deletion overreact/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,7 @@ def gyradius(atommasses, atomcoords, method="iupac"):
raise ValueError(msg)


@rx._misc.copy_unhashable
@rx._misc.copy_unhashable()
def inertia(atommasses, atomcoords, align=True):
r"""Calculate primary moments and axes from the inertia tensor.
Expand Down

0 comments on commit 6870dab

Please sign in to comment.