Skip to content

Commit

Permalink
Fixes #64. Added xxhash and now hashes the full data structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
perara committed Jan 7, 2024
1 parent 6537b94 commit 4940ac7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ dependencies = [
"pandas",
"scikit-learn",
"tqdm",
"requests"
"requests",
"xxhash"
]
requires-python = ">=3.10"

Expand Down
8 changes: 2 additions & 6 deletions tmu/util/encoded_data_cache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import hashlib
from typing import Optional

import xxhash
import numpy as np

class DataEncoderCache:
Expand All @@ -12,10 +11,7 @@ def __init__(self, seed: int):

def compute_hash(self, arr: np.ndarray) -> str:
"""Compute a hash for a numpy array."""

sampled_indices = self.rng.choice(arr.size, min(15, arr.size), replace=False)
sampled_values = arr.flat[sampled_indices]
return hashlib.sha256(sampled_values.tobytes()).hexdigest()
return xxhash.xxh3_64_hexdigest(arr)

def get_encoded_data(self, data: np.ndarray, encoder_func) -> np.ndarray:
"""Get encoded data for an array, using cache if available."""
Expand Down

0 comments on commit 4940ac7

Please sign in to comment.