math/py-annoy: New port: Approximate Nearest Neighbors in C++

This commit is contained in:
Yuri Victorovich 2023-01-11 21:24:48 -08:00
parent 99f1575aa1
commit c5c128b186
8 changed files with 85 additions and 0 deletions

View file

@ -867,6 +867,7 @@
SUBDIR += py-amply SUBDIR += py-amply
SUBDIR += py-animatplot SUBDIR += py-animatplot
SUBDIR += py-animatplot-ng SUBDIR += py-animatplot-ng
SUBDIR += py-annoy
SUBDIR += py-apgl SUBDIR += py-apgl
SUBDIR += py-arviz SUBDIR += py-arviz
SUBDIR += py-arybo SUBDIR += py-arybo

37
math/py-annoy/Makefile Normal file
View file

@ -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>

3
math/py-annoy/distinfo Normal file
View file

@ -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

View file

@ -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']
)

View file

@ -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;
}

View file

@ -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

View file

@ -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')

4
math/py-annoy/pkg-descr Normal file
View file

@ -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.