-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: #3351 Differential Revision: D57120422
- Loading branch information
1 parent
0cc0e19
commit 090044d
Showing
8 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <faiss/Clustering.h> | ||
#include <faiss/IndexFlat.h> | ||
#include <faiss/impl/AuxIndexStructures.h> | ||
#include <faiss/impl/FaissException.h> | ||
#include <faiss/utils/random.h> | ||
|
||
TEST(TestCallback, timeout) { | ||
int n = 1000; | ||
int k = 100; | ||
int d = 128; | ||
int niter = 1000000000; | ||
int seed = 42; | ||
|
||
std::vector<float> vecs(n * d); | ||
faiss::float_rand(vecs.data(), vecs.size(), seed); | ||
|
||
auto index(new faiss::IndexFlat(d)); | ||
|
||
faiss::ClusteringParameters cp; | ||
cp.niter = niter; | ||
cp.verbose = false; | ||
|
||
faiss::Clustering kmeans(d, k, cp); | ||
|
||
faiss::TimeoutCallback::reset(0.010); | ||
EXPECT_THROW(kmeans.train(n, vecs.data(), *index), faiss::FaissException); | ||
delete index; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# 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 = 1000 | ||
k = 100 | ||
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) |