git: 01c541ffecc4 - main - math/py-faiss: New port: Library for efficient similarity search & clustering of dense vectors

From: Yuri Victorovich <yuri_at_FreeBSD.org>
Date: Sat, 15 Jan 2022 10:32:19 UTC
The branch main has been updated by yuri:

URL: https://cgit.FreeBSD.org/ports/commit/?id=01c541ffecc47b79f4a1ec161645cad3138c8e37

commit 01c541ffecc47b79f4a1ec161645cad3138c8e37
Author:     Yuri Victorovich <yuri@FreeBSD.org>
AuthorDate: 2022-01-15 10:31:21 +0000
Commit:     Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2022-01-15 10:32:16 +0000

    math/py-faiss: New port: Library for efficient similarity search & clustering of dense vectors
---
 math/Makefile               |  1 +
 math/py-faiss/Makefile      | 42 ++++++++++++++++++++++++++++++++++++++++++
 math/py-faiss/distinfo      |  3 +++
 math/py-faiss/files/test.py | 16 ++++++++++++++++
 math/py-faiss/pkg-descr     |  8 ++++++++
 5 files changed, 70 insertions(+)

diff --git a/math/Makefile b/math/Makefile
index b7abeb8381c9..e9a903e9519d 100644
--- a/math/Makefile
+++ b/math/Makefile
@@ -827,6 +827,7 @@
     SUBDIR += py-deap
     SUBDIR += py-ducc0
     SUBDIR += py-ecos
+    SUBDIR += py-faiss
     SUBDIR += py-fastcluster
     SUBDIR += py-fastdtw
     SUBDIR += py-flax
diff --git a/math/py-faiss/Makefile b/math/py-faiss/Makefile
new file mode 100644
index 000000000000..ef4d64d0daef
--- /dev/null
+++ b/math/py-faiss/Makefile
@@ -0,0 +1,42 @@
+PORTNAME=	faiss
+DISTVERSIONPREFIX=	v
+DISTVERSION=	1.7.2
+CATEGORIES=	math
+PKGNAMEPREFIX=	${PYTHON_PKGNAMEPREFIX}
+
+MAINTAINER=	yuri@FreeBSD.org
+COMMENT=	Library for efficient similarity search & clustering of dense vectors
+
+LICENSE=	MIT
+LICENSE_FILE=	${WRKSRC}/../../LICENSE
+
+PY_DEPENDS=	${PYNUMPY}
+BUILD_DEPENDS=	swig:devel/swig \
+		${PY_DEPENDS}
+LIB_DEPENDS=	libfaiss.so:math/faiss
+RUN_DEPENDS=	${PY_DEPENDS}
+
+USES=		cmake compiler:c++11-lang localbase python
+
+USE_GITHUB=	yes
+GH_ACCOUNT=	facebookresearch
+
+WRKSRC_SUBDIR=	faiss/python
+
+PLIST_FILES=	\
+		${PYTHON_SITELIBDIR}/${PORTNAME}/_swigfaiss.so \
+		${PYTHON_SITELIBDIR}/${PORTNAME}/__init__.py \
+		${PYTHON_SITELIBDIR}/${PORTNAME}/loader.py \
+		${PYTHON_SITELIBDIR}/${PORTNAME}/swigfaiss.py
+
+do-install: # see https://github.com/facebookresearch/faiss/issues/2194
+	${MKDIR} ${STAGEDIR}${PYTHON_SITELIBDIR}/${PORTNAME}
+	${INSTALL_LIB} ${BUILD_WRKSRC}/_swigfaiss.so ${STAGEDIR}${PYTHON_SITELIBDIR}/${PORTNAME}
+.for f in __init__.py loader.py swigfaiss.py
+	${INSTALL_DATA} ${BUILD_WRKSRC}/${f} ${STAGEDIR}${PYTHON_SITELIBDIR}/${PORTNAME}
+.endfor
+
+do-test: install
+	@${PYTHON_CMD} ${FILESDIR}/test.py
+
+.include <bsd.port.mk>
diff --git a/math/py-faiss/distinfo b/math/py-faiss/distinfo
new file mode 100644
index 000000000000..692e7da7cd70
--- /dev/null
+++ b/math/py-faiss/distinfo
@@ -0,0 +1,3 @@
+TIMESTAMP = 1642235176
+SHA256 (facebookresearch-faiss-v1.7.2_GH0.tar.gz) = d49b4afd6a7a5b64f260a236ee9b2efb760edb08c33d5ea5610c2f078a5995ec
+SIZE (facebookresearch-faiss-v1.7.2_GH0.tar.gz) = 740431
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)
diff --git a/math/py-faiss/pkg-descr b/math/py-faiss/pkg-descr
new file mode 100644
index 000000000000..a482a49936a3
--- /dev/null
+++ b/math/py-faiss/pkg-descr
@@ -0,0 +1,8 @@
+Python binding for Faiss.
+
+Faiss is a library for efficient similarity search and clustering of dense
+vectors. It contains algorithms that search in sets of vectors of any size,
+up to ones that possibly do not fit in RAM. It also contains supporting code
+for evaluation and parameter tuning.
+
+WWW: https://github.com/facebookresearch/faiss