Skip to content

Commit

Permalink
Fix: Generating 64-bit unsigned seeds
Browse files Browse the repository at this point in the history
The previous solution failed on Windows with:
> ValueError: high is out of bounds for int32
  • Loading branch information
ashvardanian committed Oct 29, 2024
1 parent 6f132bb commit 512c6aa
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion python/usearch/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,9 @@ def kmeans(
"""
metric = _normalize_metric(metric)
dtype = _normalize_dtype(dtype, ndim=X.shape[1], metric=metric)
seed = np.random.randint(0, 2**32 - 1) if seed is None else seed

# Generating a 64-bit unsigned integer in NumPy may be somewhat tricky.
seed = np.random.default_rng().integers(0, 2**64, dtype=np.uint64) if seed is None else seed
assignments, distances, centroids = _kmeans(
X,
k,
Expand Down

0 comments on commit 512c6aa

Please sign in to comment.