1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015, 2016, 2017, 2018, 2019 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
4 ;;; Copyright © 2016, 2017 Marius Bakke <mbakke@fastmail.com>
5 ;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com>
6 ;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
7 ;;; Copyright © 2018 Kei Kebreau <kkebreau@posteo.net>
8 ;;; Copyright © 2018 Mark Meyer <mark@ofosos.org>
9 ;;; Copyright © 2018 Ben Woodcroft <donttrustben@gmail.com>
10 ;;; Copyright © 2018 Fis Trivial <ybbs.daans@hotmail.com>
11 ;;; Copyright © 2018 Julien Lepiller <julien@lepiller.eu>
12 ;;; Copyright © 2018 Björn Höfling <bjoern.hoefling@bjoernhoefling.de>
14 ;;; This file is part of GNU Guix.
16 ;;; GNU Guix is free software; you can redistribute it and/or modify it
17 ;;; under the terms of the GNU General Public License as published by
18 ;;; the Free Software Foundation; either version 3 of the License, or (at
19 ;;; your option) any later version.
21 ;;; GNU Guix is distributed in the hope that it will be useful, but
22 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;;; GNU General Public License for more details.
26 ;;; You should have received a copy of the GNU General Public License
27 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
29 (define-module (gnu packages machine-learning)
30 #:use-module ((guix licenses) #:prefix license:)
31 #:use-module (guix packages)
32 #:use-module (guix utils)
33 #:use-module (guix download)
34 #:use-module (guix svn-download)
35 #:use-module (guix build-system cmake)
36 #:use-module (guix build-system gnu)
37 #:use-module (guix build-system ocaml)
38 #:use-module (guix build-system python)
39 #:use-module (guix build-system r)
40 #:use-module (guix git-download)
41 #:use-module (gnu packages)
42 #:use-module (gnu packages adns)
43 #:use-module (gnu packages algebra)
44 #:use-module (gnu packages audio)
45 #:use-module (gnu packages autotools)
46 #:use-module (gnu packages base)
47 #:use-module (gnu packages bash)
48 #:use-module (gnu packages boost)
49 #:use-module (gnu packages check)
50 #:use-module (gnu packages compression)
51 #:use-module (gnu packages cran)
52 #:use-module (gnu packages databases)
53 #:use-module (gnu packages dejagnu)
54 #:use-module (gnu packages gcc)
55 #:use-module (gnu packages glib)
56 #:use-module (gnu packages gstreamer)
57 #:use-module (gnu packages image)
58 #:use-module (gnu packages linux)
59 #:use-module (gnu packages maths)
60 #:use-module (gnu packages mpi)
61 #:use-module (gnu packages ocaml)
62 #:use-module (gnu packages onc-rpc)
63 #:use-module (gnu packages perl)
64 #:use-module (gnu packages pkg-config)
65 #:use-module (gnu packages protobuf)
66 #:use-module (gnu packages python)
67 #:use-module (gnu packages python-web)
68 #:use-module (gnu packages python-xyz)
69 #:use-module (gnu packages serialization)
70 #:use-module (gnu packages statistics)
71 #:use-module (gnu packages sqlite)
72 #:use-module (gnu packages swig)
73 #:use-module (gnu packages tls)
74 #:use-module (gnu packages web)
75 #:use-module (gnu packages xml)
76 #:use-module (gnu packages xorg)
77 #:use-module (ice-9 match))
80 ;; The last release is >100 commits behind, so we package from git.
81 (let ((commit "d71d54788bee56ba4cf7522801270152da5209d7"))
84 (version (string-append "2.2.0-1." (string-take commit 8)))
88 (url "https://github.com/libfann/fann.git")
90 (file-name (string-append name "-" version "-checkout"))
93 "0ibwpfrjs6q2lijs8slxjgzb2llcl6rk3v2ski4r6215g5jjhg3x"))))
94 (build-system cmake-build-system)
97 (modify-phases %standard-phases
99 (lambda* (#:key outputs #:allow-other-keys)
100 (let* ((out (assoc-ref outputs "out")))
101 (with-directory-excursion (string-append (getcwd) "/tests")
102 (invoke "./fann_tests"))))))))
103 (home-page "http://leenissen.dk/fann/wp/")
104 (synopsis "Fast Artificial Neural Network")
106 "FANN is a free open source neural network library, which implements
107 multilayer artificial neural networks in C with support for both fully
108 connected and sparsely connected networks.")
109 (license license:lgpl2.1))))
111 (define-public libsvm
118 (uri (string-append "https://www.csie.ntu.edu.tw/~cjlin/libsvm/"
119 name "-" version ".tar.gz"))
121 (base32 "0jpaq0rr92x38p4nk3gjan79ip67m6p80anb28z1d8601miysyi5"))))
122 (build-system gnu-build-system)
124 `(#:tests? #f ; no "check" target
125 #:phases (modify-phases %standard-phases
128 'install ; no ‘install’ target
129 (lambda* (#:key outputs #:allow-other-keys)
130 (let* ((out (assoc-ref outputs "out"))
131 (bin (string-append out "/bin/")))
133 (for-each (lambda (file)
134 (copy-file file (string-append bin file)))
139 (home-page "http://www.csie.ntu.edu.tw/~cjlin/libsvm/")
140 (synopsis "Library for Support Vector Machines")
142 "LIBSVM is a machine learning library for support vector
143 classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and
144 distribution estimation (one-class SVM). It supports multi-class
146 (license license:bsd-3)))
148 (define-public python-libsvm
149 (package (inherit libsvm)
150 (name "python-libsvm")
151 (build-system gnu-build-system)
153 `(#:tests? #f ; no "check" target
154 #:make-flags '("-C" "python")
156 (modify-phases %standard-phases
159 'install ; no ‘install’ target
160 (lambda* (#:key inputs outputs #:allow-other-keys)
161 (let ((site (string-append (assoc-ref outputs "out")
165 (assoc-ref inputs "python") 5) 3)
167 (substitute* "python/svm.py"
168 (("../libsvm.so.2") "libsvm.so.2"))
170 (for-each (lambda (file)
171 (copy-file file (string-append site (basename file))))
172 (find-files "python" "\\.py"))
173 (copy-file "libsvm.so.2"
174 (string-append site "libsvm.so.2")))
177 `(("python" ,python)))
178 (synopsis "Python bindings of libSVM")))
181 ;; The latest release candidate is several years and a couple of fixes have
182 ;; been published since. This is why we download the sources from the SVN
184 (let ((svn-revision 2341))
187 (version (string-append "0.9-rc3-0." (number->string svn-revision)))
191 (url "http://svn.code.sf.net/p/ghmm/code/trunk")
192 (revision svn-revision)))
193 (file-name (string-append name "-" version))
196 "0qbq1rqp94l530f043qzp8aw5lj7dng9wq0miffd7spd1ff638wq"))))
197 (build-system gnu-build-system)
199 `(#:imported-modules (,@%gnu-build-system-modules
200 (guix build python-build-system))
202 (modify-phases %standard-phases
203 (add-after 'unpack 'enter-dir
204 (lambda _ (chdir "ghmm") #t))
206 (add-after 'install 'check
207 (assoc-ref %standard-phases 'check))
208 (add-before 'check 'fix-PYTHONPATH
209 (lambda* (#:key inputs outputs #:allow-other-keys)
210 (let ((python-version ((@@ (guix build python-build-system)
212 (assoc-ref inputs "python"))))
214 (string-append (getenv "PYTHONPATH")
215 ":" (assoc-ref outputs "out")
216 "/lib/python" python-version
219 (add-after 'enter-dir 'fix-runpath
220 (lambda* (#:key outputs #:allow-other-keys)
221 (substitute* "ghmmwrapper/setup.py"
222 (("^(.*)extra_compile_args = \\[" line indent)
223 (string-append indent
224 "extra_link_args = [\"-Wl,-rpath="
225 (assoc-ref outputs "out") "/lib\"],\n"
228 (assoc-ref outputs "out")
231 (add-after 'enter-dir 'disable-broken-tests
233 (substitute* "tests/Makefile.am"
234 ;; GHMM_SILENT_TESTS is assumed to be a command.
235 (("TESTS_ENVIRONMENT.*") "")
236 ;; Do not build broken tests.
240 (("label_higher_order_test.*$")
241 "label_higher_order_test\n"))
243 ;; These Python unittests are broken as there is no gato.
244 ;; See https://sourceforge.net/p/ghmm/support-requests/3/
245 (substitute* "ghmmwrapper/ghmmunittests.py"
246 (("^(.*)def (testNewXML|testMultipleTransitionClasses|testNewXML)"
248 (string-append indent
249 "@unittest.skip(\"Disabled by Guix\")\n"
252 (add-after 'disable-broken-tests 'autogen
254 (invoke "bash" "autogen.sh"))))))
256 `(("python" ,python-2) ; only Python 2 is supported
257 ("libxml2" ,libxml2)))
259 `(("pkg-config" ,pkg-config)
262 ("autoconf" ,autoconf)
263 ("automake" ,automake)
264 ("libtool" ,libtool)))
265 (home-page "http://ghmm.org")
266 (synopsis "Hidden Markov Model library")
268 "The General Hidden Markov Model library (GHMM) is a C library with
269 additional Python bindings implementing a wide range of types of @dfn{Hidden
270 Markov Models} (HMM) and algorithms: discrete, continuous emissions, basic
271 training, HMM clustering, HMM mixtures.")
272 (license license:lgpl2.0+))))
281 "http://micans.org/mcl/src/mcl-"
282 (string-replace-substring version "." "-")
286 "15xlax3z31lsn62vlg94hkm75nm40q4679amnfg13jm8m2bnhy5m"))))
287 (build-system gnu-build-system)
289 `(#:configure-flags (list "--enable-blast")))
292 (home-page "http://micans.org/mcl/")
293 (synopsis "Clustering algorithm for graphs")
295 "The MCL algorithm is short for the @dfn{Markov Cluster Algorithm}, a
296 fast and scalable unsupervised cluster algorithm for graphs (also known as
297 networks) based on simulation of (stochastic) flow in graphs.")
298 ;; In the LICENCE file and web page it says "The software is licensed
299 ;; under the GNU General Public License, version 3.", but in several of
300 ;; the source code files it suggests GPL3 or later.
301 ;; http://listserver.ebi.ac.uk/pipermail/mcl-users/2016/000376.html
302 (license license:gpl3)))
304 (define-public ocaml-mcl
307 (version "12-068oasis4")
312 (url "https://github.com/fhcrc/mcl.git")
314 (file-name (git-file-name name version))
317 "0009dc3h2jp3qg5val452wngpqnbfyhbcxylghq0mrjqxx0jdq5p"))))
318 (build-system ocaml-build-system)
321 (modify-phases %standard-phases
322 (add-before 'configure 'patch-paths
324 (substitute* "configure"
325 (("/bin/sh") (which "sh")))
326 (substitute* "setup.ml"
328 (string-append "LDFLAGS=-fPIC\"; \"SHELL=" (which "sh")))
329 (("-std=c89") "-std=gnu99")
331 ;; This is a mutable string, which is no longer supported. Use
332 ;; a byte buffer instead.
333 (("String.make \\(String.length s\\)")
334 "Bytes.make (String.length s)")
336 ;; These two belong together.
337 (("OASISString.replace_chars")
338 "Bytes.to_string (OASISString.replace_chars")
341 (substitute* "myocamlbuild.ml"
342 (("std=c89") "std=gnu99"))
343 ;; Since we build with a more recent OCaml, we have to use C99 or
344 ;; later. This causes problems with the old C code.
345 (substitute* "src/impala/matrix.c"
346 (("restrict") "restrict_"))
349 `(("ocamlbuild" ,ocamlbuild)))
350 (home-page "https://github.com/fhcrc/mcl")
351 (synopsis "OCaml wrappers around MCL")
353 "This package provides OCaml bindings for the MCL graph clustering
355 (license license:gpl3)))
357 (define-public randomjungle
359 (name "randomjungle")
365 "https://www.imbs.uni-luebeck.de/fileadmin/files/Software"
366 "/randomjungle/randomjungle-" version ".tar_.gz"))
367 (patches (search-patches "randomjungle-disable-static-build.patch"))
370 "12c8rf30cla71swx2mf4ww9mfd8jbdw5lnxd7dxhyw1ygrvg6y4w"))))
371 (build-system gnu-build-system)
374 (list "--disable-static"
375 (string-append "--with-boost="
376 (assoc-ref %build-inputs "boost")))
378 (modify-phases %standard-phases
380 'configure 'set-CXXFLAGS
382 (setenv "CXXFLAGS" "-fpermissive ")
390 `(("gfortran" ,gfortran)
391 ("gfortran:lib" ,gfortran "lib")))
392 ;; Non-portable assembly instructions are used so building fails on
393 ;; platforms other than x86_64 or i686.
394 (supported-systems '("x86_64-linux" "i686-linux"))
395 (home-page "https://www.imbs.uni-luebeck.de/forschung/software/details.html#c224")
396 (synopsis "Implementation of the Random Forests machine learning method")
398 "Random Jungle is an implementation of Random Forests. It is supposed to
399 analyse high dimensional data. In genetics, it can be used for analysing big
400 Genome Wide Association (GWA) data. Random Forests is a powerful machine
401 learning method. Most interesting features are variable selection, missing
402 value imputation, classifier creation, generalization error estimation and
403 sample proximities between pairs of cases.")
404 (license license:gpl3+)))
406 (define-public openfst
412 (uri (string-append "http://www.openfst.org/twiki/pub/FST/"
413 "FstDownload/openfst-" version ".tar.gz"))
416 "0fqgk8195kz21is09gwzwnrg7fr9526bi9mh4apyskapz27pbhr1"))))
417 (build-system gnu-build-system)
418 (home-page "http://www.openfst.org")
419 (synopsis "Library for weighted finite-state transducers")
420 (description "OpenFst is a library for constructing, combining,
421 optimizing, and searching weighted finite-state transducers (FSTs).")
422 (license license:asl2.0)))
424 (define-public shogun
432 "ftp://shogun-toolbox.org/shogun/releases/"
433 (version-major+minor version)
434 "/sources/shogun-" version ".tar.bz2"))
437 "1rn9skm3nw6hr7mr3lgp2gfqhi7ii0lyxck7qmqnf8avq349s5jp"))
438 (modules '((guix build utils)
442 ;; Remove non-free sources and files referencing them
443 (for-each delete-file
444 (find-files "src/shogun/classifier/svm/"
445 "SVMLight\\.(cpp|h)"))
446 (for-each delete-file
447 (find-files "examples/undocumented/libshogun/"
449 "(classifier_.*svmlight.*|"
450 "evaluation_cross_validation_locked_comparison).cpp")))
451 ;; Remove non-free functions.
452 (define (delete-ifdefs file)
453 (with-atomic-file-replacement file
455 (let loop ((line (read-line in 'concat))
457 (if (eof-object? line)
462 "#endif //USE_SVMLIGHT" line)))
464 "#ifdef USE_SVMLIGHT" line))))
465 (when (or (not skipping?)
466 (and skipping? (not skip-next?)))
468 (loop (read-line in 'concat) skip-next?)))))))
469 (for-each delete-ifdefs
471 (find-files "src/shogun/classifier/mkl"
472 "^MKLClassification\\.cpp")
473 (find-files "src/shogun/classifier/svm"
474 "^SVMLightOneClass\\.(cpp|h)")
475 (find-files "src/shogun/multiclass"
476 "^ScatterSVM\\.(cpp|h)")
477 (find-files "src/shogun/kernel/"
478 "^(Kernel|CombinedKernel|ProductKernel)\\.(cpp|h)")
479 (find-files "src/shogun/regression/svr"
480 "^(MKLRegression|SVRLight)\\.(cpp|h)")
481 (find-files "src/shogun/transfer/domain_adaptation"
482 "^DomainAdaptationSVM\\.(cpp|h)")))
484 (build-system cmake-build-system)
486 '(#:tests? #f ;no check target
488 (modify-phases %standard-phases
489 (add-after 'unpack 'delete-broken-symlinks
491 (for-each delete-file '("applications/arts/data"
492 "applications/asp/data"
493 "applications/easysvm/data"
494 "applications/msplicer/data"
495 "applications/ocr/data"
497 "examples/undocumented/data"))
499 (add-after 'unpack 'change-R-target-path
500 (lambda* (#:key outputs #:allow-other-keys)
501 (substitute* '("src/interfaces/r/CMakeLists.txt"
502 "examples/meta/r/CMakeLists.txt")
503 (("\\$\\{R_COMPONENT_LIB_PATH\\}")
504 (string-append (assoc-ref outputs "out")
507 (add-after 'unpack 'fix-octave-modules
508 (lambda* (#:key outputs #:allow-other-keys)
509 (substitute* "src/interfaces/octave/CMakeLists.txt"
510 (("^include_directories\\(\\$\\{OCTAVE_INCLUDE_DIRS\\}")
511 "include_directories(${OCTAVE_INCLUDE_DIRS} ${OCTAVE_INCLUDE_DIRS}/octave")
512 ;; change target directory
513 (("\\$\\{OCTAVE_OCT_LOCAL_API_FILE_DIR\\}")
514 (string-append (assoc-ref outputs "out")
515 "/share/octave/packages")))
516 (substitute* '("src/interfaces/octave/swig_typemaps.i"
517 "src/interfaces/octave/sg_print_functions.cpp")
518 ;; "octave/config.h" and "octave/oct-obj.h" deprecated in Octave.
519 (("octave/config\\.h") "octave/octave-config.h")
520 (("octave/oct-obj.h") "octave/ovl.h"))
522 (add-after 'unpack 'move-rxcpp
523 (lambda* (#:key inputs #:allow-other-keys)
524 (let ((rxcpp-dir "shogun/third-party/rxcpp"))
526 (install-file (assoc-ref inputs "rxcpp") rxcpp-dir)
528 (add-before 'build 'set-HOME
529 ;; $HOME needs to be set at some point during the build phase
530 (lambda _ (setenv "HOME" "/tmp") #t)))
532 (list "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE"
533 "-DUSE_SVMLIGHT=OFF" ;disable proprietary SVMLIGHT
534 "-DBUILD_META_EXAMPLES=OFF" ;requires unpackaged ctags
535 ;;"-DINTERFACE_JAVA=ON" ;requires unpackaged jblas
536 ;;"-DINTERFACE_RUBY=ON" ;requires unpackaged ruby-narray
537 ;;"-DINTERFACE_PERL=ON" ;"FindPerlLibs" does not exist
538 ;;"-DINTERFACE_LUA=ON" ;fails because lua doesn't build pkgconfig file
539 "-DINTERFACE_OCTAVE=ON"
540 "-DINTERFACE_PYTHON=ON"
541 "-DINTERFACE_R=ON")))
544 ("numpy" ,python-numpy)
545 ("r-minimal" ,r-minimal)
546 ("octave" ,octave-cli)
551 ("arpack" ,arpack-ng)
558 `(("pkg-config" ,pkg-config)
560 ;; Non-portable SSE instructions are used so building fails on platforms
561 ;; other than x86_64.
562 (supported-systems '("x86_64-linux"))
563 (home-page "http://shogun-toolbox.org/")
564 (synopsis "Machine learning toolbox")
566 "The Shogun Machine learning toolbox provides a wide range of unified and
567 efficient Machine Learning (ML) methods. The toolbox seamlessly allows to
568 combine multiple data representations, algorithm classes, and general purpose
569 tools. This enables both rapid prototyping of data pipelines and extensibility
570 in terms of new algorithms.")
571 (license license:gpl3+)))
581 (url "https://github.com/ReactiveX/RxCpp.git")
582 (commit (string-append "v" version))))
584 (base32 "1rdpa3jlc181jd08nk437aar085h28i45s6nzrv65apb3xyyz0ij"))
585 (file-name (git-file-name name version))))
586 (build-system cmake-build-system)
589 (modify-phases %standard-phases
590 (add-after 'unpack 'remove-werror
592 (substitute* (find-files ".")
597 (invoke "ctest"))))))
599 `(("catch" ,catch-framework)))
600 (home-page "http://reactivex.io/")
601 (synopsis "Reactive Extensions for C++")
603 "The Reactive Extensions for C++ (RxCpp) is a library of algorithms for
604 values-distributed-in-time. ReactiveX is a library for composing asynchronous
605 and event-based programs by using observable sequences.
607 It extends the observer pattern to support sequences of data and/or events and
608 adds operators that allow you to compose sequences together declaratively while
609 abstracting away concerns about things like low-level threading,
610 synchronization, thread-safety, concurrent data structures, and non-blocking
612 (license license:asl2.0)))
614 (define-public r-adaptivesparsity
616 (name "r-adaptivesparsity")
620 (uri (cran-uri "AdaptiveSparsity" version))
623 "0imr5m8mll9j6n4icsv6z9rl5kbnwsp9wvzrg7n90nnmcxq2cz91"))))
625 `((upstream-name . "AdaptiveSparsity")))
626 (build-system r-build-system)
629 (modify-phases %standard-phases
630 (add-after 'unpack 'link-against-armadillo
632 (substitute* "src/Makevars"
633 (("PKG_LIBS=" prefix)
634 (string-append prefix "-larmadillo"))))))))
637 ("r-matrix" ,r-matrix)
639 ("r-rcpparmadillo" ,r-rcpparmadillo)))
641 `(("armadillo" ,armadillo)))
642 (home-page "https://cran.r-project.org/web/packages/AdaptiveSparsity")
643 (synopsis "Adaptive sparsity models")
645 "This package implements the Figueiredo machine learning algorithm for
646 adaptive sparsity and the Wong algorithm for adaptively sparse gaussian
648 (license license:lgpl3+)))
650 (define-public gemmlowp-for-tensorflow
651 ;; The commit hash is taken from "tensorflow/workspace.bzl".
652 (let ((commit "38ebac7b059e84692f53e5938f97a9943c120d98")
656 (version (git-version "0" revision commit))
659 (uri (string-append "https://mirror.bazel.build/"
660 "github.com/google/gemmlowp/archive/"
662 (file-name (string-append "gemmlowp-" version ".zip"))
665 "0n56s2g8hrssm4w8qj1v58gfm56a04n9v992ixkmvk6zjiralzxq"))))
666 (build-system cmake-build-system)
669 (list ,@(match (%current-system)
670 ((or "x86_64-linux" "i686-linux")
671 '("-DCMAKE_CXX_FLAGS=-msse4.1"))
674 (modify-phases %standard-phases
675 ;; This directory contains the CMakeLists.txt.
676 (add-after 'unpack 'chdir
677 (lambda _ (chdir "contrib") #t))
678 ;; There is no install target
680 (lambda* (#:key outputs #:allow-other-keys)
681 (let* ((out (assoc-ref outputs "out"))
682 (lib (string-append out "/lib/"))
683 (inc (string-append out "/include/")))
684 (install-file "../build/libeight_bit_int_gemm.so" lib)
685 (for-each (lambda (dir)
686 (let ((target (string-append inc "/" dir)))
688 (for-each (lambda (h)
689 (install-file h target))
690 (find-files (string-append "../" dir)
692 '("meta" "profiling" "public" "fixedpoint"
693 "eight_bit_int_gemm" "internal"))
697 (home-page "https://github.com/google/gemmlowp")
698 (synopsis "Small self-contained low-precision GEMM library")
700 "This is a small self-contained low-precision @dfn{general matrix
701 multiplication} (GEMM) library. It is not a full linear algebra library.
702 Low-precision means that the input and output matrix entries are integers on
703 at most 8 bits. To avoid overflow, results are internally accumulated on more
704 than 8 bits, and at the end only some significant 8 bits are kept.")
705 (license license:asl2.0))))
714 "http://dlib.net/files/dlib-" version ".tar.bz2"))
717 "1mljz02kwkrbggyncxv5fpnyjdybw2qihaacb3js8yfkw12vwpc2"))
718 (modules '((guix build utils)))
721 ;; Delete ~13MB of bundled dependencies.
722 (delete-file-recursively "dlib/external")
723 (delete-file-recursively "docs/dlib/external")
725 (build-system cmake-build-system)
728 (modify-phases %standard-phases
729 (add-after 'unpack 'disable-asserts
731 ;; config.h recommends explicitly enabling or disabling asserts
732 ;; when building as a shared library. By default neither is set.
733 (substitute* "dlib/config.h"
734 (("^//#define DLIB_DISABLE_ASSERTS") "#define DLIB_DISABLE_ASSERTS"))
736 (add-after 'disable-asserts 'disable-failing-tests
738 ;; One test times out on MIPS, so we need to disable it.
739 ;; Others are flaky on some platforms.
740 (let* ((system ,(or (%current-target-system)
742 (disabled-tests (cond
743 ((string-prefix? "mips64" system)
744 '("object_detector" ; timeout
746 ((string-prefix? "armhf" system)
747 '("learning_to_track"))
748 ((string-prefix? "i686" system)
753 (substitute* "dlib/test/makefile"
754 (((string-append "SRC \\+= " test "\\.cpp")) "")))
759 ;; No test target, so we build and run the unit tests here.
760 (let ((test-dir (string-append "../dlib-" ,version "/dlib/test")))
761 (with-directory-excursion test-dir
762 (invoke "make" "-j" (number->string (parallel-job-count)))
763 (invoke "./dtest" "--runall"))
765 (add-after 'install 'delete-static-library
766 (lambda* (#:key outputs #:allow-other-keys)
767 (delete-file (string-append (assoc-ref outputs "out")
771 `(("pkg-config" ,pkg-config)
780 ("openblas" ,openblas)
783 "Toolkit for making machine learning and data analysis applications in C++")
785 "Dlib is a modern C++ toolkit containing machine learning algorithms and
786 tools. It is used in both industry and academia in a wide range of domains
787 including robotics, embedded devices, mobile phones, and large high performance
788 computing environments.")
789 (home-page "http://dlib.net")
790 (license license:boost1.0)))
792 (define-public python-scikit-learn
794 (name "python-scikit-learn")
800 (url "https://github.com/scikit-learn/scikit-learn.git")
802 (file-name (git-file-name name version))
805 "0fkhwg3xn1s7ln9q1szq6kwc4jhwvjh8w4kmv9wcrqy7cq3lbv0d"))))
806 (build-system python-build-system)
809 (modify-phases %standard-phases
810 (add-after 'build 'build-ext
811 (lambda _ (invoke "python" "setup.py" "build_ext" "--inplace") #t))
814 ;; Restrict OpenBLAS threads to prevent segfaults while testing!
815 (setenv "OPENBLAS_NUM_THREADS" "1")
817 ;; Some tests require write access to $HOME.
818 (setenv "HOME" "/tmp")
820 (invoke "pytest" "sklearn" "-m" "not network")))
821 ;; FIXME: This fails with permission denied
822 (delete 'reset-gzip-timestamps))))
824 `(("openblas" ,openblas)))
826 `(("python-pytest" ,python-pytest)
827 ("python-pandas" ,python-pandas) ;for tests
828 ("python-cython" ,python-cython)))
830 `(("python-numpy" ,python-numpy)
831 ("python-scipy" ,python-scipy)))
832 (home-page "http://scikit-learn.org/")
833 (synopsis "Machine Learning in Python")
835 "Scikit-learn provides simple and efficient tools for data mining and
837 (license license:bsd-3)))
839 (define-public python2-scikit-learn
840 (package-with-python2 python-scikit-learn))
842 (define-public python-autograd
843 (let* ((commit "442205dfefe407beffb33550846434baa90c4de7")
845 (version (git-version "0.0.0" revision commit)))
847 (name "python-autograd")
848 (home-page "https://github.com/HIPS/autograd")
856 "189sv2xb0mwnjawa9z7mrgdglc1miaq93pnck26r28fi1jdwg0z4"))
857 (file-name (git-file-name name version))))
859 (build-system python-build-system)
861 `(("python-nose" ,python-nose)
862 ("python-pytest" ,python-pytest)))
864 `(("python-future" ,python-future)
865 ("python-numpy" ,python-numpy)))
867 `(#:phases (modify-phases %standard-phases
870 (invoke "py.test" "-v"))))))
871 (synopsis "Efficiently computes derivatives of NumPy code")
872 (description "Autograd can automatically differentiate native Python and
873 NumPy code. It can handle a large subset of Python's features, including loops,
874 ifs, recursion and closures, and it can even take derivatives of derivatives
875 of derivatives. It supports reverse-mode differentiation
876 (a.k.a. backpropagation), which means it can efficiently take gradients of
877 scalar-valued functions with respect to array-valued arguments, as well as
878 forward-mode differentiation, and the two can be composed arbitrarily. The
879 main intended application of Autograd is gradient-based optimization.")
880 (license license:expat))))
882 (define-public python2-autograd
883 (package-with-python2 python-autograd))
885 (define-public lightgbm
892 "https://github.com/Microsoft/LightGBM/archive/v"
896 "132zf0yk0545mg72hyzxm102g3hpb6ixx9hnf8zd2k55gas6cjj1"))
897 (file-name (string-append name "-" version ".tar.gz"))))
899 `(("python-pytest" ,python-pytest)
900 ("python-nose" ,python-nose)))
902 `(("openmpi" ,openmpi)))
904 `(("python-numpy" ,python-numpy)
905 ("python-scipy" ,python-scipy)))
910 (modify-phases %standard-phases
912 (lambda* (#:key outputs #:allow-other-keys)
913 (with-directory-excursion ,(string-append "../LightGBM-" version)
914 (invoke "pytest" "tests/c_api_test/test_.py")))))))
915 (build-system cmake-build-system)
916 (home-page "https://github.com/Microsoft/LightGBM")
917 (synopsis "Gradient boosting framework based on decision tree algorithms")
918 (description "LightGBM is a gradient boosting framework that uses tree
919 based learning algorithms. It is designed to be distributed and efficient with
920 the following advantages:
923 @item Faster training speed and higher efficiency
924 @item Lower memory usage
925 @item Better accuracy
926 @item Parallel and GPU learning supported (not enabled in this package)
927 @item Capable of handling large-scale data
929 (license license:expat)))
931 (define-public vowpal-wabbit
932 ;; Language bindings not included.
934 (name "vowpal-wabbit")
939 "https://github.com/JohnLangford/vowpal_wabbit/archive/"
943 "0clp2kb7rk5sckhllxjr5a651awf4s8dgzg4659yh4hf5cqnf0gr"))
944 (file-name (string-append name "-" version ".tar.gz"))))
950 (list (string-append "--with-boost="
951 (assoc-ref %build-inputs "boost")))))
952 (build-system gnu-build-system)
953 (home-page "https://github.com/JohnLangford/vowpal_wabbit")
954 (synopsis "Fast machine learning library for online learning")
955 (description "Vowpal Wabbit is a machine learning system with techniques
956 such as online, hashing, allreduce, reductions, learning2search, active, and
957 interactive learning.")
958 (license license:bsd-3)))
960 (define-public python2-fastlmm
962 (name "python2-fastlmm")
967 (uri (pypi-uri "fastlmm" version ".zip"))
970 "1q8c34rpmwkfy3r4d5172pzdkpfryj561897z9r3x22gq7813x1m"))))
971 (build-system python-build-system)
973 `(#:tests? #f ; some test files are missing
974 #:python ,python-2)) ; only Python 2.7 is supported
976 `(("python2-numpy" ,python2-numpy)
977 ("python2-scipy" ,python2-scipy)
978 ("python2-matplotlib" ,python2-matplotlib)
979 ("python2-pandas" ,python2-pandas)
980 ("python2-scikit-learn" ,python2-scikit-learn)
981 ("python2-pysnptools" ,python2-pysnptools)))
984 ("python2-cython" ,python2-cython)
985 ("python2-mock" ,python2-mock)
986 ("python2-nose" ,python2-nose)))
987 (home-page "http://research.microsoft.com/en-us/um/redmond/projects/mscompbio/fastlmm/")
988 (synopsis "Perform genome-wide association studies on large data sets")
990 "FaST-LMM, which stands for Factored Spectrally Transformed Linear Mixed
991 Models, is a program for performing both single-SNP and SNP-set genome-wide
992 association studies (GWAS) on extremely large data sets.")
993 (license license:asl2.0)))
995 ;; There have been no proper releases yet.
997 (let ((commit "2f95609f0bb085bd3a1dc5eb0a39f3edea59e606")
1001 (version (git-version "0" revision commit))
1005 (url "https://github.com/kaldi-asr/kaldi.git")
1007 (file-name (git-file-name name version))
1010 "082qh3pfi7hvncylp4xsmkfahbd7gb0whdfa4rwrx7fxk9rdh3kz"))))
1011 (build-system gnu-build-system)
1013 `(#:test-target "test"
1015 (modify-phases %standard-phases
1016 (add-after 'unpack 'chdir
1017 (lambda _ (chdir "src") #t))
1019 (lambda* (#:key build system inputs outputs #:allow-other-keys)
1020 (when (not (or (string-prefix? "x86_64" system)
1021 (string-prefix? "i686" system)))
1022 (substitute* "makefiles/linux_openblas.mk"
1023 (("-msse -msse2") "")))
1024 (substitute* "makefiles/default_rules.mk"
1025 (("/bin/bash") (which "bash")))
1026 (substitute* "Makefile"
1027 (("ext_depend: check_portaudio")
1029 (substitute* '("online/Makefile"
1030 "onlinebin/Makefile"
1031 "gst-plugin/Makefile")
1032 (("../../tools/portaudio/install")
1033 (assoc-ref inputs "portaudio")))
1035 ;; This `configure' script doesn't support variables passed as
1036 ;; arguments, nor does it support "prefix".
1037 (let ((out (assoc-ref outputs "out"))
1038 (openblas (assoc-ref inputs "openblas"))
1039 (openfst (assoc-ref inputs "openfst")))
1040 (substitute* "configure"
1041 (("check_for_slow_expf;") "")
1042 ;; This affects the RPATH and also serves as the installation
1044 (("KALDILIBDIR=`pwd`/lib")
1045 (string-append "KALDILIBDIR=" out "/lib")))
1046 (mkdir-p out) ; must exist
1047 (setenv "CONFIG_SHELL" (which "bash"))
1048 (setenv "OPENFST_VER" ,(package-version openfst))
1049 (invoke "./configure"
1052 (string-append "--openblas-root=" openblas)
1053 (string-append "--fst-root=" openfst)))))
1054 (add-after 'build 'build-ext-and-gstreamer-plugin
1056 (invoke "make" "-C" "online" "depend")
1057 (invoke "make" "-C" "online")
1058 (invoke "make" "-C" "onlinebin" "depend")
1059 (invoke "make" "-C" "onlinebin")
1060 (invoke "make" "-C" "gst-plugin" "depend")
1061 (invoke "make" "-C" "gst-plugin")
1063 ;; TODO: also install the executables.
1065 (lambda* (#:key outputs #:allow-other-keys)
1066 (let* ((out (assoc-ref outputs "out"))
1067 (inc (string-append out "/include"))
1068 (lib (string-append out "/lib")))
1070 ;; The build phase installed symlinks to the actual
1071 ;; libraries. Install the actual targets.
1072 (for-each (lambda (file)
1073 (let ((target (readlink file)))
1075 (install-file target lib)))
1076 (find-files lib "\\.so"))
1078 (for-each (lambda (file)
1079 (let ((target-dir (string-append inc "/" (dirname file))))
1080 (install-file file target-dir)))
1081 (find-files "." "\\.h"))
1082 (install-file "gst-plugin/libgstonlinegmmdecodefaster.so"
1083 (string-append lib "/gstreamer-1.0"))
1086 `(("alsa-lib" ,alsa-lib)
1087 ("gfortran" ,gfortran "lib")
1089 ("gstreamer" ,gstreamer)
1091 ("openblas" ,openblas)
1092 ("openfst" ,openfst)
1093 ("portaudio" ,portaudio)
1094 ("python" ,python)))
1096 `(("glib" ,glib "bin") ; glib-genmarshal
1099 ("pkg-config" ,pkg-config)
1101 (home-page "https://kaldi-asr.org/")
1102 (synopsis "Speech recognition toolkit")
1103 (description "Kaldi is an extensible toolkit for speech recognition
1105 (license license:asl2.0))))
1107 (define-public gst-kaldi-nnet2-online
1108 (let ((commit "617e43e73c7cc45eb9119028c02bd4178f738c4a")
1111 (name "gst-kaldi-nnet2-online")
1112 (version (git-version "0" revision commit))
1116 (url "https://github.com/alumae/gst-kaldi-nnet2-online.git")
1118 (file-name (git-file-name name version))
1121 "0xh3w67b69818s6ib02ara4lw7wamjdmh4jznvkpzrs4skbs9jx9"))))
1122 (build-system gnu-build-system)
1124 `(#:tests? #f ; there are none
1126 (list (string-append "SHELL="
1127 (assoc-ref %build-inputs "bash") "/bin/bash")
1128 (string-append "KALDI_ROOT="
1129 (assoc-ref %build-inputs "kaldi-src"))
1130 (string-append "KALDILIBDIR="
1131 (assoc-ref %build-inputs "kaldi") "/lib")
1132 "KALDI_FLAVOR=dynamic")
1134 (modify-phases %standard-phases
1135 (add-after 'unpack 'chdir
1136 (lambda _ (chdir "src") #t))
1138 (lambda* (#:key inputs #:allow-other-keys)
1139 (let ((glib (assoc-ref inputs "glib")))
1140 (setenv "CXXFLAGS" "-std=c++11 -fPIC")
1141 (setenv "CPLUS_INCLUDE_PATH"
1142 (string-append glib "/include/glib-2.0:"
1143 glib "/lib/glib-2.0/include:"
1144 (assoc-ref inputs "gstreamer")
1145 "/include/gstreamer-1.0:"
1146 (getenv "CPLUS_INCLUDE_PATH"))))
1147 (substitute* "Makefile"
1148 (("include \\$\\(KALDI_ROOT\\)/src/kaldi.mk") "")
1149 (("\\$\\(error Cannot find") "#"))))
1150 (add-before 'build 'build-depend
1151 (lambda* (#:key make-flags #:allow-other-keys)
1152 (apply invoke "make" "depend" make-flags)))
1154 (lambda* (#:key outputs #:allow-other-keys)
1155 (let* ((out (assoc-ref outputs "out"))
1156 (lib (string-append out "/lib/gstreamer-1.0")))
1157 (install-file "libgstkaldinnet2onlinedecoder.so" lib)
1161 ("gstreamer" ,gstreamer)
1162 ("jansson" ,jansson)
1163 ("openfst" ,openfst)
1167 ("glib:bin" ,glib "bin") ; glib-genmarshal
1168 ("kaldi-src" ,(package-source kaldi))
1169 ("pkg-config" ,pkg-config)))
1170 (home-page "https://kaldi-asr.org/")
1171 (synopsis "Gstreamer plugin for decoding speech")
1172 (description "This package provides a GStreamer plugin that wraps
1173 Kaldi's @code{SingleUtteranceNnet2Decoder}. It requires iVector-adapted DNN
1174 acoustic models. The iVectors are adapted to the current audio stream
1176 (license license:asl2.0))))
1178 (define-public kaldi-gstreamer-server
1179 (let ((commit "1735ba49c5dc0ebfc184e45105fc600cd9f1f508")
1182 (name "kaldi-gstreamer-server")
1183 (version (git-version "0" revision commit))
1187 (url "https://github.com/alumae/kaldi-gstreamer-server.git")
1189 (file-name (git-file-name name version))
1192 "0j701m7lbwmzqxsfanj882v7881hrbmpqybbczbxqpcbg8q34w0k"))))
1193 (build-system gnu-build-system)
1195 `(#:tests? #f ; there are no tests that can be run automatically
1196 #:modules ((guix build utils)
1197 (guix build gnu-build-system)
1200 (modify-phases %standard-phases
1203 (lambda* (#:key outputs #:allow-other-keys)
1204 ;; Disable hash randomization to ensure the generated .pycs
1205 ;; are reproducible.
1206 (setenv "PYTHONHASHSEED" "0")
1207 (with-directory-excursion "kaldigstserver"
1208 (for-each (lambda (file)
1212 "-f" ; force rebuild
1214 (find-files "." "\\.py$")))
1217 (lambda* (#:key inputs outputs #:allow-other-keys)
1218 (let* ((out (assoc-ref outputs "out"))
1219 (bin (string-append out "/bin"))
1220 (share (string-append out "/share/kaldi-gstreamer-server/")))
1221 ;; Install Python files
1222 (with-directory-excursion "kaldigstserver"
1223 (for-each (cut install-file <> share)
1224 (find-files "." ".*")))
1226 ;; Install sample configuration files
1227 (for-each (cut install-file <> share)
1228 (find-files "." "\\.yaml"))
1230 ;; Install executables
1232 (let* ((server (string-append bin "/kaldi-gst-server"))
1233 (client (string-append bin "/kaldi-gst-client"))
1234 (worker (string-append bin "/kaldi-gst-worker"))
1235 (PYTHONPATH (getenv "PYTHONPATH"))
1236 (GST_PLUGIN_PATH (string-append
1237 (assoc-ref inputs "gst-kaldi-nnet2-online")
1238 "/lib/gstreamer-1.0:${GST_PLUGIN_PATH}"))
1239 (wrap (lambda (wrapper what)
1240 (with-output-to-file wrapper
1244 export PYTHONPATH=~a
1245 export GST_PLUGIN_PATH=~a
1246 exec ~a ~a/~a \"$@\"~%"
1247 (which "bash") PYTHONPATH GST_PLUGIN_PATH
1248 (which "python") share what)))
1249 (chmod wrapper #o555))))
1251 (list server client worker)
1252 (list "master_server.py"
1257 `(("gst-kaldi-nnet2-online" ,gst-kaldi-nnet2-online)
1258 ("python2" ,python-2)
1259 ("python2-futures" ,python2-futures)
1260 ("python2-pygobject" ,python2-pygobject)
1261 ("python2-pyyaml" ,python2-pyyaml)
1262 ("python2-tornado" ,python2-tornado)
1263 ("python2-ws4py" ,python2-ws4py-for-kaldi-gstreamer-server)))
1264 (home-page "https://github.com/alumae/kaldi-gstreamer-server")
1265 (synopsis "Real-time full-duplex speech recognition server")
1266 (description "This is a real-time full-duplex speech recognition server,
1267 based on the Kaldi toolkit and the GStreamer framework and implemented in
1269 (license license:bsd-2))))
1278 (url "https://github.com/grpc/grpc.git")
1279 (commit (string-append "v" version))))
1280 (file-name (git-file-name name version))
1283 "1jimqz3115f9pli5w6ik9wi7mjc7ix6y7yrq4a1ab9fc3dalj7p2"))))
1284 (build-system cmake-build-system)
1286 `(#:tests? #f ; no test target
1288 (list "-DgRPC_ZLIB_PROVIDER=package"
1289 "-DgRPC_CARES_PROVIDER=package"
1290 "-DgRPC_SSL_PROVIDER=package"
1291 "-DgRPC_PROTOBUF_PROVIDER=package")))
1293 `(("c-ares" ,c-ares-next)
1294 ("openssl" ,openssl)
1297 `(("protobuf" ,protobuf-next)
1298 ("python" ,python-wrapper)))
1299 (home-page "https://grpc.io")
1300 (synopsis "High performance universal RPC framework")
1301 (description "gRPC is a modern open source high performance @dfn{Remote
1302 Procedure Call} (RPC) framework that can run in any environment. It can
1303 efficiently connect services in and across data centers with pluggable support
1304 for load balancing, tracing, health checking and authentication. It is also
1305 applicable in last mile of distributed computing to connect devices, mobile
1306 applications and browsers to backend services.")
1307 (license license:asl2.0)))
1309 ;; Note that Tensorflow includes a "third_party" directory, which seems to not
1310 ;; only contain modified subsets of upstream library source code, but also
1311 ;; adapter headers provided by Google (such as the fft.h header, which is not
1312 ;; part of the upstream project code). The Tensorflow code includes headers
1313 ;; from the "third_party" directory. It does not look like we can replace
1314 ;; these headers with unmodified upstream files, so we keep them.
1315 (define-public tensorflow
1323 (url "https://github.com/tensorflow/tensorflow.git")
1324 (commit (string-append "v" version))))
1325 (file-name (string-append "tensorflow-" version "-checkout"))
1328 "0a9kwha395g3wgxfwln5j8vn9nkspmd75xldrlqdq540w996g8xa"))))
1329 (build-system cmake-build-system)
1331 `(#:tests? #f ; no "check" target
1332 #:build-type "Release"
1334 (let ((protobuf (assoc-ref %build-inputs "protobuf"))
1335 (protobuf:native (assoc-ref %build-inputs "protobuf:native"))
1336 (jsoncpp (assoc-ref %build-inputs "jsoncpp"))
1337 (snappy (assoc-ref %build-inputs "snappy"))
1338 (sqlite (assoc-ref %build-inputs "sqlite")))
1340 ;; Use protobuf from Guix
1341 (string-append "-Dprotobuf_STATIC_LIBRARIES="
1342 protobuf "/lib/libprotobuf.so")
1343 (string-append "-DPROTOBUF_PROTOC_EXECUTABLE="
1344 protobuf:native "/bin/protoc")
1346 ;; Use snappy from Guix
1347 (string-append "-Dsnappy_STATIC_LIBRARIES="
1348 snappy "/lib/libsnappy.so")
1349 ;; Yes, this is not actually the include directory but a prefix...
1350 (string-append "-Dsnappy_INCLUDE_DIR=" snappy)
1352 ;; Use jsoncpp from Guix
1353 (string-append "-Djsoncpp_STATIC_LIBRARIES="
1354 jsoncpp "/lib/libjsoncpp.so")
1355 ;; Yes, this is not actually the include directory but a prefix...
1356 (string-append "-Djsoncpp_INCLUDE_DIR=" jsoncpp)
1358 ;; Use sqlite from Guix
1359 (string-append "-Dsqlite_STATIC_LIBRARIES="
1360 sqlite "/lib/libsqlite.a")
1362 ;; Use system libraries wherever possible. Currently, this
1363 ;; only affects zlib.
1364 "-Dsystemlib_ALL=ON"
1365 "-Dtensorflow_ENABLE_POSITION_INDEPENDENT_CODE=ON"
1366 "-Dtensorflow_BUILD_SHARED_LIB=ON"
1367 "-Dtensorflow_OPTIMIZE_FOR_NATIVE_ARCH=OFF"
1368 "-Dtensorflow_ENABLE_SSL_SUPPORT=OFF"
1369 "-Dtensorflow_BUILD_CONTRIB_KERNELS=OFF"))
1372 #:modules ((ice-9 ftw)
1374 (guix build cmake-build-system))
1376 (modify-phases %standard-phases
1377 (add-after 'unpack 'set-source-file-times-to-1980
1378 ;; At the end of the tf_python_build_pip_package target, a ZIP
1379 ;; archive should be generated via bdist_wheel, but it fails with
1380 ;; "ZIP does not support timestamps before 1980". Luckily,
1381 ;; SOURCE_DATE_EPOCH is respected, which we set to some time in
1383 (lambda _ (setenv "SOURCE_DATE_EPOCH" "315532800") #t))
1384 ;; See https://github.com/tensorflow/tensorflow/issues/20517#issuecomment-406373913
1385 (add-after 'unpack 'python3.7-compatibility
1387 (substitute* '("tensorflow/python/eager/pywrap_tfe_src.cc"
1388 "tensorflow/python/lib/core/ndarray_tensor.cc"
1389 "tensorflow/python/lib/core/py_func.cc")
1390 (("PyUnicode_AsUTF8") "(char *)PyUnicode_AsUTF8"))
1391 (substitute* "tensorflow/c/eager/c_api.h"
1392 (("unsigned char async")
1393 "unsigned char is_async"))
1395 ;; Remove dependency on tensorboard, a complicated but probably
1396 ;; optional package.
1397 (substitute* "tensorflow/tools/pip_package/setup.py"
1398 ((".*'tensorboard >.*") ""))
1400 (add-after 'python3.7-compatibility 'chdir
1401 (lambda _ (chdir "tensorflow/contrib/cmake") #t))
1402 (add-after 'chdir 'disable-downloads
1403 (lambda* (#:key inputs #:allow-other-keys)
1404 (substitute* (find-files "external" "\\.cmake$")
1405 (("GIT_REPOSITORY.*") "")
1408 "DOWNLOAD_COMMAND \"\"\nPREFIX "))
1410 ;; Use packages from Guix
1411 (let ((grpc (assoc-ref inputs "grpc")))
1412 (substitute* "CMakeLists.txt"
1414 (("include\\(sqlite\\)") "")
1415 (("\\$\\{sqlite_STATIC_LIBRARIES\\}")
1416 (string-append (assoc-ref inputs "sqlite")
1417 "/lib/libsqlite3.so"))
1418 (("sqlite_copy_headers_to_destination") "")
1421 (("include\\(png\\)") "")
1422 (("\\$\\{png_STATIC_LIBRARIES\\}")
1423 (string-append (assoc-ref inputs "libpng")
1424 "/lib/libpng16.so"))
1425 (("png_copy_headers_to_destination") "")
1428 (("include\\(jpeg\\)") "")
1429 (("\\$\\{jpeg_STATIC_LIBRARIES\\}")
1430 (string-append (assoc-ref inputs "libjpeg")
1432 (("jpeg_copy_headers_to_destination") "")
1435 (("include\\(gif\\)") "")
1436 (("\\$\\{gif_STATIC_LIBRARIES\\}")
1437 (string-append (assoc-ref inputs "giflib")
1439 (("gif_copy_headers_to_destination") "")
1442 (("include\\(lmdb\\)") "")
1443 (("\\$\\{lmdb_STATIC_LIBRARIES\\}")
1444 (string-append (assoc-ref inputs "lmdb")
1446 (("lmdb_copy_headers_to_destination") "")
1449 (("include\\(protobuf\\)") "")
1450 (("protobuf_copy_headers_to_destination") "")
1451 (("^ +protobuf") "")
1454 (("include\\(grpc\\)")
1455 "find_package(grpc REQUIRED NAMES gRPC)")
1456 (("list\\(APPEND tensorflow_EXTERNAL_DEPENDENCIES grpc\\)") "")
1459 (("include\\(eigen\\)")
1460 (string-append "find_package(eigen REQUIRED NAMES Eigen3)
1461 set(eigen_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/external/eigen_archive "
1462 (assoc-ref inputs "eigen") "/include/eigen3)"))
1466 (("include\\(snappy\\)")
1467 "add_definitions(-DTF_USE_SNAPPY)")
1468 (("list\\(APPEND tensorflow_EXTERNAL_DEPENDENCIES snappy\\)") "")
1471 (("include\\(jsoncpp\\)") "")
1472 (("^ +jsoncpp") ""))
1474 (substitute* "tf_core_framework.cmake"
1476 (("\\$\\{GRPC_BUILD\\}/grpc_cpp_plugin")
1477 (which "grpc_cpp_plugin"))
1478 ;; Link with gRPC libraries
1479 (("add_library\\(tf_protos_cc.*" m)
1481 (format #f "\ntarget_link_libraries(tf_protos_cc PRIVATE \
1482 ~a/lib/libgrpc++_unsecure.a \
1483 ~a/lib/libgrpc_unsecure.a \
1484 ~a/lib/libaddress_sorting.a \
1489 (assoc-ref inputs "c-ares"))))))
1490 (substitute* "tf_tools.cmake"
1491 (("add_dependencies\\(\\$\\{proto_text.*") ""))
1492 ;; Remove dependency on bundled grpc
1493 (substitute* "tf_core_distributed_runtime.cmake"
1494 (("tf_core_cpu grpc") "tf_core_cpu"))
1496 ;; This directory is a dependency of many targets.
1497 (mkdir-p "protobuf")
1499 (add-after 'configure 'unpack-third-party-sources
1500 (lambda* (#:key inputs #:allow-other-keys)
1501 ;; This is needed to configure bundled packages properly.
1502 (setenv "CONFIG_SHELL" (which "bash"))
1505 (let* ((what (assoc-ref inputs (string-append name "-src")))
1506 (name* (string-map (lambda (c)
1509 (where (string-append "../build/" name* "/src/" name*)))
1511 ((string-suffix? ".zip" what)
1513 (with-directory-excursion where
1514 (invoke "unzip" what)))
1515 ((string-suffix? ".tar.gz" what)
1517 (invoke "tar" "xf" what
1518 "-C" where "--strip-components=1"))
1520 (let ((parent (dirname where)))
1522 (with-directory-excursion parent
1523 (when (file-exists? name*)
1524 (delete-file-recursively name*))
1525 (copy-recursively what name*)
1526 (map make-file-writable
1527 (find-files name* ".*"))))))))
1537 (rename-file "../build/cub/src/cub/cub-1.8.0/"
1538 "../build/cub/src/cub/cub/")
1540 (add-after 'unpack 'fix-python-build
1541 (lambda* (#:key inputs outputs #:allow-other-keys)
1542 (mkdir-p "protobuf-src")
1543 (invoke "tar" "xf" (assoc-ref inputs "protobuf:src")
1544 "-C" "protobuf-src" "--strip-components=1")
1545 (mkdir-p "eigen-src")
1546 (invoke "tar" "xf" (assoc-ref inputs "eigen:src")
1547 "-C" "eigen-src" "--strip-components=1")
1549 (substitute* "tensorflow/contrib/cmake/tf_python.cmake"
1550 ;; Ensure that all Python dependencies can be found at build time.
1551 (("PYTHONPATH=\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/tf_python" m)
1552 (string-append m ":" (getenv "PYTHONPATH")))
1553 ;; Take protobuf source files from our source package.
1554 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/protobuf/src/protobuf/src/google")
1555 (string-append (getcwd) "/protobuf-src/src/google")))
1557 (substitute* '("tensorflow/contrib/cmake/tf_shared_lib.cmake"
1558 "tensorflow/contrib/cmake/tf_python.cmake")
1559 ;; Take Eigen source files from our source package.
1560 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/eigen/src/eigen/")
1561 (string-append (getcwd) "/eigen-src/"))
1562 ;; Take Eigen headers from our own package.
1563 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/external/eigen_archive")
1564 (string-append (assoc-ref inputs "eigen") "/include/eigen3")))
1566 ;; Correct the RUNPATH of ops libraries generated for Python.
1567 ;; TODO: this doesn't work :(
1568 ;; /gnu/store/...-tensorflow-1.9.0/lib/python3.7/site-packages/tensorflow/contrib/seq2seq/python/ops/lib_beam_search_ops.so:
1569 ;; warning: RUNPATH contains bogus entries: ("/tmp/guix-build-tensorflow-1.9.0.drv-0/source/tensorflow/contrib/build")
1570 ;; /gnu/store/...-tensorflow-1.9.0/lib/python3.7/site-packages/tensorflow/contrib/seq2seq/python/ops/lib_beam_search_ops.so:
1571 ;; error: depends on 'libpywrap_tensorflow_internal.so', which
1572 ;; cannot be found in RUNPATH ...
1573 (substitute* "tensorflow/contrib/cmake/tf_cc_ops.cmake"
1574 (("set_target_properties.*")
1575 (string-append "set_target_properties(${_AT_TARGET} PROPERTIES \
1576 COMPILE_FLAGS ${target_compile_flags} \
1577 INSTALL_RPATH_USE_LINK_PATH TRUE \
1578 INSTALL_RPATH " (assoc-ref outputs "out") "/lib)\n")))
1580 (add-after 'build 'build-pip-package
1581 (lambda* (#:key outputs #:allow-other-keys)
1583 (string-append "-Wl,-rpath="
1584 (assoc-ref outputs "out") "/lib"))
1585 (invoke "make" "tf_python_build_pip_package")
1587 (add-after 'build-pip-package 'install-python
1588 (lambda* (#:key outputs #:allow-other-keys)
1589 (let ((out (assoc-ref outputs "out"))
1590 (wheel (car (find-files "../build/tf_python/dist/" "\\.whl$"))))
1591 (invoke "python" "-m" "pip" "install" wheel
1592 (string-append "--prefix=" out))
1594 ;; XXX: broken RUNPATH, see fix-python-build phase.
1597 out "/lib/python3.7/site-packages/tensorflow/contrib/"
1598 "seq2seq/python/ops/lib_beam_search_ops.so"))
1601 `(("pkg-config" ,pkg-config)
1602 ("protobuf:native" ,protobuf-next) ; protoc
1603 ("protobuf:src" ,(package-source protobuf-next))
1604 ("eigen:src" ,(package-source eigen-for-tensorflow))
1605 ;; The commit hashes and URLs for third-party source code are taken
1606 ;; from "tensorflow/workspace.bzl".
1608 ,(let ((commit "ee7aa02")
1613 (url "https://boringssl.googlesource.com/boringssl")
1615 (file-name (string-append "boringssl-0-" revision
1616 (string-take commit 7)
1620 "1jf693q0nw0adsic6cgmbdx6g7wr4rj4vxa8j1hpn792fqhd8wgw")))))
1622 ,(let ((version "1.8.0"))
1625 (uri (string-append "https://mirror.bazel.build/github.com/NVlabs/"
1626 "cub/archive/" version ".zip"))
1627 (file-name (string-append "cub-" version ".zip"))
1630 "1hsqikqridb90dkxkjr2918dcry6pfh46ccnwrzawl56aamhdykb")))))
1631 ("double-conversion-src"
1632 ,(let ((commit "5664746")
1637 (url "https://github.com/google/double-conversion.git")
1640 (git-file-name "double-conversion"
1641 (string-append "0-" revision "."
1642 (string-take commit 7))))
1645 "1h5lppqqxcvdg5jq42i5msgwx20ryij3apvmndflngrgdpc04gn1")))))
1647 ,(let ((commit "816a4ae622e964763ca0862d9dbd19324a1eaf45"))
1651 "https://mirror.bazel.build/github.com/google/farmhash/archive/"
1653 (file-name (string-append "farmhash-0-" (string-take commit 7)
1657 "185b2xdxl4d4cnsnv6abg8s22gxvx8673jq2yaq85bz4cdy58q35")))))
1658 ;; The license notice on the home page at
1659 ;; http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html says:
1660 ;; Copyright Takuya OOURA, 1996-2001
1662 ;; You may use, copy, modify and distribute this code for any purpose
1663 ;; (include commercial use) and without fee. Please refer to this
1664 ;; package when you modify this code.
1666 ;; We take the identical tarball from the Bazel mirror, because the URL
1667 ;; at the home page is not versioned and might change.
1671 (uri "https://mirror.bazel.build/www.kurims.kyoto-u.ac.jp/~ooura/fft.tgz")
1672 (file-name "fft2d.tar.gz")
1675 "15jjkfvhqvl2c0753d2di8hz0pyzn598g74wqy79awdrf1y67fsj"))))
1677 ,(let ((commit "be5edafc2e1a455768e260ccd68ae7317b6690ee")
1682 (url "https://github.com/google/highwayhash.git")
1684 (file-name (string-append "highwayhash-0-" revision
1685 (string-take commit 7)
1689 "154jwf98cyy54hldr94pgjn85zynly3abpnc1avmb8a18lzwjyb6")))))
1691 ,(let ((version "0559ce013feac8db639ee1bf776aca0325d28777")
1695 (uri (string-append "https://mirror.bazel.build/"
1696 "github.com/google/nsync/archive/"
1698 (file-name (string-append "nsync-0." revision
1699 "-" (string-take version 7)
1703 "0qdkyqym34x739mmzv97ah5r7ph462v5xkxqxvidmcfqbi64b132")))))
1705 ,(let ((commit "e7efc48")
1710 (url "https://github.com/google/re2")
1712 (file-name (string-append "re2-0-" revision
1713 (string-take commit 7)
1717 "161g9841rjfsy5pn52fcis0s9hdr7rxvb06pad38j5rppfihvign")))))
1718 ("googletest" ,googletest)
1722 `(("python-absl-py" ,python-absl-py)
1723 ("python-astor" ,python-astor)
1724 ("python-gast" ,python-gast)
1725 ("python-grpcio" ,python-grpcio)
1726 ("python-numpy" ,python-numpy)
1727 ("python-protobuf" ,python-protobuf-next)
1728 ("python-six" ,python-six)
1729 ("python-termcolo" ,python-termcolor)
1730 ("python-wheel" ,python-wheel)))
1732 `(("c-ares" ,c-ares-next)
1733 ("eigen" ,eigen-for-tensorflow)
1734 ("gemmlowp" ,gemmlowp-for-tensorflow)
1736 ("libjpeg" ,libjpeg)
1740 ("jsoncpp" ,jsoncpp-for-tensorflow)
1743 ("protobuf" ,protobuf-next)
1744 ("python" ,python-wrapper)
1746 (home-page "https://tensorflow.org")
1747 (synopsis "Machine learning framework")
1749 "TensorFlow is a flexible platform for building and training machine
1750 learning models. It provides a library for high performance numerical
1751 computation and includes high level Python APIs, including both a sequential
1752 API for beginners that allows users to build models quickly by plugging
1753 together building blocks and a subclassing API with an imperative style for
1754 advanced research.")
1755 (license license:asl2.0)))