aboutsummaryrefslogtreecommitdiff
path: root/math/py-annoy
diff options
context:
space:
mode:
authorYuri Victorovich <yuri@FreeBSD.org>2023-01-12 05:24:48 +0000
committerYuri Victorovich <yuri@FreeBSD.org>2023-01-12 05:25:23 +0000
commitc5c128b186be0150e2d4885d9dde759fc93b25c9 (patch)
treecf59959ddf6923cd98a71fde122f60eef9b033eb /math/py-annoy
parent99f1575aa19c4f727561c8e8a6f858e8c681958d (diff)
downloadports-c5c128b186be0150e2d4885d9dde759fc93b25c9.tar.gz
ports-c5c128b186be0150e2d4885d9dde759fc93b25c9.zip
math/py-annoy: New port: Approximate Nearest Neighbors in C++
Diffstat (limited to 'math/py-annoy')
-rw-r--r--math/py-annoy/Makefile37
-rw-r--r--math/py-annoy/distinfo3
-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
-rw-r--r--math/py-annoy/pkg-descr4
7 files changed, 84 insertions, 0 deletions
diff --git a/math/py-annoy/Makefile b/math/py-annoy/Makefile
new file mode 100644
index 000000000000..f60de58fde88
--- /dev/null
+++ b/math/py-annoy/Makefile
@@ -0,0 +1,37 @@
+PORTNAME= annoy
+DISTVERSIONPREFIX= v
+DISTVERSION= 1.17.1
+CATEGORIES= math
+PKGNAMEPREFIX= ${PYTHON_PKGNAMEPREFIX}
+
+MAINTAINER= yuri@FreeBSD.org
+COMMENT= Approximate Nearest Neighbors in C++
+WWW= https://github.com/spotify/annoy
+
+LICENSE= APACHE20
+LICENSE_FILE= ${WRKSRC}/LICENSE
+
+TEST_DEPENDS= ${PYTHON_PKGNAMEPREFIX}h5py>0:science/py-h5py@${PY_FLAVOR} \
+ ${PYNUMPY}
+
+USES= python
+USE_PYTHON= distutils autoplist pytest # tests fail because nose is broken
+
+USE_GITHUB= yes
+GH_ACCOUNT= spotify
+
+TEST_ENV= ${MAKE_ENV} PYTHONPATH=${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}
+TEST_WRKSRC= ${WRKSRC}/test
+
+post-install:
+ @${STRIP_CMD} ${STAGEDIR}${PYTHON_SITELIBDIR}/annoy/annoylib${PYTHON_EXT_SUFFIX}.so
+
+do-test:
+ cd ${TEST_WRKSRC} && \
+ ${ECHO} "saving data" && \
+ ${SETENV} ${TEST_ENV} ${PYTHON_CMD} ${FILESDIR}/test-save.py && \
+ ${ECHO} "loading data" && \
+ ${SETENV} ${TEST_ENV} ${PYTHON_CMD} ${FILESDIR}/test-load.py && \
+ ${ECHO} "tests succeeded"
+
+.include <bsd.port.mk>
diff --git a/math/py-annoy/distinfo b/math/py-annoy/distinfo
new file mode 100644
index 000000000000..7820871881b9
--- /dev/null
+++ b/math/py-annoy/distinfo
@@ -0,0 +1,3 @@
+TIMESTAMP = 1673498821
+SHA256 (spotify-annoy-v1.17.1_GH0.tar.gz) = 4f7a2f2d86d45b432de68dba06667b23d0ce2b03595d64bd5c05f42dc32e7f4b
+SIZE (spotify-annoy-v1.17.1_GH0.tar.gz) = 674087
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')
diff --git a/math/py-annoy/pkg-descr b/math/py-annoy/pkg-descr
new file mode 100644
index 000000000000..8d40cf570d67
--- /dev/null
+++ b/math/py-annoy/pkg-descr
@@ -0,0 +1,4 @@
+Annoy (Approximate Nearest Neighbors Oh Yeah) is a C++ library with Python
+bindings to search for points in space that are close to a given query point.
+It also creates large read-only file-based data structures that are mmapped
+into memory so that many processes may share the same data.