forked from Enet4/faiss
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw when attempting to move IndexPQ to GPU (facebookresearch#3328)
Summary: Pull Request resolved: facebookresearch#3328 Reviewed By: junjieqi Differential Revision: D55476917 fbshipit-source-id: e7f64adefa07650fda32ad2300a1b933cedc9c79
- Loading branch information
1 parent
4e6b6f8
commit 77e2e79
Showing
3 changed files
with
38 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import numpy as np | ||
import unittest | ||
import faiss | ||
|
||
|
||
class TestMoveToGpu(unittest.TestCase): | ||
def test_index_cpu_to_gpu(self): | ||
dimension = 128 | ||
n = 2500 | ||
db_vectors = np.random.random((n, dimension)).astype('float32') | ||
code_size = 16 | ||
res = faiss.StandardGpuResources() | ||
index_pq = faiss.IndexPQ(dimension, code_size, 6) | ||
index_pq.train(db_vectors) | ||
index_pq.add(db_vectors) | ||
self.assertRaisesRegex(Exception, ".*not implemented.*", | ||
faiss.index_cpu_to_gpu, res, 0, index_pq) | ||
|
||
def test_index_cpu_to_gpu_does_not_throw_with_index_flat(self): | ||
dimension = 128 | ||
n = 100 | ||
db_vectors = np.random.random((n, dimension)).astype('float32') | ||
res = faiss.StandardGpuResources() | ||
index_flat = faiss.IndexFlatL2(dimension) | ||
index_flat.add(db_vectors) | ||
try: | ||
faiss.index_cpu_to_gpu(res, 0, index_flat) | ||
except Exception: | ||
self.fail("index_cpu_to_gpu() threw an unexpected exception.") |
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