summary refs log tree commit diff
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2019-03-28 23:50:33 +0100
committerRicardo Wurmus <rekado@elephly.net>2019-03-29 03:55:45 +0100
commit51a9971ccb631e56d67f2cf71c2d8defae73955c (patch)
tree8fec97e5ed06423887563579eae52843602508b9
parent3e4031877200b454a89263d6a51afe127738644b (diff)
downloadguix-51a9971ccb631e56d67f2cf71c2d8defae73955c.tar.gz
gnu: Add python-faiss.
* gnu/packages/graph.scm (python-faiss): New variable.
-rw-r--r--gnu/packages/graph.scm50
1 files changed, 50 insertions, 0 deletions
diff --git a/gnu/packages/graph.scm b/gnu/packages/graph.scm
index b3723d4069..2e8f7c1331 100644
--- a/gnu/packages/graph.scm
+++ b/gnu/packages/graph.scm
@@ -22,6 +22,7 @@
   #:use-module (guix download)
   #:use-module (guix git-download)
   #:use-module (guix packages)
+  #:use-module (guix utils)
   #:use-module (guix build-system cmake)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system python)
@@ -42,6 +43,7 @@
   #:use-module (gnu packages python-web)
   #:use-module (gnu packages python-xyz)
   #:use-module (gnu packages statistics)
+  #:use-module (gnu packages swig)
   #:use-module (gnu packages time)
   #:use-module (gnu packages xml))
 
@@ -322,3 +324,51 @@ 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.")
     (license license:bsd-3)))
+
+(define-public python-faiss
+  (package (inherit faiss)
+    (name "python-faiss")
+    (build-system python-build-system)
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'chdir
+           (lambda _ (chdir "python") #t))
+         (add-after 'chdir 'build-swig
+           (lambda* (#:key inputs #:allow-other-keys)
+             (with-output-to-file "../makefile.inc"
+               (lambda ()
+                 (let ((python-version ,(version-major+minor (package-version python))))
+                   (format #t "\
+PYTHONCFLAGS =-I~a/include/python~am/ -I~a/lib/python~a/site-packages/numpy/core/include
+LIBS = -lpython~am -lfaiss
+SHAREDFLAGS = -shared -fopenmp
+CXXFLAGS = -fpermissive -std=c++11 -fopenmp -fPIC
+CPUFLAGS = ~{~a ~}~%"
+                           (assoc-ref inputs "python*") python-version
+                           (assoc-ref inputs "python-numpy") python-version
+                           python-version
+                           (cons "-mpopcnt"
+                                 (list ,@(let ((system (or (%current-target-system)
+                                                           (%current-system))))
+                                           (cond
+                                            ((string-prefix? "x86_64" system)
+                                             '("-mavx" "-msse2"))
+                                            ((string-prefix? "i686" system)
+                                             '("-msse2"))
+                                            (else
+                                             '())))))))))
+             (substitute* "Makefile"
+               (("../libfaiss.a") ""))
+             (invoke "make" "cpu"))))))
+    (inputs
+     `(("faiss" ,faiss)
+       ("openblas" ,openblas)
+       ("python*" ,python)
+       ("swig" ,swig)))
+    (propagated-inputs
+     `(("python-matplotlib" ,python-matplotlib)
+       ("python-numpy" ,python-numpy)))
+    (description "Faiss is a library for efficient similarity search and
+clustering of dense vectors.  This package provides Python bindings to the
+Faiss library.")))