summaryrefslogtreecommitdiff
path: root/math/py-faiss/files/test.py
diff options
context:
space:
mode:
authorYuri Victorovich <yuri@FreeBSD.org>2022-01-15 02:31:21 -0800
committerYuri Victorovich <yuri@FreeBSD.org>2022-01-15 02:32:16 -0800
commit01c541ffecc47b79f4a1ec161645cad3138c8e37 (patch)
treed11e2cf49b6c8d0fe3a32f7c0a0e265044450a83 /math/py-faiss/files/test.py
parentmath/faiss: Update 1.7.1 -> 1.7.2 (diff)
math/py-faiss: New port: Library for efficient similarity search & clustering of dense vectors
Diffstat (limited to 'math/py-faiss/files/test.py')
-rw-r--r--math/py-faiss/files/test.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/math/py-faiss/files/test.py b/math/py-faiss/files/test.py
new file mode 100644
index 000000000000..f1395cf46a3e
--- /dev/null
+++ b/math/py-faiss/files/test.py
@@ -0,0 +1,16 @@
+import numpy as np
+d = 64 # dimension
+nb = 100000 # database size
+nq = 10000 # nb of queries
+np.random.seed(1234) # make reproducible
+xb = np.random.random((nb, d)).astype('float32')
+xb[:, 0] += np.arange(nb) / 1000.
+xq = np.random.random((nq, d)).astype('float32')
+xq[:, 0] += np.arange(nq) / 1000.
+
+
+import faiss # make faiss available
+index = faiss.IndexFlatL2(d) # build the index
+print(index.is_trained)
+index.add(xb) # add vectors to the index
+print(index.ntotal)