summaryrefslogtreecommitdiff
path: root/math/py-annoy/files
diff options
context:
space:
mode:
authorYuri Victorovich <yuri@FreeBSD.org>2023-01-11 21:24:48 -0800
committerYuri Victorovich <yuri@FreeBSD.org>2023-01-11 21:25:23 -0800
commitc5c128b186be0150e2d4885d9dde759fc93b25c9 (patch)
treecf59959ddf6923cd98a71fde122f60eef9b033eb /math/py-annoy/files
parentmath/annoy: New port: Approximate Nearest Neighbors in C++ (diff)
math/py-annoy: New port: Approximate Nearest Neighbors in C++
Diffstat (limited to 'math/py-annoy/files')
-rw-r--r--math/py-annoy/files/patch-setup.py10
-rw-r--r--math/py-annoy/files/patch-src_annoymodule.cc11
-rw-r--r--math/py-annoy/files/test-load.py7
-rw-r--r--math/py-annoy/files/test-save.py12
4 files changed, 40 insertions, 0 deletions
diff --git a/math/py-annoy/files/patch-setup.py b/math/py-annoy/files/patch-setup.py
new file mode 100644
index 000000000000..f1bf9c98ae64
--- /dev/null
+++ b/math/py-annoy/files/patch-setup.py
@@ -0,0 +1,10 @@
+--- setup.py.orig 2023-01-12 05:20:26 UTC
++++ setup.py
+@@ -104,6 +104,6 @@ setup(name='annoy',
+ 'Programming Language :: Python :: 3.9',
+ ],
+ keywords='nns, approximate nearest neighbor search',
+- setup_requires=['nose>=1.0'],
++ setup_requires=[],
+ tests_require=['numpy', 'h5py']
+ )
diff --git a/math/py-annoy/files/patch-src_annoymodule.cc b/math/py-annoy/files/patch-src_annoymodule.cc
new file mode 100644
index 000000000000..6c0be8088fde
--- /dev/null
+++ b/math/py-annoy/files/patch-src_annoymodule.cc
@@ -0,0 +1,11 @@
+--- src/annoymodule.cc.orig 2023-01-12 04:57:07 UTC
++++ src/annoymodule.cc
+@@ -179,7 +179,7 @@ py_an_init(py_annoy *self, PyObject *args, PyObject *k
+ int f;
+ static char const * kwlist[] = {"f", "metric", NULL};
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|s", (char**)kwlist, &f, &metric))
+- return (int) NULL;
++ return 0;
+ return 0;
+ }
+
diff --git a/math/py-annoy/files/test-load.py b/math/py-annoy/files/test-load.py
new file mode 100644
index 000000000000..3eecbf6bb041
--- /dev/null
+++ b/math/py-annoy/files/test-load.py
@@ -0,0 +1,7 @@
+from annoy import AnnoyIndex
+
+f = 40 # Length of item vector that will be indexed
+
+u = AnnoyIndex(f, 'angular')
+u.load('test.ann') # super fast, will just mmap the file
+print(u.get_nns_by_item(0, 1000)) # will find the 1000 nearest neighbors
diff --git a/math/py-annoy/files/test-save.py b/math/py-annoy/files/test-save.py
new file mode 100644
index 000000000000..21a8f50df0c0
--- /dev/null
+++ b/math/py-annoy/files/test-save.py
@@ -0,0 +1,12 @@
+from annoy import AnnoyIndex
+import random
+
+f = 40 # Length of item vector that will be indexed
+
+t = AnnoyIndex(f, 'angular')
+for i in range(1000):
+ v = [random.gauss(0, 1) for z in range(f)]
+ t.add_item(i, v)
+
+t.build(10) # 10 trees
+t.save('test.ann')