mirror of
https://github.com/facebookresearch/faiss.git
synced 2026-10-11 22:50:00 +00:00
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4745 Reduce test dataset size to use ~13 MB instead of ~1.5 GB while maintaining enough computational complexity to trigger the 10ms timeout before early stopping can converge. Reviewed By: bshethmeta Differential Revision: D90128255 fbshipit-source-id: 75b875d23ce459849d29acdb9d6de0828879ae46
33 lines
799 B
Python
33 lines
799 B
Python
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
#
|
|
# This source code is licensed under the MIT license found in the
|
|
# LICENSE file in the root directory of this source tree.
|
|
|
|
import unittest
|
|
import numpy as np
|
|
import faiss
|
|
|
|
|
|
class TestCallbackPy(unittest.TestCase):
|
|
def setUp(self) -> None:
|
|
super().setUp()
|
|
|
|
def test_timeout(self) -> None:
|
|
n = 20000
|
|
k = 5000
|
|
d = 128
|
|
niter = 1_000_000_000
|
|
|
|
x = np.random.rand(n, d).astype('float32')
|
|
index = faiss.IndexFlat(d)
|
|
|
|
cp = faiss.ClusteringParameters()
|
|
cp.niter = niter
|
|
cp.verbose = False
|
|
|
|
kmeans = faiss.Clustering(d, k, cp)
|
|
|
|
with self.assertRaises(RuntimeError):
|
|
with faiss.TimeoutGuard(0.010):
|
|
kmeans.train(x, index)
|