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 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"))
122 "0zd7s19y5vb7agczl6456bn45cj1y64739sslaskw1qk7dywd0bd"))))
123 (build-system gnu-build-system)
125 `(#:tests? #f ;no "check" target
126 #:phases (modify-phases %standard-phases
129 'install ; no ‘install’ target
130 (lambda* (#:key outputs #:allow-other-keys)
131 (let* ((out (assoc-ref outputs "out"))
132 (bin (string-append out "/bin/")))
134 (for-each (lambda (file)
135 (copy-file file (string-append bin file)))
140 (home-page "http://www.csie.ntu.edu.tw/~cjlin/libsvm/")
141 (synopsis "Library for Support Vector Machines")
143 "LIBSVM is a machine learning library for support vector
144 classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and
145 distribution estimation (one-class SVM). It supports multi-class
147 (license license:bsd-3)))
149 (define-public python-libsvm
150 (package (inherit libsvm)
151 (name "python-libsvm")
152 (build-system gnu-build-system)
154 `(#:tests? #f ;no "check" target
155 #:make-flags '("-C" "python")
157 (modify-phases %standard-phases
160 'install ; no ‘install’ target
161 (lambda* (#:key inputs outputs #:allow-other-keys)
162 (let ((site (string-append (assoc-ref outputs "out")
166 (assoc-ref inputs "python") 5) 3)
168 (substitute* "python/svm.py"
169 (("../libsvm.so.2") "libsvm.so.2"))
171 (for-each (lambda (file)
172 (copy-file file (string-append site (basename file))))
173 (find-files "python" "\\.py"))
174 (copy-file "libsvm.so.2"
175 (string-append site "libsvm.so.2")))
178 `(("python" ,python)))
179 (synopsis "Python bindings of libSVM")))
182 ;; The latest release candidate is several years and a couple of fixes have
183 ;; been published since. This is why we download the sources from the SVN
185 (let ((svn-revision 2341))
188 (version (string-append "0.9-rc3-0." (number->string svn-revision)))
192 (url "http://svn.code.sf.net/p/ghmm/code/trunk")
193 (revision svn-revision)))
194 (file-name (string-append name "-" version))
197 "0qbq1rqp94l530f043qzp8aw5lj7dng9wq0miffd7spd1ff638wq"))))
198 (build-system gnu-build-system)
200 `(#:imported-modules (,@%gnu-build-system-modules
201 (guix build python-build-system))
203 (modify-phases %standard-phases
204 (add-after 'unpack 'enter-dir
205 (lambda _ (chdir "ghmm") #t))
207 (add-after 'install 'check
208 (assoc-ref %standard-phases 'check))
209 (add-before 'check 'fix-PYTHONPATH
210 (lambda* (#:key inputs outputs #:allow-other-keys)
211 (let ((python-version ((@@ (guix build python-build-system)
213 (assoc-ref inputs "python"))))
215 (string-append (getenv "PYTHONPATH")
216 ":" (assoc-ref outputs "out")
217 "/lib/python" python-version
220 (add-after 'enter-dir 'fix-runpath
221 (lambda* (#:key outputs #:allow-other-keys)
222 (substitute* "ghmmwrapper/setup.py"
223 (("^(.*)extra_compile_args = \\[" line indent)
224 (string-append indent
225 "extra_link_args = [\"-Wl,-rpath="
226 (assoc-ref outputs "out") "/lib\"],\n"
229 (assoc-ref outputs "out")
232 (add-after 'enter-dir 'disable-broken-tests
234 (substitute* "tests/Makefile.am"
235 ;; GHMM_SILENT_TESTS is assumed to be a command.
236 (("TESTS_ENVIRONMENT.*") "")
237 ;; Do not build broken tests.
241 (("label_higher_order_test.*$")
242 "label_higher_order_test\n"))
244 ;; These Python unittests are broken as there is no gato.
245 ;; See https://sourceforge.net/p/ghmm/support-requests/3/
246 (substitute* "ghmmwrapper/ghmmunittests.py"
247 (("^(.*)def (testNewXML|testMultipleTransitionClasses|testNewXML)"
249 (string-append indent
250 "@unittest.skip(\"Disabled by Guix\")\n"
253 (add-after 'disable-broken-tests 'autogen
255 (invoke "bash" "autogen.sh"))))))
257 `(("python" ,python-2) ; only Python 2 is supported
258 ("libxml2" ,libxml2)))
260 `(("pkg-config" ,pkg-config)
263 ("autoconf" ,autoconf)
264 ("automake" ,automake)
265 ("libtool" ,libtool)))
266 (home-page "http://ghmm.org")
267 (synopsis "Hidden Markov Model library")
269 "The General Hidden Markov Model library (GHMM) is a C library with
270 additional Python bindings implementing a wide range of types of @dfn{Hidden
271 Markov Models} (HMM) and algorithms: discrete, continuous emissions, basic
272 training, HMM clustering, HMM mixtures.")
273 (license license:lgpl2.0+))))
282 "http://micans.org/mcl/src/mcl-"
283 (string-replace-substring version "." "-")
287 "15xlax3z31lsn62vlg94hkm75nm40q4679amnfg13jm8m2bnhy5m"))))
288 (build-system gnu-build-system)
290 `(#:configure-flags (list "--enable-blast")))
293 (home-page "http://micans.org/mcl/")
294 (synopsis "Clustering algorithm for graphs")
296 "The MCL algorithm is short for the @dfn{Markov Cluster Algorithm}, a
297 fast and scalable unsupervised cluster algorithm for graphs (also known as
298 networks) based on simulation of (stochastic) flow in graphs.")
299 ;; In the LICENCE file and web page it says "The software is licensed
300 ;; under the GNU General Public License, version 3.", but in several of
301 ;; the source code files it suggests GPL3 or later.
302 ;; http://listserver.ebi.ac.uk/pipermail/mcl-users/2016/000376.html
303 (license license:gpl3)))
305 (define-public ocaml-mcl
308 (version "12-068oasis4")
313 (url "https://github.com/fhcrc/mcl.git")
315 (file-name (git-file-name name version))
318 "0009dc3h2jp3qg5val452wngpqnbfyhbcxylghq0mrjqxx0jdq5p"))))
319 (build-system ocaml-build-system)
322 (modify-phases %standard-phases
323 (add-before 'configure 'patch-paths
325 (substitute* "configure"
326 (("/bin/sh") (which "sh")))
327 (substitute* "setup.ml"
329 (string-append "LDFLAGS=-fPIC\"; \"SHELL=" (which "sh")))
330 (("-std=c89") "-std=gnu99")
332 ;; This is a mutable string, which is no longer supported. Use
333 ;; a byte buffer instead.
334 (("String.make \\(String.length s\\)")
335 "Bytes.make (String.length s)")
337 ;; These two belong together.
338 (("OASISString.replace_chars")
339 "Bytes.to_string (OASISString.replace_chars")
342 (substitute* "myocamlbuild.ml"
343 (("std=c89") "std=gnu99"))
344 ;; Since we build with a more recent OCaml, we have to use C99 or
345 ;; later. This causes problems with the old C code.
346 (substitute* "src/impala/matrix.c"
347 (("restrict") "restrict_"))
350 `(("ocamlbuild" ,ocamlbuild)))
351 (home-page "https://github.com/fhcrc/mcl")
352 (synopsis "OCaml wrappers around MCL")
354 "This package provides OCaml bindings for the MCL graph clustering
356 (license license:gpl3)))
358 (define-public randomjungle
360 (name "randomjungle")
366 "https://www.imbs.uni-luebeck.de/fileadmin/files/Software"
367 "/randomjungle/randomjungle-" version ".tar_.gz"))
368 (patches (search-patches "randomjungle-disable-static-build.patch"))
371 "12c8rf30cla71swx2mf4ww9mfd8jbdw5lnxd7dxhyw1ygrvg6y4w"))))
372 (build-system gnu-build-system)
375 (list "--disable-static"
376 (string-append "--with-boost="
377 (assoc-ref %build-inputs "boost")))
379 (modify-phases %standard-phases
381 'configure 'set-CXXFLAGS
383 (setenv "CXXFLAGS" "-fpermissive ")
391 `(("gfortran" ,gfortran)
392 ("gfortran:lib" ,gfortran "lib")))
393 ;; Non-portable assembly instructions are used so building fails on
394 ;; platforms other than x86_64 or i686.
395 (supported-systems '("x86_64-linux" "i686-linux"))
396 (home-page "https://www.imbs.uni-luebeck.de/forschung/software/details.html#c224")
397 (synopsis "Implementation of the Random Forests machine learning method")
399 "Random Jungle is an implementation of Random Forests. It is supposed to
400 analyse high dimensional data. In genetics, it can be used for analysing big
401 Genome Wide Association (GWA) data. Random Forests is a powerful machine
402 learning method. Most interesting features are variable selection, missing
403 value imputation, classifier creation, generalization error estimation and
404 sample proximities between pairs of cases.")
405 (license license:gpl3+)))
407 (define-public openfst
413 (uri (string-append "http://www.openfst.org/twiki/pub/FST/"
414 "FstDownload/openfst-" version ".tar.gz"))
417 "0x9wfcqd8hq4h349s7j77sr60h8xjdfshqw1m3a2n6z5bdr9qkm1"))))
418 (build-system gnu-build-system)
419 (home-page "http://www.openfst.org")
420 (synopsis "Library for weighted finite-state transducers")
421 (description "OpenFst is a library for constructing, combining,
422 optimizing, and searching weighted finite-state transducers (FSTs).")
423 (license license:asl2.0)))
425 (define-public shogun
433 "ftp://shogun-toolbox.org/shogun/releases/"
434 (version-major+minor version)
435 "/sources/shogun-" version ".tar.bz2"))
438 "1rn9skm3nw6hr7mr3lgp2gfqhi7ii0lyxck7qmqnf8avq349s5jp"))
439 (modules '((guix build utils)
443 ;; Remove non-free sources and files referencing them
444 (for-each delete-file
445 (find-files "src/shogun/classifier/svm/"
446 "SVMLight\\.(cpp|h)"))
447 (for-each delete-file
448 (find-files "examples/undocumented/libshogun/"
450 "(classifier_.*svmlight.*|"
451 "evaluation_cross_validation_locked_comparison).cpp")))
452 ;; Remove non-free functions.
453 (define (delete-ifdefs file)
454 (with-atomic-file-replacement file
456 (let loop ((line (read-line in 'concat))
458 (if (eof-object? line)
463 "#endif //USE_SVMLIGHT" line)))
465 "#ifdef USE_SVMLIGHT" line))))
466 (when (or (not skipping?)
467 (and skipping? (not skip-next?)))
469 (loop (read-line in 'concat) skip-next?)))))))
470 (for-each delete-ifdefs
472 (find-files "src/shogun/classifier/mkl"
473 "^MKLClassification\\.cpp")
474 (find-files "src/shogun/classifier/svm"
475 "^SVMLightOneClass\\.(cpp|h)")
476 (find-files "src/shogun/multiclass"
477 "^ScatterSVM\\.(cpp|h)")
478 (find-files "src/shogun/kernel/"
479 "^(Kernel|CombinedKernel|ProductKernel)\\.(cpp|h)")
480 (find-files "src/shogun/regression/svr"
481 "^(MKLRegression|SVRLight)\\.(cpp|h)")
482 (find-files "src/shogun/transfer/domain_adaptation"
483 "^DomainAdaptationSVM\\.(cpp|h)")))
485 (build-system cmake-build-system)
487 '(#:tests? #f ;no check target
489 (modify-phases %standard-phases
490 (add-after 'unpack 'delete-broken-symlinks
492 (for-each delete-file '("applications/arts/data"
493 "applications/asp/data"
494 "applications/easysvm/data"
495 "applications/msplicer/data"
496 "applications/ocr/data"
498 "examples/undocumented/data"))
500 (add-after 'unpack 'change-R-target-path
501 (lambda* (#:key outputs #:allow-other-keys)
502 (substitute* '("src/interfaces/r/CMakeLists.txt"
503 "examples/meta/r/CMakeLists.txt")
504 (("\\$\\{R_COMPONENT_LIB_PATH\\}")
505 (string-append (assoc-ref outputs "out")
508 (add-after 'unpack 'fix-octave-modules
509 (lambda* (#:key outputs #:allow-other-keys)
510 (substitute* "src/interfaces/octave/CMakeLists.txt"
511 (("^include_directories\\(\\$\\{OCTAVE_INCLUDE_DIRS\\}")
512 "include_directories(${OCTAVE_INCLUDE_DIRS} ${OCTAVE_INCLUDE_DIRS}/octave")
513 ;; change target directory
514 (("\\$\\{OCTAVE_OCT_LOCAL_API_FILE_DIR\\}")
515 (string-append (assoc-ref outputs "out")
516 "/share/octave/packages")))
517 (substitute* '("src/interfaces/octave/swig_typemaps.i"
518 "src/interfaces/octave/sg_print_functions.cpp")
519 ;; "octave/config.h" and "octave/oct-obj.h" deprecated in Octave.
520 (("octave/config\\.h") "octave/octave-config.h")
521 (("octave/oct-obj.h") "octave/ovl.h"))
523 (add-after 'unpack 'move-rxcpp
524 (lambda* (#:key inputs #:allow-other-keys)
525 (let ((rxcpp-dir "shogun/third-party/rxcpp"))
527 (install-file (assoc-ref inputs "rxcpp") rxcpp-dir)
529 (add-before 'build 'set-HOME
530 ;; $HOME needs to be set at some point during the build phase
531 (lambda _ (setenv "HOME" "/tmp") #t)))
533 (list "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE"
534 "-DUSE_SVMLIGHT=OFF" ;disable proprietary SVMLIGHT
535 "-DBUILD_META_EXAMPLES=OFF" ;requires unpackaged ctags
536 ;;"-DINTERFACE_JAVA=ON" ;requires unpackaged jblas
537 ;;"-DINTERFACE_RUBY=ON" ;requires unpackaged ruby-narray
538 ;;"-DINTERFACE_PERL=ON" ;"FindPerlLibs" does not exist
539 ;;"-DINTERFACE_LUA=ON" ;fails because lua doesn't build pkgconfig file
540 "-DINTERFACE_OCTAVE=ON"
541 "-DINTERFACE_PYTHON=ON"
542 "-DINTERFACE_R=ON")))
545 ("numpy" ,python-numpy)
546 ("r-minimal" ,r-minimal)
547 ("octave" ,octave-cli)
552 ("arpack" ,arpack-ng)
559 `(("pkg-config" ,pkg-config)
561 ;; Non-portable SSE instructions are used so building fails on platforms
562 ;; other than x86_64.
563 (supported-systems '("x86_64-linux"))
564 (home-page "http://shogun-toolbox.org/")
565 (synopsis "Machine learning toolbox")
567 "The Shogun Machine learning toolbox provides a wide range of unified and
568 efficient Machine Learning (ML) methods. The toolbox seamlessly allows to
569 combine multiple data representations, algorithm classes, and general purpose
570 tools. This enables both rapid prototyping of data pipelines and extensibility
571 in terms of new algorithms.")
572 (license license:gpl3+)))
581 (uri (string-append "https://github.com/ReactiveX/RxCpp/archive/v"
585 "0y2isr8dy2n1yjr9c5570kpc9lvdlch6jv0jvw000amwn5d3krsh"))
586 (file-name (string-append name "-" version ".tar.gz"))))
587 (build-system cmake-build-system)
590 (modify-phases %standard-phases
591 (add-after 'unpack 'remove-werror
593 (substitute* (find-files ".")
598 (invoke "ctest"))))))
600 `(("catch" ,catch-framework)))
601 (home-page "http://reactivex.io/")
602 (synopsis "Reactive Extensions for C++")
604 "The Reactive Extensions for C++ (RxCpp) is a library of algorithms for
605 values-distributed-in-time. ReactiveX is a library for composing asynchronous
606 and event-based programs by using observable sequences.
608 It extends the observer pattern to support sequences of data and/or events and
609 adds operators that allow you to compose sequences together declaratively while
610 abstracting away concerns about things like low-level threading,
611 synchronization, thread-safety, concurrent data structures, and non-blocking
613 (license license:asl2.0)))
615 (define-public r-adaptivesparsity
617 (name "r-adaptivesparsity")
621 (uri (cran-uri "AdaptiveSparsity" version))
624 "0imr5m8mll9j6n4icsv6z9rl5kbnwsp9wvzrg7n90nnmcxq2cz91"))))
626 `((upstream-name . "AdaptiveSparsity")))
627 (build-system r-build-system)
630 (modify-phases %standard-phases
631 (add-after 'unpack 'link-against-armadillo
633 (substitute* "src/Makevars"
634 (("PKG_LIBS=" prefix)
635 (string-append prefix "-larmadillo"))))))))
638 ("r-matrix" ,r-matrix)
640 ("r-rcpparmadillo" ,r-rcpparmadillo)))
642 `(("armadillo" ,armadillo)))
643 (home-page "https://cran.r-project.org/web/packages/AdaptiveSparsity")
644 (synopsis "Adaptive sparsity models")
646 "This package implements the Figueiredo machine learning algorithm for
647 adaptive sparsity and the Wong algorithm for adaptively sparse gaussian
649 (license license:lgpl3+)))
651 (define-public gemmlowp-for-tensorflow
652 ;; The commit hash is taken from "tensorflow/workspace.bzl".
653 (let ((commit "38ebac7b059e84692f53e5938f97a9943c120d98")
657 (version (git-version "0" revision commit))
660 (uri (string-append "https://mirror.bazel.build/"
661 "github.com/google/gemmlowp/archive/"
663 (file-name (string-append "gemmlowp-" version ".zip"))
666 "0n56s2g8hrssm4w8qj1v58gfm56a04n9v992ixkmvk6zjiralzxq"))))
667 (build-system cmake-build-system)
670 (list ,@(match (%current-system)
671 ((or "x86_64-linux" "i686-linux")
672 '("-DCMAKE_CXX_FLAGS=-msse4.1"))
675 (modify-phases %standard-phases
676 ;; This directory contains the CMakeLists.txt.
677 (add-after 'unpack 'chdir
678 (lambda _ (chdir "contrib") #t))
679 ;; There is no install target
681 (lambda* (#:key outputs #:allow-other-keys)
682 (let* ((out (assoc-ref outputs "out"))
683 (lib (string-append out "/lib/"))
684 (inc (string-append out "/include/")))
685 (install-file "../build/libeight_bit_int_gemm.so" lib)
686 (for-each (lambda (dir)
687 (let ((target (string-append inc "/" dir)))
689 (for-each (lambda (h)
690 (install-file h target))
691 (find-files (string-append "../" dir)
693 '("meta" "profiling" "public" "fixedpoint"
694 "eight_bit_int_gemm" "internal"))
698 (home-page "https://github.com/google/gemmlowp")
699 (synopsis "Small self-contained low-precision GEMM library")
701 "This is a small self-contained low-precision @dfn{general matrix
702 multiplication} (GEMM) library. It is not a full linear algebra library.
703 Low-precision means that the input and output matrix entries are integers on
704 at most 8 bits. To avoid overflow, results are internally accumulated on more
705 than 8 bits, and at the end only some significant 8 bits are kept.")
706 (license license:asl2.0))))
715 "http://dlib.net/files/dlib-" version ".tar.bz2"))
718 "1mljz02kwkrbggyncxv5fpnyjdybw2qihaacb3js8yfkw12vwpc2"))
719 (modules '((guix build utils)))
722 ;; Delete ~13MB of bundled dependencies.
723 (delete-file-recursively "dlib/external")
724 (delete-file-recursively "docs/dlib/external")
726 (build-system cmake-build-system)
729 (modify-phases %standard-phases
730 (add-after 'unpack 'disable-asserts
732 ;; config.h recommends explicitly enabling or disabling asserts
733 ;; when building as a shared library. By default neither is set.
734 (substitute* "dlib/config.h"
735 (("^//#define DLIB_DISABLE_ASSERTS") "#define DLIB_DISABLE_ASSERTS"))
737 (add-after 'disable-asserts 'disable-failing-tests
739 ;; One test times out on MIPS, so we need to disable it.
740 ;; Others are flaky on some platforms.
741 (let* ((system ,(or (%current-target-system)
743 (disabled-tests (cond
744 ((string-prefix? "mips64" system)
745 '("object_detector" ; timeout
747 ((string-prefix? "armhf" system)
748 '("learning_to_track"))
749 ((string-prefix? "i686" system)
754 (substitute* "dlib/test/makefile"
755 (((string-append "SRC \\+= " test "\\.cpp")) "")))
760 ;; No test target, so we build and run the unit tests here.
761 (let ((test-dir (string-append "../dlib-" ,version "/dlib/test")))
762 (with-directory-excursion test-dir
763 (invoke "make" "-j" (number->string (parallel-job-count)))
764 (invoke "./dtest" "--runall"))
766 (add-after 'install 'delete-static-library
767 (lambda* (#:key outputs #:allow-other-keys)
768 (delete-file (string-append (assoc-ref outputs "out")
772 `(("pkg-config" ,pkg-config)
781 ("openblas" ,openblas)
784 "Toolkit for making machine learning and data analysis applications in C++")
786 "Dlib is a modern C++ toolkit containing machine learning algorithms and
787 tools. It is used in both industry and academia in a wide range of domains
788 including robotics, embedded devices, mobile phones, and large high performance
789 computing environments.")
790 (home-page "http://dlib.net")
791 (license license:boost1.0)))
793 (define-public python-scikit-learn
795 (name "python-scikit-learn")
801 (url "https://github.com/scikit-learn/scikit-learn.git")
803 (file-name (git-file-name name version))
806 "0fkhwg3xn1s7ln9q1szq6kwc4jhwvjh8w4kmv9wcrqy7cq3lbv0d"))))
807 (build-system python-build-system)
810 (modify-phases %standard-phases
811 (add-after 'build 'build-ext
812 (lambda _ (invoke "python" "setup.py" "build_ext" "--inplace") #t))
815 ;; Restrict OpenBLAS threads to prevent segfaults while testing!
816 (setenv "OPENBLAS_NUM_THREADS" "1")
818 ;; Some tests require write access to $HOME.
819 (setenv "HOME" "/tmp")
821 (invoke "pytest" "sklearn" "-m" "not network")))
822 ;; FIXME: This fails with permission denied
823 (delete 'reset-gzip-timestamps))))
825 `(("openblas" ,openblas)))
827 `(("python-pytest" ,python-pytest)
828 ("python-pandas" ,python-pandas) ;for tests
829 ("python-cython" ,python-cython)))
831 `(("python-numpy" ,python-numpy)
832 ("python-scipy" ,python-scipy)))
833 (home-page "http://scikit-learn.org/")
834 (synopsis "Machine Learning in Python")
836 "Scikit-learn provides simple and efficient tools for data mining and
838 (license license:bsd-3)))
840 (define-public python2-scikit-learn
841 (package-with-python2 python-scikit-learn))
843 (define-public python-autograd
844 (let* ((commit "442205dfefe407beffb33550846434baa90c4de7")
846 (version (git-version "0.0.0" revision commit)))
848 (name "python-autograd")
849 (home-page "https://github.com/HIPS/autograd")
857 "189sv2xb0mwnjawa9z7mrgdglc1miaq93pnck26r28fi1jdwg0z4"))
858 (file-name (git-file-name name version))))
860 (build-system python-build-system)
862 `(("python-nose" ,python-nose)
863 ("python-pytest" ,python-pytest)))
865 `(("python-future" ,python-future)
866 ("python-numpy" ,python-numpy)))
868 `(#:phases (modify-phases %standard-phases
871 (invoke "py.test" "-v"))))))
872 (synopsis "Efficiently computes derivatives of NumPy code")
873 (description "Autograd can automatically differentiate native Python and
874 NumPy code. It can handle a large subset of Python's features, including loops,
875 ifs, recursion and closures, and it can even take derivatives of derivatives
876 of derivatives. It supports reverse-mode differentiation
877 (a.k.a. backpropagation), which means it can efficiently take gradients of
878 scalar-valued functions with respect to array-valued arguments, as well as
879 forward-mode differentiation, and the two can be composed arbitrarily. The
880 main intended application of Autograd is gradient-based optimization.")
881 (license license:expat))))
883 (define-public python2-autograd
884 (package-with-python2 python-autograd))
886 (define-public lightgbm
893 "https://github.com/Microsoft/LightGBM/archive/v"
897 "132zf0yk0545mg72hyzxm102g3hpb6ixx9hnf8zd2k55gas6cjj1"))
898 (file-name (string-append name "-" version ".tar.gz"))))
900 `(("python-pytest" ,python-pytest)
901 ("python-nose" ,python-nose)))
903 `(("openmpi" ,openmpi)))
905 `(("python-numpy" ,python-numpy)
906 ("python-scipy" ,python-scipy)))
911 (modify-phases %standard-phases
913 (lambda* (#:key outputs #:allow-other-keys)
914 (with-directory-excursion ,(string-append "../LightGBM-" version)
915 (invoke "pytest" "tests/c_api_test/test_.py")))))))
916 (build-system cmake-build-system)
917 (home-page "https://github.com/Microsoft/LightGBM")
918 (synopsis "Gradient boosting framework based on decision tree algorithms")
919 (description "LightGBM is a gradient boosting framework that uses tree
920 based learning algorithms. It is designed to be distributed and efficient with
921 the following advantages:
924 @item Faster training speed and higher efficiency
925 @item Lower memory usage
926 @item Better accuracy
927 @item Parallel and GPU learning supported (not enabled in this package)
928 @item Capable of handling large-scale data
930 (license license:expat)))
932 (define-public vowpal-wabbit
933 ;; Language bindings not included.
935 (name "vowpal-wabbit")
940 "https://github.com/JohnLangford/vowpal_wabbit/archive/"
944 "0clp2kb7rk5sckhllxjr5a651awf4s8dgzg4659yh4hf5cqnf0gr"))
945 (file-name (string-append name "-" version ".tar.gz"))))
951 (list (string-append "--with-boost="
952 (assoc-ref %build-inputs "boost")))))
953 (build-system gnu-build-system)
954 (home-page "https://github.com/JohnLangford/vowpal_wabbit")
955 (synopsis "Fast machine learning library for online learning")
956 (description "Vowpal Wabbit is a machine learning system with techniques
957 such as online, hashing, allreduce, reductions, learning2search, active, and
958 interactive learning.")
959 (license license:bsd-3)))
961 (define-public python2-fastlmm
963 (name "python2-fastlmm")
968 (uri (pypi-uri "fastlmm" version ".zip"))
971 "1q8c34rpmwkfy3r4d5172pzdkpfryj561897z9r3x22gq7813x1m"))))
972 (build-system python-build-system)
974 `(#:tests? #f ; some test files are missing
975 #:python ,python-2)) ; only Python 2.7 is supported
977 `(("python2-numpy" ,python2-numpy)
978 ("python2-scipy" ,python2-scipy)
979 ("python2-matplotlib" ,python2-matplotlib)
980 ("python2-pandas" ,python2-pandas)
981 ("python2-scikit-learn" ,python2-scikit-learn)
982 ("python2-pysnptools" ,python2-pysnptools)))
985 ("python2-cython" ,python2-cython)
986 ("python2-mock" ,python2-mock)
987 ("python2-nose" ,python2-nose)))
988 (home-page "http://research.microsoft.com/en-us/um/redmond/projects/mscompbio/fastlmm/")
989 (synopsis "Perform genome-wide association studies on large data sets")
991 "FaST-LMM, which stands for Factored Spectrally Transformed Linear Mixed
992 Models, is a program for performing both single-SNP and SNP-set genome-wide
993 association studies (GWAS) on extremely large data sets.")
994 (license license:asl2.0)))
996 ;; There have been no proper releases yet.
998 (let ((commit "2f95609f0bb085bd3a1dc5eb0a39f3edea59e606")
1002 (version (git-version "0" revision commit))
1006 (url "https://github.com/kaldi-asr/kaldi.git")
1008 (file-name (git-file-name name version))
1011 "082qh3pfi7hvncylp4xsmkfahbd7gb0whdfa4rwrx7fxk9rdh3kz"))))
1012 (build-system gnu-build-system)
1014 `(#:test-target "test"
1016 (modify-phases %standard-phases
1017 (add-after 'unpack 'chdir
1018 (lambda _ (chdir "src") #t))
1020 (lambda* (#:key build system inputs outputs #:allow-other-keys)
1021 (when (not (or (string-prefix? "x86_64" system)
1022 (string-prefix? "i686" system)))
1023 (substitute* "makefiles/linux_openblas.mk"
1024 (("-msse -msse2") "")))
1025 (substitute* "makefiles/default_rules.mk"
1026 (("/bin/bash") (which "bash")))
1027 (substitute* "Makefile"
1028 (("ext_depend: check_portaudio")
1030 (substitute* '("online/Makefile"
1031 "onlinebin/Makefile"
1032 "gst-plugin/Makefile")
1033 (("../../tools/portaudio/install")
1034 (assoc-ref inputs "portaudio")))
1036 ;; This `configure' script doesn't support variables passed as
1037 ;; arguments, nor does it support "prefix".
1038 (let ((out (assoc-ref outputs "out"))
1039 (openblas (assoc-ref inputs "openblas"))
1040 (openfst (assoc-ref inputs "openfst")))
1041 (substitute* "configure"
1042 (("check_for_slow_expf;") "")
1043 ;; This affects the RPATH and also serves as the installation
1045 (("KALDILIBDIR=`pwd`/lib")
1046 (string-append "KALDILIBDIR=" out "/lib")))
1047 (mkdir-p out) ; must exist
1048 (setenv "CONFIG_SHELL" (which "bash"))
1049 (setenv "OPENFST_VER" ,(package-version openfst))
1050 (invoke "./configure"
1053 (string-append "--openblas-root=" openblas)
1054 (string-append "--fst-root=" openfst)))))
1055 (add-after 'build 'build-ext-and-gstreamer-plugin
1057 (invoke "make" "-C" "online" "depend")
1058 (invoke "make" "-C" "online")
1059 (invoke "make" "-C" "onlinebin" "depend")
1060 (invoke "make" "-C" "onlinebin")
1061 (invoke "make" "-C" "gst-plugin" "depend")
1062 (invoke "make" "-C" "gst-plugin")
1064 ;; TODO: also install the executables.
1066 (lambda* (#:key outputs #:allow-other-keys)
1067 (let* ((out (assoc-ref outputs "out"))
1068 (inc (string-append out "/include"))
1069 (lib (string-append out "/lib")))
1071 ;; The build phase installed symlinks to the actual
1072 ;; libraries. Install the actual targets.
1073 (for-each (lambda (file)
1074 (let ((target (readlink file)))
1076 (install-file target lib)))
1077 (find-files lib "\\.so"))
1079 (for-each (lambda (file)
1080 (let ((target-dir (string-append inc "/" (dirname file))))
1081 (install-file file target-dir)))
1082 (find-files "." "\\.h"))
1083 (install-file "gst-plugin/libgstonlinegmmdecodefaster.so"
1084 (string-append lib "/gstreamer-1.0"))
1087 `(("alsa-lib" ,alsa-lib)
1088 ("gfortran" ,gfortran "lib")
1090 ("gstreamer" ,gstreamer)
1092 ("openblas" ,openblas)
1093 ("openfst" ,openfst)
1094 ("portaudio" ,portaudio)
1095 ("python" ,python)))
1097 `(("glib" ,glib "bin") ; glib-genmarshal
1100 ("pkg-config" ,pkg-config)
1102 (home-page "https://kaldi-asr.org/")
1103 (synopsis "Speech recognition toolkit")
1104 (description "Kaldi is an extensible toolkit for speech recognition
1106 (license license:asl2.0))))
1108 (define-public gst-kaldi-nnet2-online
1109 (let ((commit "617e43e73c7cc45eb9119028c02bd4178f738c4a")
1112 (name "gst-kaldi-nnet2-online")
1113 (version (git-version "0" revision commit))
1117 (url "https://github.com/alumae/gst-kaldi-nnet2-online.git")
1119 (file-name (git-file-name name version))
1122 "0xh3w67b69818s6ib02ara4lw7wamjdmh4jznvkpzrs4skbs9jx9"))))
1123 (build-system gnu-build-system)
1125 `(#:tests? #f ; there are none
1127 (list (string-append "SHELL="
1128 (assoc-ref %build-inputs "bash") "/bin/bash")
1129 (string-append "KALDI_ROOT="
1130 (assoc-ref %build-inputs "kaldi-src"))
1131 (string-append "KALDILIBDIR="
1132 (assoc-ref %build-inputs "kaldi") "/lib")
1133 "KALDI_FLAVOR=dynamic")
1135 (modify-phases %standard-phases
1136 (add-after 'unpack 'chdir
1137 (lambda _ (chdir "src") #t))
1139 (lambda* (#:key inputs #:allow-other-keys)
1140 (let ((glib (assoc-ref inputs "glib")))
1141 (setenv "CXXFLAGS" "-std=c++11 -fPIC")
1142 (setenv "CPLUS_INCLUDE_PATH"
1143 (string-append glib "/include/glib-2.0:"
1144 glib "/lib/glib-2.0/include:"
1145 (assoc-ref inputs "gstreamer")
1146 "/include/gstreamer-1.0:"
1147 (getenv "CPLUS_INCLUDE_PATH"))))
1148 (substitute* "Makefile"
1149 (("include \\$\\(KALDI_ROOT\\)/src/kaldi.mk") "")
1150 (("\\$\\(error Cannot find") "#"))))
1151 (add-before 'build 'build-depend
1152 (lambda* (#:key make-flags #:allow-other-keys)
1153 (apply invoke "make" "depend" make-flags)))
1155 (lambda* (#:key outputs #:allow-other-keys)
1156 (let* ((out (assoc-ref outputs "out"))
1157 (lib (string-append out "/lib/gstreamer-1.0")))
1158 (install-file "libgstkaldinnet2onlinedecoder.so" lib)
1162 ("gstreamer" ,gstreamer)
1163 ("jansson" ,jansson)
1164 ("openfst" ,openfst)
1168 ("glib:bin" ,glib "bin") ; glib-genmarshal
1169 ("kaldi-src" ,(package-source kaldi))
1170 ("pkg-config" ,pkg-config)))
1171 (home-page "https://kaldi-asr.org/")
1172 (synopsis "Gstreamer plugin for decoding speech")
1173 (description "This package provides a GStreamer plugin that wraps
1174 Kaldi's @code{SingleUtteranceNnet2Decoder}. It requires iVector-adapted DNN
1175 acoustic models. The iVectors are adapted to the current audio stream
1177 (license license:asl2.0))))
1179 (define-public kaldi-gstreamer-server
1180 (let ((commit "1735ba49c5dc0ebfc184e45105fc600cd9f1f508")
1183 (name "kaldi-gstreamer-server")
1184 (version (git-version "0" revision commit))
1188 (url "https://github.com/alumae/kaldi-gstreamer-server.git")
1190 (file-name (git-file-name name version))
1193 "0j701m7lbwmzqxsfanj882v7881hrbmpqybbczbxqpcbg8q34w0k"))))
1194 (build-system gnu-build-system)
1196 `(#:tests? #f ; there are no tests that can be run automatically
1197 #:modules ((guix build utils)
1198 (guix build gnu-build-system)
1201 (modify-phases %standard-phases
1204 (lambda* (#:key outputs #:allow-other-keys)
1205 ;; Disable hash randomization to ensure the generated .pycs
1206 ;; are reproducible.
1207 (setenv "PYTHONHASHSEED" "0")
1208 (with-directory-excursion "kaldigstserver"
1209 (for-each (lambda (file)
1213 "-f" ; force rebuild
1215 (find-files "." "\\.py$")))
1218 (lambda* (#:key inputs outputs #:allow-other-keys)
1219 (let* ((out (assoc-ref outputs "out"))
1220 (bin (string-append out "/bin"))
1221 (share (string-append out "/share/kaldi-gstreamer-server/")))
1222 ;; Install Python files
1223 (with-directory-excursion "kaldigstserver"
1224 (for-each (cut install-file <> share)
1225 (find-files "." ".*")))
1227 ;; Install sample configuration files
1228 (for-each (cut install-file <> share)
1229 (find-files "." "\\.yaml"))
1231 ;; Install executables
1233 (let* ((server (string-append bin "/kaldi-gst-server"))
1234 (client (string-append bin "/kaldi-gst-client"))
1235 (worker (string-append bin "/kaldi-gst-worker"))
1236 (PYTHONPATH (getenv "PYTHONPATH"))
1237 (GST_PLUGIN_PATH (string-append
1238 (assoc-ref inputs "gst-kaldi-nnet2-online")
1239 "/lib/gstreamer-1.0:${GST_PLUGIN_PATH}"))
1240 (wrap (lambda (wrapper what)
1241 (with-output-to-file wrapper
1245 export PYTHONPATH=~a
1246 export GST_PLUGIN_PATH=~a
1247 exec ~a ~a/~a \"$@\"~%"
1248 (which "bash") PYTHONPATH GST_PLUGIN_PATH
1249 (which "python") share what)))
1250 (chmod wrapper #o555))))
1252 (list server client worker)
1253 (list "master_server.py"
1258 `(("gst-kaldi-nnet2-online" ,gst-kaldi-nnet2-online)
1259 ("python2" ,python-2)
1260 ("python2-futures" ,python2-futures)
1261 ("python2-pygobject" ,python2-pygobject)
1262 ("python2-pyyaml" ,python2-pyyaml)
1263 ("python2-tornado" ,python2-tornado)
1264 ("python2-ws4py" ,python2-ws4py-for-kaldi-gstreamer-server)))
1265 (home-page "https://github.com/alumae/kaldi-gstreamer-server")
1266 (synopsis "Real-time full-duplex speech recognition server")
1267 (description "This is a real-time full-duplex speech recognition server,
1268 based on the Kaldi toolkit and the GStreamer framework and implemented in
1270 (license license:bsd-2))))
1279 (url "https://github.com/grpc/grpc.git")
1280 (commit (string-append "v" version))))
1281 (file-name (git-file-name name version))
1284 "1jimqz3115f9pli5w6ik9wi7mjc7ix6y7yrq4a1ab9fc3dalj7p2"))))
1285 (build-system cmake-build-system)
1287 `(#:tests? #f ; no test target
1289 (list "-DgRPC_ZLIB_PROVIDER=package"
1290 "-DgRPC_CARES_PROVIDER=package"
1291 "-DgRPC_SSL_PROVIDER=package"
1292 "-DgRPC_PROTOBUF_PROVIDER=package")))
1294 `(("c-ares" ,c-ares-next)
1295 ("openssl" ,openssl)
1298 `(("protobuf" ,protobuf-next)
1299 ("python" ,python-wrapper)))
1300 (home-page "https://grpc.io")
1301 (synopsis "High performance universal RPC framework")
1302 (description "gRPC is a modern open source high performance @dfn{Remote
1303 Procedure Call} (RPC) framework that can run in any environment. It can
1304 efficiently connect services in and across data centers with pluggable support
1305 for load balancing, tracing, health checking and authentication. It is also
1306 applicable in last mile of distributed computing to connect devices, mobile
1307 applications and browsers to backend services.")
1308 (license license:asl2.0)))
1310 ;; Note that Tensorflow includes a "third_party" directory, which seems to not
1311 ;; only contain modified subsets of upstream library source code, but also
1312 ;; adapter headers provided by Google (such as the fft.h header, which is not
1313 ;; part of the upstream project code). The Tensorflow code includes headers
1314 ;; from the "third_party" directory. It does not look like we can replace
1315 ;; these headers with unmodified upstream files, so we keep them.
1316 (define-public tensorflow
1324 (url "https://github.com/tensorflow/tensorflow.git")
1325 (commit (string-append "v" version))))
1326 (file-name (string-append "tensorflow-" version "-checkout"))
1329 "0a9kwha395g3wgxfwln5j8vn9nkspmd75xldrlqdq540w996g8xa"))))
1330 (build-system cmake-build-system)
1332 `(#:tests? #f ; no "check" target
1333 #:build-type "Release"
1335 (let ((protobuf (assoc-ref %build-inputs "protobuf"))
1336 (protobuf:native (assoc-ref %build-inputs "protobuf:native"))
1337 (jsoncpp (assoc-ref %build-inputs "jsoncpp"))
1338 (snappy (assoc-ref %build-inputs "snappy"))
1339 (sqlite (assoc-ref %build-inputs "sqlite")))
1341 ;; Use protobuf from Guix
1342 (string-append "-Dprotobuf_STATIC_LIBRARIES="
1343 protobuf "/lib/libprotobuf.so")
1344 (string-append "-DPROTOBUF_PROTOC_EXECUTABLE="
1345 protobuf:native "/bin/protoc")
1347 ;; Use snappy from Guix
1348 (string-append "-Dsnappy_STATIC_LIBRARIES="
1349 snappy "/lib/libsnappy.so")
1350 ;; Yes, this is not actually the include directory but a prefix...
1351 (string-append "-Dsnappy_INCLUDE_DIR=" snappy)
1353 ;; Use jsoncpp from Guix
1354 (string-append "-Djsoncpp_STATIC_LIBRARIES="
1355 jsoncpp "/lib/libjsoncpp.so")
1356 ;; Yes, this is not actually the include directory but a prefix...
1357 (string-append "-Djsoncpp_INCLUDE_DIR=" jsoncpp)
1359 ;; Use sqlite from Guix
1360 (string-append "-Dsqlite_STATIC_LIBRARIES="
1361 sqlite "/lib/libsqlite.a")
1363 ;; Use system libraries wherever possible. Currently, this
1364 ;; only affects zlib.
1365 "-Dsystemlib_ALL=ON"
1366 "-Dtensorflow_ENABLE_POSITION_INDEPENDENT_CODE=ON"
1367 "-Dtensorflow_BUILD_SHARED_LIB=ON"
1368 "-Dtensorflow_OPTIMIZE_FOR_NATIVE_ARCH=OFF"
1369 "-Dtensorflow_ENABLE_SSL_SUPPORT=OFF"
1370 "-Dtensorflow_BUILD_CONTRIB_KERNELS=OFF"))
1373 #:modules ((ice-9 ftw)
1375 (guix build cmake-build-system))
1377 (modify-phases %standard-phases
1378 (add-after 'unpack 'set-source-file-times-to-1980
1379 ;; At the end of the tf_python_build_pip_package target, a ZIP
1380 ;; archive should be generated via bdist_wheel, but it fails with
1381 ;; "ZIP does not support timestamps before 1980". Luckily,
1382 ;; SOURCE_DATE_EPOCH is respected, which we set to some time in
1384 (lambda _ (setenv "SOURCE_DATE_EPOCH" "315532800") #t))
1385 ;; See https://github.com/tensorflow/tensorflow/issues/20517#issuecomment-406373913
1386 (add-after 'unpack 'python3.7-compatibility
1388 (substitute* '("tensorflow/python/eager/pywrap_tfe_src.cc"
1389 "tensorflow/python/lib/core/ndarray_tensor.cc"
1390 "tensorflow/python/lib/core/py_func.cc")
1391 (("PyUnicode_AsUTF8") "(char *)PyUnicode_AsUTF8"))
1392 (substitute* "tensorflow/c/eager/c_api.h"
1393 (("unsigned char async")
1394 "unsigned char is_async"))
1396 ;; Remove dependency on tensorboard, a complicated but probably
1397 ;; optional package.
1398 (substitute* "tensorflow/tools/pip_package/setup.py"
1399 ((".*'tensorboard >.*") ""))
1401 (add-after 'python3.7-compatibility 'chdir
1402 (lambda _ (chdir "tensorflow/contrib/cmake") #t))
1403 (add-after 'chdir 'disable-downloads
1404 (lambda* (#:key inputs #:allow-other-keys)
1405 (substitute* (find-files "external" "\\.cmake$")
1406 (("GIT_REPOSITORY.*") "")
1409 "DOWNLOAD_COMMAND \"\"\nPREFIX "))
1411 ;; Use packages from Guix
1412 (let ((grpc (assoc-ref inputs "grpc")))
1413 (substitute* "CMakeLists.txt"
1415 (("include\\(sqlite\\)") "")
1416 (("\\$\\{sqlite_STATIC_LIBRARIES\\}")
1417 (string-append (assoc-ref inputs "sqlite")
1418 "/lib/libsqlite3.so"))
1419 (("sqlite_copy_headers_to_destination") "")
1422 (("include\\(png\\)") "")
1423 (("\\$\\{png_STATIC_LIBRARIES\\}")
1424 (string-append (assoc-ref inputs "libpng")
1425 "/lib/libpng16.so"))
1426 (("png_copy_headers_to_destination") "")
1429 (("include\\(jpeg\\)") "")
1430 (("\\$\\{jpeg_STATIC_LIBRARIES\\}")
1431 (string-append (assoc-ref inputs "libjpeg")
1433 (("jpeg_copy_headers_to_destination") "")
1436 (("include\\(gif\\)") "")
1437 (("\\$\\{gif_STATIC_LIBRARIES\\}")
1438 (string-append (assoc-ref inputs "giflib")
1440 (("gif_copy_headers_to_destination") "")
1443 (("include\\(lmdb\\)") "")
1444 (("\\$\\{lmdb_STATIC_LIBRARIES\\}")
1445 (string-append (assoc-ref inputs "lmdb")
1447 (("lmdb_copy_headers_to_destination") "")
1450 (("include\\(protobuf\\)") "")
1451 (("protobuf_copy_headers_to_destination") "")
1452 (("^ +protobuf") "")
1455 (("include\\(grpc\\)")
1456 "find_package(grpc REQUIRED NAMES gRPC)")
1457 (("list\\(APPEND tensorflow_EXTERNAL_DEPENDENCIES grpc\\)") "")
1460 (("include\\(eigen\\)")
1461 (string-append "find_package(eigen REQUIRED NAMES Eigen3)
1462 set(eigen_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/external/eigen_archive "
1463 (assoc-ref inputs "eigen") "/include/eigen3)"))
1467 (("include\\(snappy\\)")
1468 "add_definitions(-DTF_USE_SNAPPY)")
1469 (("list\\(APPEND tensorflow_EXTERNAL_DEPENDENCIES snappy\\)") "")
1472 (("include\\(jsoncpp\\)") "")
1473 (("^ +jsoncpp") ""))
1475 (substitute* "tf_core_framework.cmake"
1477 (("\\$\\{GRPC_BUILD\\}/grpc_cpp_plugin")
1478 (which "grpc_cpp_plugin"))
1479 ;; Link with gRPC libraries
1480 (("add_library\\(tf_protos_cc.*" m)
1482 (format #f "\ntarget_link_libraries(tf_protos_cc PRIVATE \
1483 ~a/lib/libgrpc++_unsecure.a \
1484 ~a/lib/libgrpc_unsecure.a \
1485 ~a/lib/libaddress_sorting.a \
1490 (assoc-ref inputs "c-ares"))))))
1491 (substitute* "tf_tools.cmake"
1492 (("add_dependencies\\(\\$\\{proto_text.*") ""))
1493 ;; Remove dependency on bundled grpc
1494 (substitute* "tf_core_distributed_runtime.cmake"
1495 (("tf_core_cpu grpc") "tf_core_cpu"))
1497 ;; This directory is a dependency of many targets.
1498 (mkdir-p "protobuf")
1500 (add-after 'configure 'unpack-third-party-sources
1501 (lambda* (#:key inputs #:allow-other-keys)
1502 ;; This is needed to configure bundled packages properly.
1503 (setenv "CONFIG_SHELL" (which "bash"))
1506 (let* ((what (assoc-ref inputs (string-append name "-src")))
1507 (name* (string-map (lambda (c)
1510 (where (string-append "../build/" name* "/src/" name*)))
1512 ((string-suffix? ".zip" what)
1514 (with-directory-excursion where
1515 (invoke "unzip" what)))
1516 ((string-suffix? ".tar.gz" what)
1518 (invoke "tar" "xf" what
1519 "-C" where "--strip-components=1"))
1521 (let ((parent (dirname where)))
1523 (with-directory-excursion parent
1524 (when (file-exists? name*)
1525 (delete-file-recursively name*))
1526 (copy-recursively what name*)
1527 (map make-file-writable
1528 (find-files name* ".*"))))))))
1538 (rename-file "../build/cub/src/cub/cub-1.8.0/"
1539 "../build/cub/src/cub/cub/")
1541 (add-after 'unpack 'fix-python-build
1542 (lambda* (#:key inputs outputs #:allow-other-keys)
1543 (mkdir-p "protobuf-src")
1544 (invoke "tar" "xf" (assoc-ref inputs "protobuf:src")
1545 "-C" "protobuf-src" "--strip-components=1")
1546 (mkdir-p "eigen-src")
1547 (invoke "tar" "xf" (assoc-ref inputs "eigen:src")
1548 "-C" "eigen-src" "--strip-components=1")
1550 (substitute* "tensorflow/contrib/cmake/tf_python.cmake"
1551 ;; Ensure that all Python dependencies can be found at build time.
1552 (("PYTHONPATH=\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/tf_python" m)
1553 (string-append m ":" (getenv "PYTHONPATH")))
1554 ;; Take protobuf source files from our source package.
1555 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/protobuf/src/protobuf/src/google")
1556 (string-append (getcwd) "/protobuf-src/src/google")))
1558 (substitute* '("tensorflow/contrib/cmake/tf_shared_lib.cmake"
1559 "tensorflow/contrib/cmake/tf_python.cmake")
1560 ;; Take Eigen source files from our source package.
1561 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/eigen/src/eigen/")
1562 (string-append (getcwd) "/eigen-src/"))
1563 ;; Take Eigen headers from our own package.
1564 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/external/eigen_archive")
1565 (string-append (assoc-ref inputs "eigen") "/include/eigen3")))
1567 ;; Correct the RUNPATH of ops libraries generated for Python.
1568 ;; TODO: this doesn't work :(
1569 ;; /gnu/store/...-tensorflow-1.9.0/lib/python3.7/site-packages/tensorflow/contrib/seq2seq/python/ops/lib_beam_search_ops.so:
1570 ;; warning: RUNPATH contains bogus entries: ("/tmp/guix-build-tensorflow-1.9.0.drv-0/source/tensorflow/contrib/build")
1571 ;; /gnu/store/...-tensorflow-1.9.0/lib/python3.7/site-packages/tensorflow/contrib/seq2seq/python/ops/lib_beam_search_ops.so:
1572 ;; error: depends on 'libpywrap_tensorflow_internal.so', which
1573 ;; cannot be found in RUNPATH ...
1574 (substitute* "tensorflow/contrib/cmake/tf_cc_ops.cmake"
1575 (("set_target_properties.*")
1576 (string-append "set_target_properties(${_AT_TARGET} PROPERTIES \
1577 COMPILE_FLAGS ${target_compile_flags} \
1578 INSTALL_RPATH_USE_LINK_PATH TRUE \
1579 INSTALL_RPATH " (assoc-ref outputs "out") "/lib)\n")))
1581 (add-after 'build 'build-pip-package
1582 (lambda* (#:key outputs #:allow-other-keys)
1584 (string-append "-Wl,-rpath="
1585 (assoc-ref outputs "out") "/lib"))
1586 (invoke "make" "tf_python_build_pip_package")
1588 (add-after 'build-pip-package 'install-python
1589 (lambda* (#:key outputs #:allow-other-keys)
1590 (let ((out (assoc-ref outputs "out"))
1591 (wheel (car (find-files "../build/tf_python/dist/" "\\.whl$"))))
1592 (invoke "python" "-m" "pip" "install" wheel
1593 (string-append "--prefix=" out))
1595 ;; XXX: broken RUNPATH, see fix-python-build phase.
1598 out "/lib/python3.7/site-packages/tensorflow/contrib/"
1599 "seq2seq/python/ops/lib_beam_search_ops.so"))
1602 `(("pkg-config" ,pkg-config)
1603 ("protobuf:native" ,protobuf-next) ; protoc
1604 ("protobuf:src" ,(package-source protobuf-next))
1605 ("eigen:src" ,(package-source eigen-for-tensorflow))
1606 ;; The commit hashes and URLs for third-party source code are taken
1607 ;; from "tensorflow/workspace.bzl".
1609 ,(let ((commit "ee7aa02")
1614 (url "https://boringssl.googlesource.com/boringssl")
1616 (file-name (string-append "boringssl-0-" revision
1617 (string-take commit 7)
1621 "1jf693q0nw0adsic6cgmbdx6g7wr4rj4vxa8j1hpn792fqhd8wgw")))))
1623 ,(let ((version "1.8.0"))
1626 (uri (string-append "https://mirror.bazel.build/github.com/NVlabs/"
1627 "cub/archive/" version ".zip"))
1628 (file-name (string-append "cub-" version ".zip"))
1631 "1hsqikqridb90dkxkjr2918dcry6pfh46ccnwrzawl56aamhdykb")))))
1632 ("double-conversion-src"
1633 ,(let ((commit "5664746")
1638 (url "https://github.com/google/double-conversion.git")
1641 (git-file-name "double-conversion"
1642 (string-append "0-" revision "."
1643 (string-take commit 7))))
1646 "1h5lppqqxcvdg5jq42i5msgwx20ryij3apvmndflngrgdpc04gn1")))))
1648 ,(let ((commit "816a4ae622e964763ca0862d9dbd19324a1eaf45"))
1652 "https://mirror.bazel.build/github.com/google/farmhash/archive/"
1654 (file-name (string-append "farmhash-0-" (string-take commit 7)
1658 "185b2xdxl4d4cnsnv6abg8s22gxvx8673jq2yaq85bz4cdy58q35")))))
1659 ;; The license notice on the home page at
1660 ;; http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html says:
1661 ;; Copyright Takuya OOURA, 1996-2001
1663 ;; You may use, copy, modify and distribute this code for any purpose
1664 ;; (include commercial use) and without fee. Please refer to this
1665 ;; package when you modify this code.
1667 ;; We take the identical tarball from the Bazel mirror, because the URL
1668 ;; at the home page is not versioned and might change.
1672 (uri "https://mirror.bazel.build/www.kurims.kyoto-u.ac.jp/~ooura/fft.tgz")
1673 (file-name "fft2d.tar.gz")
1676 "15jjkfvhqvl2c0753d2di8hz0pyzn598g74wqy79awdrf1y67fsj"))))
1678 ,(let ((commit "be5edafc2e1a455768e260ccd68ae7317b6690ee")
1683 (url "https://github.com/google/highwayhash.git")
1685 (file-name (string-append "highwayhash-0-" revision
1686 (string-take commit 7)
1690 "154jwf98cyy54hldr94pgjn85zynly3abpnc1avmb8a18lzwjyb6")))))
1692 ,(let ((version "0559ce013feac8db639ee1bf776aca0325d28777")
1696 (uri (string-append "https://mirror.bazel.build/"
1697 "github.com/google/nsync/archive/"
1699 (file-name (string-append "nsync-0." revision
1700 "-" (string-take version 7)
1704 "0qdkyqym34x739mmzv97ah5r7ph462v5xkxqxvidmcfqbi64b132")))))
1706 ,(let ((commit "e7efc48")
1711 (url "https://github.com/google/re2")
1713 (file-name (string-append "re2-0-" revision
1714 (string-take commit 7)
1718 "161g9841rjfsy5pn52fcis0s9hdr7rxvb06pad38j5rppfihvign")))))
1719 ("googletest" ,googletest)
1723 `(("python-absl-py" ,python-absl-py)
1724 ("python-astor" ,python-astor)
1725 ("python-gast" ,python-gast)
1726 ("python-grpcio" ,python-grpcio)
1727 ("python-numpy" ,python-numpy)
1728 ("python-protobuf" ,python-protobuf-next)
1729 ("python-six" ,python-six)
1730 ("python-termcolo" ,python-termcolor)
1731 ("python-wheel" ,python-wheel)))
1733 `(("c-ares" ,c-ares-next)
1734 ("eigen" ,eigen-for-tensorflow)
1735 ("gemmlowp" ,gemmlowp-for-tensorflow)
1737 ("libjpeg" ,libjpeg)
1741 ("jsoncpp" ,jsoncpp-for-tensorflow)
1744 ("protobuf" ,protobuf-next)
1745 ("python" ,python-wrapper)
1747 (home-page "https://tensorflow.org")
1748 (synopsis "Machine learning framework")
1750 "TensorFlow is a flexible platform for building and training machine
1751 learning models. It provides a library for high performance numerical
1752 computation and includes high level Python APIs, including both a sequential
1753 API for beginners that allows users to build models quickly by plugging
1754 together building blocks and a subclassing API with an imperative style for
1755 advanced research.")
1756 (license license:asl2.0)))