Skip to content

Commit

Permalink
fix numpy hash for bigendian
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasdiener committed Jan 16, 2025
1 parent 668b7fe commit 3046e99
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pytools/persistent_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ def rec(self, key_hash: Hash, key: Any) -> Hash:
# Non-numpy scalars are handled above in the try block.
method = self.update_for_numpy_scalar

# numpy arrays are mutable so they are not handled in KeyBuilder

if method is None:
if issubclass(tp, Enum):
method = self.update_for_enum
Expand Down Expand Up @@ -324,6 +326,8 @@ def update_for_specific_dtype(self, key_hash: Hash, key: Any) -> None:

def update_for_numpy_scalar(self, key_hash: Hash, key: Any) -> None:
import numpy as np
if sys.byteorder == "big":
key = key.byteswap()
if hasattr(np, "complex256") and key.dtype == np.dtype("complex256"):
key_hash.update(repr(complex(key)).encode("utf8"))
elif hasattr(np, "float128") and key.dtype == np.dtype("float128"):
Expand Down

0 comments on commit 3046e99

Please sign in to comment.