gnu: r-opencyto: Update to 2.8.4.
[jackhill/guix/guix.git] / gnu / packages / machine-learning.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2016, 2020, 2021, 2022 Efraim Flashner <efraim@flashner.co.il>
4 ;;; Copyright © 2016, 2017, 2020 Marius Bakke <mbakke@fastmail.com>
5 ;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com>
6 ;;; Copyright © 2018, 2019, 2020 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>
13 ;;; Copyright © 2019 Nicolas Goaziou <mail@nicolasgoaziou.fr>
14 ;;; Copyright © 2019, 2020 Guillaume Le Vaillant <glv@posteo.net>
15 ;;; Copyright © 2019 Brett Gilio <brettg@gnu.org>
16 ;;; Copyright © 2020 Konrad Hinsen <konrad.hinsen@fastmail.net>
17 ;;; Copyright © 2020 Edouard Klein <edk@beaver-labs.com>
18 ;;; Copyright © 2020, 2021, 2022 Vinicius Monego <monego@posteo.net>
19 ;;; Copyright © 2020, 2021, 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
20 ;;;
21 ;;; This file is part of GNU Guix.
22 ;;;
23 ;;; GNU Guix is free software; you can redistribute it and/or modify it
24 ;;; under the terms of the GNU General Public License as published by
25 ;;; the Free Software Foundation; either version 3 of the License, or (at
26 ;;; your option) any later version.
27 ;;;
28 ;;; GNU Guix is distributed in the hope that it will be useful, but
29 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
30 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 ;;; GNU General Public License for more details.
32 ;;;
33 ;;; You should have received a copy of the GNU General Public License
34 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
35
36 (define-module (gnu packages machine-learning)
37 #:use-module ((guix licenses) #:prefix license:)
38 #:use-module (guix gexp)
39 #:use-module (guix packages)
40 #:use-module (guix utils)
41 #:use-module (guix download)
42 #:use-module (guix svn-download)
43 #:use-module (guix build-system cmake)
44 #:use-module (guix build-system gnu)
45 #:use-module (guix build-system ocaml)
46 #:use-module (guix build-system python)
47 #:use-module (guix build-system r)
48 #:use-module (guix git-download)
49 #:use-module (gnu packages)
50 #:use-module (gnu packages adns)
51 #:use-module (gnu packages algebra)
52 #:use-module (gnu packages audio)
53 #:use-module (gnu packages autotools)
54 #:use-module (gnu packages base)
55 #:use-module (gnu packages bash)
56 #:use-module (gnu packages boost)
57 #:use-module (gnu packages bdw-gc)
58 #:use-module (gnu packages check)
59 #:use-module (gnu packages compression)
60 #:use-module (gnu packages cmake)
61 #:use-module (gnu packages cpp)
62 #:use-module (gnu packages cran)
63 #:use-module (gnu packages databases)
64 #:use-module (gnu packages dejagnu)
65 #:use-module (gnu packages gcc)
66 #:use-module (gnu packages gettext)
67 #:use-module (gnu packages gl)
68 #:use-module (gnu packages glib)
69 #:use-module (gnu packages graphviz)
70 #:use-module (gnu packages gstreamer)
71 #:use-module (gnu packages guile)
72 #:use-module (gnu packages haskell-xyz)
73 #:use-module (gnu packages image)
74 #:use-module (gnu packages image-processing)
75 #:use-module (gnu packages imagemagick)
76 #:use-module (gnu packages jupyter)
77 #:use-module (gnu packages libffi)
78 #:use-module (gnu packages linux)
79 #:use-module (gnu packages llvm)
80 #:use-module (gnu packages maths)
81 #:use-module (gnu packages mpi)
82 #:use-module (gnu packages ninja)
83 #:use-module (gnu packages ocaml)
84 #:use-module (gnu packages onc-rpc)
85 #:use-module (gnu packages parallel)
86 #:use-module (gnu packages perl)
87 #:use-module (gnu packages pkg-config)
88 #:use-module (gnu packages protobuf)
89 #:use-module (gnu packages pulseaudio)
90 #:use-module (gnu packages python)
91 #:use-module (gnu packages python-build)
92 #:use-module (gnu packages python-check)
93 #:use-module (gnu packages python-science)
94 #:use-module (gnu packages python-web)
95 #:use-module (gnu packages python-xyz)
96 #:use-module (gnu packages rpc)
97 #:use-module (gnu packages serialization)
98 #:use-module (gnu packages sphinx)
99 #:use-module (gnu packages statistics)
100 #:use-module (gnu packages sqlite)
101 #:use-module (gnu packages swig)
102 #:use-module (gnu packages tls)
103 #:use-module (gnu packages video)
104 #:use-module (gnu packages web)
105 #:use-module (gnu packages xml)
106 #:use-module (gnu packages xorg)
107 #:use-module (ice-9 match))
108
109 (define-public fann
110 ;; The last release is >100 commits behind, so we package from git.
111 (let ((commit "d71d54788bee56ba4cf7522801270152da5209d7"))
112 (package
113 (name "fann")
114 (version (string-append "2.2.0-1." (string-take commit 8)))
115 (source (origin
116 (method git-fetch)
117 (uri (git-reference
118 (url "https://github.com/libfann/fann")
119 (commit commit)))
120 (file-name (string-append name "-" version "-checkout"))
121 (sha256
122 (base32
123 "0ibwpfrjs6q2lijs8slxjgzb2llcl6rk3v2ski4r6215g5jjhg3x"))))
124 (build-system cmake-build-system)
125 (arguments
126 `(#:phases
127 (modify-phases %standard-phases
128 (replace 'check
129 (lambda* (#:key outputs #:allow-other-keys)
130 (let* ((out (assoc-ref outputs "out")))
131 (with-directory-excursion (string-append (getcwd) "/tests")
132 (invoke "./fann_tests"))))))))
133 (home-page "http://leenissen.dk/fann/wp/")
134 (synopsis "Fast Artificial Neural Network")
135 (description
136 "FANN is a neural network library, which implements multilayer
137 artificial neural networks in C with support for both fully connected and
138 sparsely connected networks.")
139 (license license:lgpl2.1))))
140
141 (define-public libsvm
142 (package
143 (name "libsvm")
144 (version "3.23")
145 (source
146 (origin
147 (method url-fetch)
148 (uri (string-append "https://www.csie.ntu.edu.tw/~cjlin/libsvm/"
149 name "-" version ".tar.gz"))
150 (sha256
151 (base32 "0jpaq0rr92x38p4nk3gjan79ip67m6p80anb28z1d8601miysyi5"))))
152 (build-system gnu-build-system)
153 (arguments
154 `(#:tests? #f ; no "check" target
155 #:phases
156 (modify-phases %standard-phases
157 (delete 'configure)
158 (add-after 'build 'build-lib
159 (lambda _
160 (invoke "make" "lib")))
161 (replace 'install ; no ‘install’ target
162 (lambda* (#:key outputs #:allow-other-keys)
163 (let* ((out (assoc-ref outputs "out"))
164 (bin (string-append out "/bin/"))
165 (lib (string-append out "/lib/"))
166 (inc (string-append out "/include/libsvm")))
167 (mkdir-p bin)
168 (for-each (lambda (file)
169 (copy-file file (string-append bin file)))
170 '("svm-train"
171 "svm-predict"
172 "svm-scale"))
173 (mkdir-p lib)
174 (install-file "libsvm.so.2" lib)
175 (mkdir-p inc)
176 (install-file "svm.h" inc)))))))
177 (home-page "https://www.csie.ntu.edu.tw/~cjlin/libsvm/")
178 (synopsis "Library for Support Vector Machines")
179 (description
180 "LIBSVM is a machine learning library for support vector
181 classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and
182 distribution estimation (one-class SVM). It supports multi-class
183 classification.")
184 (license license:bsd-3)))
185
186 (define-public python-libsvm
187 (package (inherit libsvm)
188 (name "python-libsvm")
189 (build-system gnu-build-system)
190 (arguments
191 `(#:tests? #f ; no "check" target
192 #:make-flags '("-C" "python")
193 #:phases
194 (modify-phases %standard-phases
195 (delete 'configure)
196 (replace
197 'install ; no ‘install’ target
198 (lambda* (#:key inputs outputs #:allow-other-keys)
199 (let ((site (string-append (assoc-ref outputs "out")
200 "/lib/python"
201 (string-take
202 (string-take-right
203 (assoc-ref inputs "python") 5) 3)
204 "/site-packages/")))
205 (substitute* "python/svm.py"
206 (("../libsvm.so.2") "libsvm.so.2"))
207 (mkdir-p site)
208 (for-each (lambda (file)
209 (copy-file file (string-append site (basename file))))
210 (find-files "python" "\\.py"))
211 (copy-file "libsvm.so.2"
212 (string-append site "libsvm.so.2")))
213 #t)))))
214 (inputs
215 (list python))
216 (synopsis "Python bindings of libSVM")))
217
218 (define-public ghmm
219 ;; The latest release candidate is several years and a couple of fixes have
220 ;; been published since. This is why we download the sources from the SVN
221 ;; repository.
222 (let ((svn-revision 2341))
223 (package
224 (name "ghmm")
225 (version (string-append "0.9-rc3-0." (number->string svn-revision)))
226 (source (origin
227 (method svn-fetch)
228 (uri (svn-reference
229 (url "http://svn.code.sf.net/p/ghmm/code/trunk")
230 (revision svn-revision)))
231 (file-name (string-append name "-" version "-checkout"))
232 (sha256
233 (base32
234 "0qbq1rqp94l530f043qzp8aw5lj7dng9wq0miffd7spd1ff638wq"))))
235 (build-system gnu-build-system)
236 (arguments
237 `(#:imported-modules (,@%gnu-build-system-modules
238 (guix build python-build-system))
239 #:modules ((guix build python-build-system)
240 ,@%gnu-build-system-modules)
241 #:phases
242 (modify-phases %standard-phases
243 (add-after 'unpack 'enter-dir
244 (lambda _ (chdir "ghmm")))
245 (add-after 'enter-dir 'fix-runpath
246 (lambda* (#:key outputs #:allow-other-keys)
247 (substitute* "ghmmwrapper/setup.py"
248 (("^(.*)extra_compile_args = \\[" line indent)
249 (string-append indent
250 "extra_link_args = [\"-Wl,-rpath="
251 (assoc-ref outputs "out") "/lib\"],\n"
252 line
253 "\"-Wl,-rpath="
254 (assoc-ref outputs "out")
255 "/lib\", ")))))
256 (add-after 'enter-dir 'disable-broken-tests
257 (lambda _
258 (substitute* "tests/Makefile.am"
259 ;; GHMM_SILENT_TESTS is assumed to be a command.
260 (("TESTS_ENVIRONMENT.*") "")
261 ;; Do not build broken tests.
262 (("chmm .*") "")
263 (("read_fa .*") "")
264 (("mcmc .*") "")
265 (("label_higher_order_test.*$")
266 "label_higher_order_test\n"))
267
268 ;; These Python unittests are broken as there is no gato.
269 ;; See https://sourceforge.net/p/ghmm/support-requests/3/
270 (substitute* "ghmmwrapper/ghmmunittests.py"
271 (("^(.*)def (testNewXML|testMultipleTransitionClasses|testNewXML)"
272 line indent)
273 (string-append indent
274 "@unittest.skip(\"Disabled by Guix\")\n"
275 line))))))))
276 (inputs
277 `(("python" ,python-2) ; only Python 2 is supported
278 ("libxml2" ,libxml2)))
279 (native-inputs
280 (list pkg-config
281 dejagnu
282 swig
283 autoconf
284 automake
285 libtool))
286 (home-page "http://ghmm.org")
287 (synopsis "Hidden Markov Model library")
288 (description
289 "The General Hidden Markov Model library (GHMM) is a C library with
290 additional Python bindings implementing a wide range of types of @dfn{Hidden
291 Markov Models} (HMM) and algorithms: discrete, continuous emissions, basic
292 training, HMM clustering, HMM mixtures.")
293 (license license:lgpl2.0+))))
294
295 (define-public guile-aiscm
296 (package
297 (name "guile-aiscm")
298 (version "0.24.2")
299 (source (origin
300 (method git-fetch)
301 (uri (git-reference
302 (url "https://github.com/wedesoft/aiscm")
303 (commit "2e16e38391bf1638f1dd9a1cf4b25a25f6626078")))
304 (file-name (git-file-name name version))
305 (sha256
306 (base32
307 "1gwqpzl6irpaszkpxaf5wliwq19280632hlgxs3ikjkfg8mkqql0"))))
308 (build-system gnu-build-system)
309 (arguments
310 (list
311 #:configure-flags
312 #~(list (string-append "OPENCV_CFLAGS=-I" #$(this-package-input "opencv")
313 "/include/opencv4")
314 (let ((modules
315 (list "aruco" "barcode" "bgsegm" "bioinspired"
316 "calib3d" "ccalib" "core" "datasets" "dnn"
317 "dnn_objdetect" "dnn_superres" "dpm" "face"
318 "features2d" "flann" "freetype" "fuzzy" "hdf"
319 "hfs" "highgui" "img_hash" "imgcodecs" "imgproc"
320 "intensity_transform" "line_descriptor" "mcc"
321 "ml" "objdetect" "optflow" "phase_unwrapping"
322 "photo" "plot" "quality" "rapid" "reg" "rgbd"
323 "saliency" "shape" "stereo" "stitching"
324 "structured_light" "superres" "surface_matching"
325 "text" "tracking" "video" "videoio" "videostab"
326 "wechat_qrcode" "ximgproc" "xobjdetect" "xphoto")))
327 (format #false "OPENCV_LIBS=~{-lopencv_~a~^ ~}" modules)))
328 #:make-flags
329 #~(list (string-append "GUILE_CACHE=" #$output "/lib/guile/3.0/site-ccache")
330 (string-append "GUILE_EXT=" #$output "/lib/guile/3.0/extensions")
331 (string-append "GUILE_SITE=" #$output "/share/guile/site/3.0"))
332 #:phases
333 '(modify-phases %standard-phases
334 (add-after 'unpack 'build-reproducibly
335 (lambda _
336 (substitute* "doc/Makefile.am"
337 (("\\$\\(DATE\\)") "1970-01-01"))))
338 (add-after 'unpack 'find-clearsilver
339 (lambda* (#:key inputs #:allow-other-keys)
340 (substitute* "configure.ac"
341 (("/usr/local/include/ClearSilver")
342 (string-append (assoc-ref inputs "clearsilver")
343 "/include/ClearSilver")))
344 (substitute* "aiscm/Makefile.am"
345 (("-lneo_utl" m)
346 (string-append m " -lstreamhtmlparser")))
347 (setenv "C_INCLUDE_PATH"
348 (string-append (assoc-ref inputs "clearsilver")
349 "/include/ClearSilver:"
350 (or (getenv "C_INCLUDE_PATH") "")))))
351 (add-after 'unpack 'use-llvm-config
352 (lambda _
353 (substitute* "m4/ax_llvmc.m4"
354 (("llvm-config-11") "llvm-config")
355 ;; For some reason this library is not on the link list.
356 (("(LLVM_LIBS=\"\\$\\(\\$ac_llvm_config_path --libs \\$1\\))\"" _ m)
357 (string-append m " -lLLVMMCJIT\"")))
358
359 ;; Because of this message:
360 ;; symbol lookup error: ./.libs/libguile-aiscm-core.so: undefined symbol: LLVMInitializeX86TargetInfo
361 ;; This probably needs to differ when building on architectures
362 ;; other than x86_64.
363 (substitute* "aiscm/Makefile.am"
364 (("LLVM_LIBS\\)") "LLVM_LIBS) \
365 -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Info"))))
366 ;; This test fails because our version of tensorflow is too old
367 ;; to provide tf-string-length.
368 (add-after 'unpack 'disable-broken-test
369 (lambda _
370 (substitute* "tests/test_tensorflow.scm"
371 (("\\(test-eqv \"determine string length" m)
372 (string-append "#;" m)))))
373 ;; Use Clang instead of GCC.
374 (add-before 'configure 'prepare-build-environment
375 (lambda _
376 (setenv "AR" "llvm-ar")
377 (setenv "NM" "llvm-nm")
378 (setenv "CC" "clang")
379 (setenv "CXX" "clang++"))))))
380 (inputs
381 (list clearsilver
382 ffmpeg-4
383 freeglut
384 guile-3.0
385 imagemagick
386 libgc
387 libjpeg-turbo
388 libomp
389 libxi
390 libxmu
391 libxpm
392 libxt
393 libxv
394 mesa
395 mjpegtools
396 opencv
397 pandoc
398 pulseaudio
399 tensorflow))
400 (native-inputs
401 (list clang-11
402 llvm-11
403 pkg-config
404 protobuf-c
405 autoconf
406 automake
407 gettext-minimal
408 libtool
409 which))
410 (home-page "https://wedesoft.github.io/aiscm/")
411 (synopsis "Guile extension for numerical arrays and tensors")
412 (description "AIscm is a Guile extension for numerical arrays and tensors.
413 Performance is achieved by using the LLVM JIT compiler.")
414 (license license:gpl3+)))
415
416 (define-public guile-aiscm-next
417 (deprecated-package "guile-aiscm-next" guile-aiscm))
418
419 (define-public mcl
420 (package
421 (name "mcl")
422 (version "14.137")
423 (source (origin
424 (method url-fetch)
425 (uri (string-append
426 "http://micans.org/mcl/src/mcl-"
427 (string-replace-substring version "." "-")
428 ".tar.gz"))
429 (sha256
430 (base32
431 "15xlax3z31lsn62vlg94hkm75nm40q4679amnfg13jm8m2bnhy5m"))))
432 (build-system gnu-build-system)
433 (arguments
434 `(#:configure-flags (list "--enable-blast"
435 "CFLAGS=-fcommon")))
436 (inputs
437 (list perl))
438 (home-page "http://micans.org/mcl/")
439 (synopsis "Clustering algorithm for graphs")
440 (description
441 "The MCL algorithm is short for the @dfn{Markov Cluster Algorithm}, a
442 fast and scalable unsupervised cluster algorithm for graphs (also known as
443 networks) based on simulation of (stochastic) flow in graphs.")
444 ;; In the LICENCE file and web page it says "The software is licensed
445 ;; under the GNU General Public License, version 3.", but in several of
446 ;; the source code files it suggests GPL3 or later.
447 ;; http://listserver.ebi.ac.uk/pipermail/mcl-users/2016/000376.html
448 (license license:gpl3)))
449
450 (define-public ocaml-mcl
451 (package
452 (name "ocaml-mcl")
453 (version "12-068oasis4")
454 (source
455 (origin
456 (method git-fetch)
457 (uri (git-reference
458 (url "https://github.com/fhcrc/mcl")
459 (commit version)))
460 (file-name (git-file-name name version))
461 (sha256
462 (base32
463 "0009dc3h2jp3qg5val452wngpqnbfyhbcxylghq0mrjqxx0jdq5p"))))
464 (build-system ocaml-build-system)
465 (arguments
466 `(#:phases
467 (modify-phases %standard-phases
468 (add-before 'configure 'patch-paths
469 (lambda _
470 (substitute* "setup.ml"
471 (("LDFLAGS=-fPIC")
472 (string-append "LDFLAGS=-fPIC\"; \"SHELL=" (which "sh")))
473 (("-std=c89") "-std=gnu99 -fcommon")
474
475 ;; This is a mutable string, which is no longer supported. Use
476 ;; a byte buffer instead.
477 (("String.make \\(String.length s\\)")
478 "Bytes.make (String.length s)")
479
480 ;; These two belong together.
481 (("OASISString.replace_chars")
482 "Bytes.to_string (OASISString.replace_chars")
483 ((" s;")
484 " s);"))
485 (substitute* "myocamlbuild.ml"
486 (("std=c89") "std=gnu99 -fcommon"))
487 ;; Since we build with a more recent OCaml, we have to use C99 or
488 ;; later. This causes problems with the old C code.
489 (substitute* "src/impala/matrix.c"
490 (("restrict") "restrict_"))
491 #t)))))
492 (native-inputs
493 (list ocamlbuild))
494 (home-page "https://github.com/fhcrc/mcl")
495 (synopsis "OCaml wrappers around MCL")
496 (description
497 "This package provides OCaml bindings for the MCL graph clustering
498 algorithm.")
499 (license license:gpl3)))
500
501 (define-public randomjungle
502 (package
503 (name "randomjungle")
504 (version "2.1.0")
505 (source
506 (origin
507 (method url-fetch)
508 (uri (string-append
509 "https://www.imbs.uni-luebeck.de/fileadmin/files/Software"
510 "/randomjungle/randomjungle-" version ".tar_.gz"))
511 (patches (search-patches "randomjungle-disable-static-build.patch"))
512 (sha256
513 (base32
514 "12c8rf30cla71swx2mf4ww9mfd8jbdw5lnxd7dxhyw1ygrvg6y4w"))))
515 (build-system gnu-build-system)
516 (arguments
517 `(#:configure-flags
518 (list "--disable-static"
519 (string-append "--with-boost="
520 (assoc-ref %build-inputs "boost")))
521 #:phases
522 (modify-phases %standard-phases
523 (add-after 'unpack 'fix-compatibility-errors
524 (lambda _
525 (substitute* "src/library/IAM2WayImportance.h"
526 (("= std::make_pair.*")
527 "= std::minmax(varID1, varID2);"))
528 (substitute* "src/library/DataFrame.h"
529 (("isFirst\\?.*")
530 "if (isFirst) { isFirst = false; } else { os << par.delimiter; }\n"))))
531 (add-before 'configure 'set-CXXFLAGS
532 (lambda _ (setenv "CXXFLAGS" "-fpermissive "))))))
533 (inputs
534 (list boost gsl libxml2 zlib))
535 (native-inputs
536 `(("gfortran" ,gfortran)
537 ("gfortran:lib" ,gfortran "lib")))
538 ;; Non-portable assembly instructions are used so building fails on
539 ;; platforms other than x86_64 or i686.
540 (supported-systems '("x86_64-linux" "i686-linux"))
541 (home-page "https://www.imbs.uni-luebeck.de/forschung/software/details.html#c224")
542 (synopsis "Implementation of the Random Forests machine learning method")
543 (description
544 "Random Jungle is an implementation of Random Forests. It is supposed to
545 analyse high dimensional data. In genetics, it can be used for analysing big
546 Genome Wide Association (GWA) data. Random Forests is a powerful machine
547 learning method. Most interesting features are variable selection, missing
548 value imputation, classifier creation, generalization error estimation and
549 sample proximities between pairs of cases.")
550 (license license:gpl3+)))
551
552 (define-public openfst
553 (package
554 (name "openfst")
555 (version "1.8.2")
556 (source (origin
557 (method url-fetch)
558 (uri (string-append "http://www.openfst.org/twiki/pub/FST/"
559 "FstDownload/openfst-" version ".tar.gz"))
560 (sha256
561 (base32
562 "0hlbdmjjf1jgsvi3d2hwni5lz3l9a5bzj6ijpbawa8a7cbrpp66y"))))
563 (build-system gnu-build-system)
564 (arguments '(#:configure-flags '("--enable-ngram-fsts")))
565 (home-page "http://www.openfst.org")
566 (synopsis "Library for weighted finite-state transducers")
567 (description "OpenFst is a library for constructing, combining,
568 optimizing, and searching weighted finite-state transducers (FSTs).")
569 (license license:asl2.0)))
570
571 ;; This is a temporary addition to bypass upstream issues with the kaldi
572 ;; package.
573 (define-public openfst-1.7.3
574 (package (inherit openfst)
575 (version "1.7.3")
576 (source (origin
577 (method url-fetch)
578 (uri (string-append "http://www.openfst.org/twiki/pub/FST/"
579 "FstDownload/openfst-" version ".tar.gz"))
580 (sha256
581 (base32
582 "038a60w7y8qnbxmcrsim9rafz9mihsny8xv50jpzlr7rl166pp5q"))))
583 (arguments '(#:configure-flags '("--enable-ngram-fsts" "CXXFLAGS=-std=c++14")
584 #:make-flags '("CXXFLAGS=-std=c++14")))))
585
586 (define-public shogun
587 (package
588 (name "shogun")
589 (version "6.1.3")
590 (source
591 (origin
592 (method url-fetch)
593 (uri (string-append
594 "ftp://shogun-toolbox.org/shogun/releases/"
595 (version-major+minor version)
596 "/sources/shogun-" version ".tar.bz2"))
597 (sha256
598 (base32
599 "1rn9skm3nw6hr7mr3lgp2gfqhi7ii0lyxck7qmqnf8avq349s5jp"))
600 (modules '((guix build utils)
601 (ice-9 rdelim)))
602 (snippet
603 '(begin
604 ;; Remove non-free sources and files referencing them
605 (for-each delete-file
606 (find-files "src/shogun/classifier/svm/"
607 "SVMLight\\.(cpp|h)"))
608 (for-each delete-file
609 (find-files "examples/undocumented/libshogun/"
610 (string-append
611 "(classifier_.*svmlight.*|"
612 "evaluation_cross_validation_locked_comparison).cpp")))
613 ;; Remove non-free functions.
614 (define (delete-ifdefs file)
615 (with-atomic-file-replacement file
616 (lambda (in out)
617 (let loop ((line (read-line in 'concat))
618 (skipping? #f))
619 (if (eof-object? line)
620 #t
621 (let ((skip-next?
622 (or (and skipping?
623 (not (string-prefix?
624 "#endif //USE_SVMLIGHT" line)))
625 (string-prefix?
626 "#ifdef USE_SVMLIGHT" line))))
627 (when (or (not skipping?)
628 (and skipping? (not skip-next?)))
629 (display line out))
630 (loop (read-line in 'concat) skip-next?)))))))
631 (for-each delete-ifdefs
632 (append
633 (find-files "src/shogun/classifier/mkl"
634 "^MKLClassification\\.cpp")
635 (find-files "src/shogun/classifier/svm"
636 "^SVMLightOneClass\\.(cpp|h)")
637 (find-files "src/shogun/multiclass"
638 "^ScatterSVM\\.(cpp|h)")
639 (find-files "src/shogun/kernel/"
640 "^(Kernel|CombinedKernel|ProductKernel)\\.(cpp|h)")
641 (find-files "src/shogun/regression/svr"
642 "^(MKLRegression|SVRLight)\\.(cpp|h)")
643 (find-files "src/shogun/transfer/domain_adaptation"
644 "^DomainAdaptationSVM\\.(cpp|h)")))
645 #t))))
646 (build-system cmake-build-system)
647 (arguments
648 '(#:tests? #f ;no check target
649 #:phases
650 (modify-phases %standard-phases
651 (add-after 'unpack 'delete-broken-symlinks
652 (lambda _
653 (for-each delete-file '("applications/arts/data"
654 "applications/asp/data"
655 "applications/easysvm/data"
656 "applications/msplicer/data"
657 "applications/ocr/data"
658 "examples/meta/data"
659 "examples/undocumented/data"))
660 #t))
661 (add-after 'unpack 'change-R-target-path
662 (lambda* (#:key outputs #:allow-other-keys)
663 (substitute* '("src/interfaces/r/CMakeLists.txt"
664 "examples/meta/r/CMakeLists.txt")
665 (("\\$\\{R_COMPONENT_LIB_PATH\\}")
666 (string-append (assoc-ref outputs "out")
667 "/lib/R/library/")))
668 #t))
669 (add-after 'unpack 'fix-octave-modules
670 (lambda* (#:key outputs #:allow-other-keys)
671 (substitute* "src/interfaces/octave/CMakeLists.txt"
672 (("^include_directories\\(\\$\\{OCTAVE_INCLUDE_DIRS\\}")
673 "include_directories(${OCTAVE_INCLUDE_DIRS} ${OCTAVE_INCLUDE_DIRS}/octave")
674 ;; change target directory
675 (("\\$\\{OCTAVE_OCT_LOCAL_API_FILE_DIR\\}")
676 (string-append (assoc-ref outputs "out")
677 "/share/octave/packages")))
678 (substitute* '("src/interfaces/octave/swig_typemaps.i"
679 "src/interfaces/octave/sg_print_functions.cpp")
680 ;; "octave/config.h" and "octave/oct-obj.h" deprecated in Octave.
681 (("octave/config\\.h") "octave/octave-config.h")
682 (("octave/oct-obj.h") "octave/ovl.h"))
683 #t))
684 (add-after 'unpack 'move-rxcpp
685 (lambda* (#:key inputs #:allow-other-keys)
686 (let ((rxcpp-dir "shogun/third-party/rxcpp"))
687 (mkdir-p rxcpp-dir)
688 (install-file (assoc-ref inputs "rxcpp") rxcpp-dir)
689 #t)))
690 (add-before 'build 'set-HOME
691 ;; $HOME needs to be set at some point during the build phase
692 (lambda _ (setenv "HOME" "/tmp") #t)))
693 #:configure-flags
694 (list "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE"
695 "-DUSE_SVMLIGHT=OFF" ;disable proprietary SVMLIGHT
696 "-DBUILD_META_EXAMPLES=OFF" ;requires unpackaged ctags
697 ;;"-DINTERFACE_JAVA=ON" ;requires unpackaged jblas
698 ;;"-DINTERFACE_RUBY=ON" ;requires unpackaged ruby-narray
699 ;;"-DINTERFACE_PERL=ON" ;"FindPerlLibs" does not exist
700 ;;"-DINTERFACE_LUA=ON" ;fails because lua doesn't build pkgconfig file
701 "-DINTERFACE_OCTAVE=ON"
702 "-DINTERFACE_PYTHON=ON"
703 "-DINTERFACE_R=ON")))
704 (inputs
705 `(("python" ,python)
706 ("numpy" ,python-numpy)
707 ("r-minimal" ,r-minimal)
708 ("octave" ,octave-cli)
709 ("swig" ,swig)
710 ("eigen" ,eigen)
711 ("hdf5" ,hdf5)
712 ("atlas" ,atlas)
713 ("arpack" ,arpack-ng)
714 ("lapack" ,lapack)
715 ("glpk" ,glpk)
716 ("libxml2" ,libxml2)
717 ("lzo" ,lzo)
718 ("zlib" ,zlib)))
719 (native-inputs
720 (list pkg-config rxcpp))
721 ;; Non-portable SSE instructions are used so building fails on platforms
722 ;; other than x86_64.
723 (supported-systems '("x86_64-linux"))
724 (home-page "https://shogun-toolbox.org/")
725 (synopsis "Machine learning toolbox")
726 (description
727 "The Shogun Machine learning toolbox provides a wide range of unified and
728 efficient Machine Learning (ML) methods. The toolbox seamlessly
729 combines multiple data representations, algorithm classes, and general purpose
730 tools. This enables both rapid prototyping of data pipelines and extensibility
731 in terms of new algorithms.")
732 (license license:gpl3+)))
733
734 (define-public onnx
735 (package
736 (name "onnx")
737 (version "1.12.0")
738 (source (origin
739 (method git-fetch)
740 (uri (git-reference
741 (url "https://github.com/onnx/onnx")
742 (commit (string-append "v" version))))
743 (sha256
744 (base32
745 "1g9f1hviksbn7gi6fnd0dsm7nf0w3yia0mjj33d9mggklrl0db6x"))
746 (file-name (git-file-name name version))
747 (patches (search-patches "onnx-use-system-googletest.patch"
748 "onnx-shared-libraries.patch"
749 "onnx-skip-model-downloads.patch"))
750 (modules '((guix build utils)))
751 (snippet '(delete-file-recursively "third_party"))))
752 (build-system python-build-system)
753 (arguments
754 '(#:phases (modify-phases %standard-phases
755 (add-before 'build 'pass-cmake-arguments
756 (lambda* (#:key outputs #:allow-other-keys)
757 ;; Pass options to the CMake-based build process.
758 (define out
759 (assoc-ref outputs "out"))
760
761 (define args
762 ;; Copy arguments from 'cmake-build-system', plus ask
763 ;; for shared libraries.
764 (list "-DCMAKE_BUILD_TYPE=RelWithDebInfo"
765 (string-append "-DCMAKE_INSTALL_PREFIX=" out)
766 "-DCMAKE_INSTALL_LIBDIR=lib"
767 "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE"
768 (string-append "-DCMAKE_INSTALL_RPATH=" out
769 "/lib")
770 "-DCMAKE_VERBOSE_MAKEFILE=ON"
771
772 "-DBUILD_SHARED_LIBS=ON"))
773
774 ;; This environment variable is honored by 'setup.py',
775 ;; which passes it down to 'cmake'.
776 (setenv "CMAKE_ARGS" (string-join args))
777
778 ;; This one is honored by 'setup.py' and passed to 'make
779 ;; -j'.
780 (setenv "MAX_JOBS"
781 (number->string (parallel-job-count)))))
782 (add-before 'check 'make-test-directory-writable
783 (lambda _
784 ;; Make things writable for tests.
785 (setenv "HOME" (getcwd))
786 (for-each make-file-writable
787 (find-files "onnx/examples" "."
788 #:directories? #t))))
789 (add-after 'install 'install-from-cmake
790 (lambda _
791 ;; Run "make install" in the build tree 'setup.py'
792 ;; created for CMake so that libonnx.so,
793 ;; libonnx_proto.so, etc. are installed.
794 (invoke "make" "install"
795 "-C" ".setuptools-cmake-build"))))))
796 (native-inputs
797 (list cmake
798 googletest
799 pybind11
800 python-coverage
801 python-nbval
802 python-pytest
803 python-pytest-runner))
804 (inputs
805 (list protobuf))
806 (propagated-inputs
807 (list python-numpy python-protobuf python-six python-tabulate
808 python-typing-extensions))
809 (home-page "https://onnx.ai/")
810 (synopsis "Open Neural Network Exchange")
811 (description
812 "@acronym{ONNX, Open Neural Network Exchange} is a format for AI models,
813 both deep learning and traditional @acronym{ML, machine learning}. It defines
814 an extensible computation graph model, as well as definitions of built-in
815 operators and standard data types.")
816 (license license:expat)))
817
818 (define-public python-onnx
819 ;; This used to be called "python-onnx" because it provided nothing but
820 ;; Python bindings. The package now provides shared libraries and C++
821 ;; headers, hence the name change.
822 (deprecated-package "python-onnx" onnx))
823
824 (define-public onnx-optimizer
825 (package
826 (name "onnx-optimizer")
827 ;; Note: 0.2.x is *more* recent than 1.5.0.
828 (version "0.2.6")
829 (home-page "https://github.com/onnx/optimizer")
830 (source (origin
831 (method git-fetch)
832 (uri (git-reference
833 (url home-page)
834 (commit (string-append "v" version))))
835 (sha256
836 (base32
837 "1wkqqdxcxpfbf8zpbdfdd3zz5jkw775g31gyykj11z4y6pp659l6"))
838 (file-name (git-file-name name version))
839 (patches (search-patches "onnx-optimizer-system-library.patch"))
840 (modules '((guix build utils)))
841 (snippet '(delete-file-recursively "third_party"))))
842 (build-system python-build-system)
843 (arguments (package-arguments onnx)) ;reuse build system tweaks
844 (native-inputs
845 (list cmake python-pytest python-pytest-runner python-nbval
846 python-coverage))
847 (inputs
848 (list onnx protobuf pybind11))
849 (propagated-inputs
850 (list python-numpy))
851 (synopsis "Library to optimize ONNX models")
852 (description
853 "This package provides a C++ and Python library for performing arbitrary
854 optimizations on ONNX models, as well as a growing list of prepackaged
855 optimization passes.
856
857 Not all possible optimizations can be directly implemented on ONNX graphs---
858 some will need additional backend-specific information---but many can, and the
859 aim is to provide all such passes along with ONNX so that they can be re-used
860 with a single function call.")
861 (license license:expat)))
862
863 (define-public rxcpp
864 (package
865 (name "rxcpp")
866 (version "4.1.0")
867 (source
868 (origin
869 (method git-fetch)
870 (uri (git-reference
871 (url "https://github.com/ReactiveX/RxCpp")
872 (commit (string-append "v" version))))
873 (sha256
874 (base32 "1rdpa3jlc181jd08nk437aar085h28i45s6nzrv65apb3xyyz0ij"))
875 (file-name (git-file-name name version))))
876 (build-system cmake-build-system)
877 (arguments
878 `(#:phases
879 (modify-phases %standard-phases
880 (add-after 'unpack 'remove-werror
881 (lambda _
882 (substitute* (find-files ".")
883 (("-Werror") ""))
884 #t))
885 (replace 'check
886 (lambda _
887 (invoke "ctest"))))))
888 (native-inputs
889 (list catch-framework))
890 (home-page "http://reactivex.io/")
891 (synopsis "Reactive Extensions for C++")
892 (description
893 "The Reactive Extensions for C++ (RxCpp) is a library of algorithms for
894 values-distributed-in-time. ReactiveX is a library for composing asynchronous
895 and event-based programs by using observable sequences.
896
897 It extends the observer pattern to support sequences of data and/or events and
898 adds operators that allow you to compose sequences together declaratively while
899 abstracting away concerns about things like low-level threading,
900 synchronization, thread-safety, concurrent data structures, and non-blocking
901 I/O.")
902 (license license:asl2.0)))
903
904
905 (define-public gemmlowp
906 (let ((commit "f9959600daa42992baace8a49544a00a743ce1b6")
907 (version "0.1")
908 (revision "1"))
909 (package
910 (name "gemmlowp")
911 (version (git-version version revision commit))
912 (home-page "https://github.com/google/gemmlowp")
913 (source (origin
914 (method git-fetch)
915 (uri (git-reference (url home-page) (commit commit)))
916 (file-name (git-file-name name version))
917 (sha256
918 (base32
919 "1hzfhlhzcb827aza6a7drydc67dw5fm3qfqilb9ibskan8dsf0c6"))))
920 (arguments
921 `(#:configure-flags
922 (list ,@(match (%current-system)
923 ((or "x86_64-linux" "i686-linux")
924 '("-DCMAKE_CXX_FLAGS=-msse2"))
925 (_ '())))
926 #:phases
927 (modify-phases %standard-phases
928 ;; This directory contains the CMakeLists.txt.
929 (add-after 'unpack 'chdir
930 (lambda _ (chdir "contrib") #t))
931 ;; There is no install target
932 (replace 'install
933 (lambda* (#:key outputs #:allow-other-keys)
934 (let* ((out (assoc-ref outputs "out"))
935 (lib (string-append out "/lib/"))
936 (inc (string-append out "/include/")))
937 (install-file "../build/libeight_bit_int_gemm.so" lib)
938 (for-each (lambda (dir)
939 (let ((target
940 (string-append inc "/gemmlowp/" dir)))
941 (for-each (lambda (h)
942 (install-file h target))
943 (find-files (string-append "../" dir)
944 "\\.h$"))))
945 '("meta" "profiling" "public" "fixedpoint"
946 "eight_bit_int_gemm" "internal"))))))))
947 (build-system cmake-build-system)
948 (synopsis "Small self-contained low-precision GEMM library")
949 (description
950 "This is a small self-contained low-precision @dfn{general matrix
951 multiplication} (GEMM) library. It is not a full linear algebra library.
952 Low-precision means that the input and output matrix entries are integers on
953 at most 8 bits. To avoid overflow, results are internally accumulated on more
954 than 8 bits, and at the end only some significant 8 bits are kept.")
955 (license license:asl2.0))))
956
957 (define-public gemmlowp-for-tensorflow
958 ;; The commit hash is taken from "tensorflow/workspace.bzl".
959 (let ((commit "38ebac7b059e84692f53e5938f97a9943c120d98")
960 (revision "2"))
961 (package
962 (inherit gemmlowp)
963 (version (git-version "0" revision commit))
964 (source (origin
965 (method url-fetch)
966 (uri (string-append "https://mirror.bazel.build/"
967 "github.com/google/gemmlowp/archive/"
968 commit ".zip"))
969 (file-name (string-append "gemmlowp-" version ".zip"))
970 (sha256
971 (base32
972 "0n56s2g8hrssm4w8qj1v58gfm56a04n9v992ixkmvk6zjiralzxq"))))
973 (arguments
974 (substitute-keyword-arguments (package-arguments gemmlowp)
975 ((#:phases phases)
976 `(modify-phases ,phases
977 (replace 'install
978 (lambda* (#:key outputs #:allow-other-keys)
979 (let* ((out (assoc-ref outputs "out"))
980 (lib (string-append out "/lib/"))
981 (inc (string-append out "/include/")))
982 (install-file "../build/libeight_bit_int_gemm.so" lib)
983 (for-each (lambda (dir)
984 ;; Note: Install headers straight into
985 ;; $includedir instead of $includedir/gemmlowp.
986 (let ((target (string-append inc "/" dir)))
987 (for-each (lambda (h)
988 (install-file h target))
989 (find-files (string-append "../" dir)
990 "\\.h$"))))
991 '("meta" "profiling" "public" "fixedpoint"
992 "eight_bit_int_gemm" "internal")))))))))
993 (native-inputs
994 (list unzip))
995 (properties '((hidden? . #t))))))
996
997 (define-public dlib
998 (package
999 (name "dlib")
1000 (version "19.20")
1001 (source (origin
1002 (method url-fetch)
1003 (uri (string-append
1004 "http://dlib.net/files/dlib-" version ".tar.bz2"))
1005 (sha256
1006 (base32
1007 "139jyi19qz37wwmmy48gil9d1kkh2r3w3bwdzabha6ayxmba96nz"))
1008 (modules '((guix build utils)))
1009 (snippet
1010 '(begin
1011 ;; Delete ~13MB of bundled dependencies.
1012 (delete-file-recursively "dlib/external")
1013 (delete-file-recursively "docs/dlib/external")
1014 #t))))
1015 (build-system cmake-build-system)
1016 (arguments
1017 `(#:configure-flags '("-DBUILD_SHARED_LIBS=ON")
1018 #:phases
1019 (modify-phases %standard-phases
1020 (add-after 'unpack 'disable-asserts
1021 (lambda _
1022 ;; config.h recommends explicitly enabling or disabling asserts
1023 ;; when building as a shared library. By default neither is set.
1024 (substitute* "dlib/config.h"
1025 (("^//#define DLIB_DISABLE_ASSERTS") "#define DLIB_DISABLE_ASSERTS"))
1026 #t))
1027 (add-after 'disable-asserts 'disable-failing-tests
1028 (lambda _
1029 ;; One test times out on MIPS, so we need to disable it.
1030 ;; Others are flaky on some platforms.
1031 (let* ((system ,(or (%current-target-system)
1032 (%current-system)))
1033 (disabled-tests (cond
1034 ((string-prefix? "mips64" system)
1035 '("object_detector" ; timeout
1036 "data_io"))
1037 ((string-prefix? "armhf" system)
1038 '("learning_to_track"))
1039 ((string-prefix? "i686" system)
1040 '("optimization"))
1041 (else '()))))
1042 (for-each
1043 (lambda (test)
1044 (substitute* "dlib/test/makefile"
1045 (((string-append "SRC \\+= " test "\\.cpp")) "")))
1046 disabled-tests)
1047 #t)))
1048 (replace 'check
1049 (lambda _
1050 ;; No test target, so we build and run the unit tests here.
1051 (let ((test-dir (string-append "../dlib-" ,version "/dlib/test")))
1052 (with-directory-excursion test-dir
1053 (invoke "make" "-j" (number->string (parallel-job-count)))
1054 (invoke "./dtest" "--runall"))
1055 #t))))))
1056 (native-inputs
1057 (list pkg-config
1058 ;; For tests.
1059 libnsl))
1060 (inputs
1061 `(("giflib" ,giflib)
1062 ("lapack" ,lapack)
1063 ("libjpeg" ,libjpeg-turbo)
1064 ("libpng" ,libpng)
1065 ("libx11" ,libx11)
1066 ("openblas" ,openblas)
1067 ("zlib" ,zlib)))
1068 (synopsis
1069 "Toolkit for making machine learning and data analysis applications in C++")
1070 (description
1071 "Dlib is a modern C++ toolkit containing machine learning algorithms and
1072 tools. It is used in both industry and academia in a wide range of domains
1073 including robotics, embedded devices, mobile phones, and large high performance
1074 computing environments.")
1075 (home-page "http://dlib.net")
1076 (license license:boost1.0)))
1077
1078 (define-public python-scikit-learn
1079 (package
1080 (name "python-scikit-learn")
1081 (version "1.1.2")
1082 (source
1083 (origin
1084 (method git-fetch)
1085 (uri (git-reference
1086 (url "https://github.com/scikit-learn/scikit-learn")
1087 (commit version)))
1088 (file-name (git-file-name name version))
1089 (sha256
1090 (base32
1091 "0wcngyfm2fl3vgyi2aq6j5fvky5185xjzgip64968wqj1hmir5nv"))))
1092 (build-system python-build-system)
1093 (arguments
1094 `(#:phases
1095 (modify-phases %standard-phases
1096 (add-before 'build 'configure
1097 (lambda _
1098 (setenv "SKLEARN_BUILD_PARALLEL"
1099 (number->string (parallel-job-count)))))
1100 (add-after 'build 'build-ext
1101 (lambda _ (invoke "python" "setup.py" "build_ext" "--inplace"
1102 "-j" (number->string (parallel-job-count)))))
1103 (replace 'check
1104 (lambda* (#:key tests? #:allow-other-keys)
1105 (when tests?
1106 ;; Restrict OpenBLAS threads to prevent segfaults while testing!
1107 (setenv "OPENBLAS_NUM_THREADS" "1")
1108
1109 ;; Some tests require write access to $HOME.
1110 (setenv "HOME" "/tmp")
1111
1112 ;; Step out of the source directory to avoid interference;
1113 ;; we want to run the installed code with extensions etc.
1114 (with-directory-excursion "/tmp"
1115 (invoke "pytest" "-vv" "--pyargs" "sklearn"
1116 "-m" "not network"
1117 "-n" (number->string (parallel-job-count))
1118 ;; This test tries to access the internet.
1119 "-k" "not test_load_boston_alternative"))))))))
1120 (inputs (list openblas))
1121 (native-inputs
1122 (list python-cython
1123 python-pandas
1124 python-pytest
1125 python-pytest-xdist))
1126 (propagated-inputs
1127 (list python-numpy python-threadpoolctl python-scipy python-joblib))
1128 (home-page "https://scikit-learn.org/")
1129 (synopsis "Machine Learning in Python")
1130 (description
1131 "Scikit-learn provides simple and efficient tools for data mining and
1132 data analysis.")
1133 (license license:bsd-3)))
1134
1135 (define-public python-threadpoolctl
1136 (package
1137 (name "python-threadpoolctl")
1138 (version "2.1.0")
1139 (source
1140 (origin
1141 (method url-fetch)
1142 (uri (pypi-uri "threadpoolctl" version))
1143 (sha256
1144 (base32
1145 "0szsxcm2fbxrn83iynn42bnvrdh7mfsmkhfn8pdn7swblfb7rifx"))))
1146 (build-system python-build-system)
1147 (arguments
1148 `(#:phases
1149 (modify-phases %standard-phases
1150 (replace 'check
1151 (lambda* (#:key tests? inputs outputs #:allow-other-keys)
1152 (when tests?
1153 (add-installed-pythonpath inputs outputs)
1154 (invoke "pytest"))
1155 #t)))))
1156 (native-inputs
1157 (list python-pytest))
1158 (home-page "https://github.com/joblib/threadpoolctl")
1159 (synopsis "Python helpers for common threading libraries")
1160 (description "Thread-pool Controls provides Python helpers to limit the
1161 number of threads used in the threadpool-backed of common native libraries used
1162 for scientific computing and data science (e.g. BLAS and OpenMP).")
1163 (license license:bsd-3)))
1164
1165 (define-public python-pynndescent
1166 (package
1167 (name "python-pynndescent")
1168 (version "0.5.6")
1169 (source
1170 (origin
1171 (method url-fetch)
1172 (uri (pypi-uri "pynndescent" version))
1173 (sha256
1174 (base32 "0p3jsdcprjfzz7qf5674dsqfpvdn6p4wgqikg7b6ki5abf433yv1"))))
1175 (build-system python-build-system)
1176 (arguments
1177 `(#:phases
1178 (modify-phases %standard-phases
1179 (replace 'check
1180 (lambda* (#:key inputs outputs tests? #:allow-other-keys)
1181 (when tests?
1182 (invoke "python" "-m" "pytest" "--pyargs" "pynndescent"
1183 ;; wminkowski no longer exists in scipy 1.8.0 (see:
1184 ;; https://github.com/lmcinnes/pynndescent/issues/177)
1185 "-k" "not test_weighted_minkowski")))))))
1186 (native-inputs (list python-pytest))
1187 (propagated-inputs
1188 (list python-joblib
1189 python-llvmlite
1190 python-numba
1191 python-scikit-learn
1192 python-scipy))
1193 (home-page "https://github.com/lmcinnes/pynndescent")
1194 (synopsis "Nearest neighbor descent for approximate nearest neighbors")
1195 (description
1196 "PyNNDescent provides a Python implementation of Nearest Neighbor Descent
1197 for k-neighbor-graph construction and approximate nearest neighbor search.")
1198 (license license:bsd-2)))
1199
1200 (define-public python-opentsne
1201 (package
1202 (name "python-opentsne")
1203 (version "0.6.1")
1204 (source
1205 (origin
1206 (method git-fetch) ; no tests in PyPI release
1207 (uri (git-reference
1208 (url "https://github.com/pavlin-policar/openTSNE")
1209 (commit (string-append "v" version))))
1210 (file-name (git-file-name name version))
1211 (sha256
1212 (base32 "124nid27lfq1ipfjd2gkynqcmb4khisjb4r05jv42ckfkk4dbsxs"))))
1213 (build-system python-build-system)
1214 (arguments
1215 `(#:phases
1216 (modify-phases %standard-phases
1217 ;; Benchmarks require the 'macosko2015' data files.
1218 (add-after 'unpack 'delete-benchmark
1219 (lambda _
1220 (delete-file-recursively "benchmarks")))
1221 (add-after 'unpack 'skip-test
1222 (lambda _ ;; TODO: figure out why this test fails.
1223 (substitute* "tests/test_correctness.py"
1224 (("def test_iris\\(self\\)") "def _test_iris(self)"))))
1225 ;; Numba needs a writable dir to cache functions.
1226 (add-before 'check 'set-numba-cache-dir
1227 (lambda _
1228 (setenv "NUMBA_CACHE_DIR" "/tmp"))))))
1229 (native-inputs
1230 (list python-cython))
1231 (inputs
1232 (list fftw))
1233 (propagated-inputs
1234 (list python-numpy python-pynndescent python-scikit-learn
1235 python-scipy))
1236 (home-page "https://github.com/pavlin-policar/openTSNE")
1237 (synopsis "Extensible, parallel implementations of t-SNE")
1238 (description
1239 "This is a modular Python implementation of t-Distributed Stochastic
1240 Neighbor Embedding (t-SNE), a popular dimensionality-reduction algorithm for
1241 visualizing high-dimensional data sets.")
1242 (license license:bsd-3)))
1243
1244 (define-public python-scikit-rebate
1245 (package
1246 (name "python-scikit-rebate")
1247 (version "0.62")
1248 (source (origin
1249 (method url-fetch)
1250 (uri (pypi-uri "skrebate" version))
1251 (sha256
1252 (base32
1253 "0n55ghvnv7rxqa5agq6a4892ad0ghha165b0g4ghwr9gqm6ss3dj"))))
1254 (build-system python-build-system)
1255 (arguments '(#:tests? #f)) ;no tests on PyPI and no tags in repo
1256 (propagated-inputs
1257 (list python-numpy python-scipy python-scikit-learn python-joblib))
1258 (home-page "https://epistasislab.github.io/scikit-rebate/")
1259 (synopsis "Relief-based feature selection algorithms for Python")
1260 (description "Scikit-rebate is a scikit-learn-compatible Python
1261 implementation of ReBATE, a suite of Relief-based feature selection algorithms
1262 for Machine Learning. These algorithms excel at identifying features that are
1263 predictive of the outcome in supervised learning problems, and are especially
1264 good at identifying feature interactions that are normally overlooked by
1265 standard feature selection algorithms.")
1266 (license license:expat)))
1267
1268 (define-public python-cmaes
1269 (package
1270 (name "python-cmaes")
1271 (version "0.8.2")
1272 (source
1273 (origin
1274 (method git-fetch) ;no tests in PyPI
1275 (uri (git-reference
1276 (url "https://github.com/CyberAgent/cmaes")
1277 (commit (string-append "v" version))))
1278 (sha256
1279 (base32 "1jyckaifir528dz6m95nvky8hvqmz5gz6dlp65baahhbca0danzb"))
1280 (file-name (git-file-name name version))))
1281 (build-system python-build-system)
1282 (native-inputs
1283 (list python-setuptools ;build fails without this
1284 python-wheel))
1285 (propagated-inputs
1286 (list python-numpy))
1287 (home-page "https://github.com/CyberAgent/cmaes")
1288 (synopsis "CMA-ES implementation for Python")
1289 (description "This package provides provides an implementation of the
1290 Covariance Matrix Adaptation Evolution Strategy (CMA-ES) for Python.")
1291 (license license:expat)))
1292
1293 (define-public python-autograd
1294 (let* ((commit "442205dfefe407beffb33550846434baa90c4de7")
1295 (revision "0")
1296 (version (git-version "0.0.0" revision commit)))
1297 (package
1298 (name "python-autograd")
1299 (home-page "https://github.com/HIPS/autograd")
1300 (source (origin
1301 (method git-fetch)
1302 (uri (git-reference
1303 (url home-page)
1304 (commit commit)))
1305 (sha256
1306 (base32
1307 "189sv2xb0mwnjawa9z7mrgdglc1miaq93pnck26r28fi1jdwg0z4"))
1308 (file-name (git-file-name name version))))
1309 (version version)
1310 (build-system python-build-system)
1311 (native-inputs
1312 (list python-nose python-pytest))
1313 (propagated-inputs
1314 (list python-future python-numpy))
1315 (arguments
1316 `(#:phases (modify-phases %standard-phases
1317 (replace 'check
1318 (lambda _
1319 (invoke "py.test" "-v"))))))
1320 (synopsis "Efficiently computes derivatives of NumPy code")
1321 (description "Autograd can automatically differentiate native Python and
1322 NumPy code. It can handle a large subset of Python's features, including loops,
1323 ifs, recursion and closures, and it can even take derivatives of derivatives
1324 of derivatives. It supports reverse-mode differentiation
1325 (a.k.a. backpropagation), which means it can efficiently take gradients of
1326 scalar-valued functions with respect to array-valued arguments, as well as
1327 forward-mode differentiation, and the two can be composed arbitrarily. The
1328 main intended application of Autograd is gradient-based optimization.")
1329 (license license:expat))))
1330
1331 (define-public lightgbm
1332 (package
1333 (name "lightgbm")
1334 (version "2.0.12")
1335 (source (origin
1336 (method git-fetch)
1337 (uri (git-reference
1338 (url "https://github.com/Microsoft/LightGBM")
1339 (commit (string-append "v" version))))
1340 (sha256
1341 (base32
1342 "0jlvyn7k81dzrh9ij3zw576wbgiwmmr26rzpdxjn1dbpc3njpvzi"))
1343 (file-name (git-file-name name version))))
1344 (native-inputs
1345 (list python-pytest python-nose))
1346 (inputs
1347 (list openmpi))
1348 (propagated-inputs
1349 (list python-numpy python-scipy))
1350 (arguments
1351 `(#:configure-flags
1352 '("-DUSE_MPI=ON")
1353 #:phases
1354 (modify-phases %standard-phases
1355 (replace 'check
1356 (lambda _
1357 (with-directory-excursion "../source"
1358 (invoke "pytest" "tests/c_api_test/test_.py")))))))
1359 (build-system cmake-build-system)
1360 (home-page "https://github.com/Microsoft/LightGBM")
1361 (synopsis "Gradient boosting framework based on decision tree algorithms")
1362 (description "LightGBM is a gradient boosting framework that uses tree
1363 based learning algorithms. It is designed to be distributed and efficient with
1364 the following advantages:
1365
1366 @itemize
1367 @item Faster training speed and higher efficiency
1368 @item Lower memory usage
1369 @item Better accuracy
1370 @item Parallel and GPU learning supported (not enabled in this package)
1371 @item Capable of handling large-scale data
1372 @end itemize\n")
1373 (license license:expat)))
1374
1375 (define-public vowpal-wabbit
1376 ;; Language bindings not included.
1377 (package
1378 (name "vowpal-wabbit")
1379 (version "8.5.0")
1380 (source (origin
1381 (method git-fetch)
1382 (uri (git-reference
1383 (url "https://github.com/JohnLangford/vowpal_wabbit")
1384 (commit version)))
1385 (sha256
1386 (base32
1387 "04bwzk6ifgnz3fmzid8b7avxf9n5pnx9xcjm61nkjng1vv0bpj8x"))
1388 (file-name (git-file-name name version))))
1389 (inputs
1390 (list boost zlib))
1391 (arguments
1392 `(#:configure-flags
1393 (list (string-append "--with-boost="
1394 (assoc-ref %build-inputs "boost")))
1395 #:phases
1396 (modify-phases %standard-phases
1397 (add-after 'unpack 'make-files-writable
1398 (lambda _
1399 (for-each make-file-writable (find-files "." ".*")) #t))
1400 (add-after 'install 'install-more-headers
1401 (lambda* (#:key outputs #:allow-other-keys)
1402 (for-each
1403 (lambda (file)
1404 (install-file file (string-append
1405 (assoc-ref outputs "out")
1406 "/include/vowpalwabbit")))
1407 (find-files "vowpalwabbit" "\\.h$"))
1408 #t)))))
1409 (build-system gnu-build-system)
1410 (home-page "https://github.com/JohnLangford/vowpal_wabbit")
1411 (synopsis "Fast machine learning library for online learning")
1412 (description "Vowpal Wabbit is a machine learning system with techniques
1413 such as online, hashing, allreduce, reductions, learning2search, active, and
1414 interactive learning.")
1415 (license license:bsd-3)))
1416
1417 (define-public python-hyperopt
1418 (package
1419 (name "python-hyperopt")
1420 (version "0.2.5")
1421 (source
1422 (origin
1423 (method url-fetch)
1424 (uri (pypi-uri "hyperopt" version))
1425 (sha256
1426 (base32 "1k4ma8ci0bxghw7g4ms944zak1pi83yv2d6bxd7fcslm1zalfq5w"))))
1427 (build-system python-build-system)
1428 (arguments
1429 `(#:phases
1430 (modify-phases %standard-phases
1431 (replace 'check
1432 (lambda* (#:key inputs outputs tests? #:allow-other-keys)
1433 (when tests?
1434 (add-installed-pythonpath inputs outputs)
1435 (invoke "python" "-m" "pytest" "--ignore"
1436 ;; Needs python-pyspark.
1437 "hyperopt/tests/test_spark.py"
1438 ;; Needs both python-scikit-learn and python-lightgbm.
1439 "--ignore" "hyperopt/tests/test_atpe_basic.py"
1440 ;; The tests below need python-lightgbm.
1441 "-k" (string-append "not test_branin"
1442 " and not test_distractor"
1443 " and not test_q1lognormal"
1444 " and not test_quadratic1"
1445 " and not test_twoarms"))))))))
1446 (propagated-inputs
1447 (list python-cloudpickle
1448 python-future
1449 python-networkx
1450 python-numpy
1451 python-scipy
1452 python-six
1453 python-tqdm))
1454 (native-inputs
1455 (list python-black
1456 python-ipython
1457 python-ipyparallel
1458 python-nose
1459 python-pymongo
1460 python-pytest))
1461 (home-page "https://hyperopt.github.io/hyperopt/")
1462 (synopsis "Library for hyperparameter optimization")
1463 (description "Hyperopt is a Python library for serial and parallel
1464 optimization over awkward search spaces, which may include real-valued,
1465 discrete, and conditional dimensions.")
1466 (license license:bsd-3)))
1467
1468 ;; There have been no proper releases yet.
1469 (define-public kaldi
1470 (let ((commit "dd107fd594ac58af962031c1689abfdc10f84452")
1471 (revision "0")
1472 (openfst openfst-1.7.3)) ;; Temporary bypass for upstream issues
1473 (package
1474 (name "kaldi")
1475 (version (git-version "0" revision commit))
1476 (source (origin
1477 (method git-fetch)
1478 (uri (git-reference
1479 (url "https://github.com/kaldi-asr/kaldi")
1480 (commit commit)))
1481 (file-name (git-file-name name version))
1482 (sha256
1483 (base32
1484 "0iqbzgn7gzmgwvjfzifpbwwidxx887qmlgmsjkg7b1yzyfv00l21"))))
1485 (build-system gnu-build-system)
1486 (arguments
1487 `(#:test-target "test"
1488 #:phases
1489 (modify-phases %standard-phases
1490 (add-after 'unpack 'chdir
1491 (lambda _ (chdir "src") #t))
1492 (replace 'configure
1493 (lambda* (#:key build system inputs outputs #:allow-other-keys)
1494 (when (not (or (string-prefix? "x86_64" system)
1495 (string-prefix? "i686" system)))
1496 (substitute* "makefiles/linux_openblas.mk"
1497 (("-msse -msse2") "")))
1498 (substitute* "makefiles/default_rules.mk"
1499 (("/bin/bash") (which "bash")))
1500 (substitute* "Makefile"
1501 (("ext_depend: check_portaudio")
1502 "ext_depend:"))
1503 (substitute* '("online/Makefile"
1504 "onlinebin/Makefile"
1505 "gst-plugin/Makefile")
1506 (("../../tools/portaudio/install")
1507 (assoc-ref inputs "portaudio")))
1508 (substitute* "matrix/Makefile" ;temporary test bypass
1509 (("matrix-lib-test sparse-matrix-test") ""))
1510
1511 ;; This `configure' script doesn't support variables passed as
1512 ;; arguments, nor does it support "prefix".
1513 (let ((out (assoc-ref outputs "out"))
1514 (openblas (assoc-ref inputs "openblas"))
1515 (openfst (assoc-ref inputs "openfst")))
1516 (substitute* "configure"
1517 (("check_for_slow_expf;") "")
1518 ;; This affects the RPATH and also serves as the installation
1519 ;; directory.
1520 (("KALDILIBDIR=`pwd`/lib")
1521 (string-append "KALDILIBDIR=" out "/lib")))
1522 (mkdir-p out) ; must exist
1523 (setenv "CONFIG_SHELL" (which "bash"))
1524 (setenv "OPENFST_VER" ,(package-version openfst))
1525 (invoke "./configure"
1526 "--use-cuda=no"
1527 "--shared"
1528 (string-append "--openblas-root=" openblas)
1529 (string-append "--fst-root=" openfst)))))
1530 (add-after 'build 'build-ext-and-gstreamer-plugin
1531 (lambda _
1532 (invoke "make" "-C" "online" "depend")
1533 (invoke "make" "-C" "online")
1534 (invoke "make" "-C" "onlinebin" "depend")
1535 (invoke "make" "-C" "onlinebin")
1536 (invoke "make" "-C" "gst-plugin" "depend")
1537 (invoke "make" "-C" "gst-plugin")
1538 #t))
1539 ;; TODO: also install the executables.
1540 (replace 'install
1541 (lambda* (#:key outputs #:allow-other-keys)
1542 (let* ((out (assoc-ref outputs "out"))
1543 (inc (string-append out "/include"))
1544 (lib (string-append out "/lib")))
1545 (mkdir-p lib)
1546 ;; The build phase installed symlinks to the actual
1547 ;; libraries. Install the actual targets.
1548 (for-each (lambda (file)
1549 (let ((target (readlink file)))
1550 (delete-file file)
1551 (install-file target lib)))
1552 (find-files lib "\\.so"))
1553 ;; Install headers
1554 (for-each (lambda (file)
1555 (let ((target-dir (string-append inc "/" (dirname file))))
1556 (install-file file target-dir)))
1557 (find-files "." "\\.h"))
1558 (install-file "gst-plugin/libgstonlinegmmdecodefaster.so"
1559 (string-append lib "/gstreamer-1.0"))
1560 #t))))))
1561 (inputs
1562 (list alsa-lib
1563 `(,gfortran "lib")
1564 glib
1565 gstreamer
1566 jack-1
1567 openblas
1568 openfst
1569 portaudio
1570 python))
1571 (native-inputs
1572 (list `(,glib "bin") ; glib-genmarshal
1573 grep
1574 sed
1575 pkg-config
1576 which))
1577 (home-page "https://kaldi-asr.org/")
1578 (synopsis "Speech recognition toolkit")
1579 (description "Kaldi is an extensible toolkit for speech recognition
1580 written in C++.")
1581 (license license:asl2.0))))
1582
1583 (define-public gst-kaldi-nnet2-online
1584 (let ((commit "cb227ef43b66a9835c14eb0ad39e08ee03c210ad")
1585 (revision "2"))
1586 (package
1587 (name "gst-kaldi-nnet2-online")
1588 (version (git-version "0" revision commit))
1589 (source (origin
1590 (method git-fetch)
1591 (uri (git-reference
1592 (url "https://github.com/alumae/gst-kaldi-nnet2-online")
1593 (commit commit)))
1594 (file-name (git-file-name name version))
1595 (sha256
1596 (base32
1597 "1i6ffwiavxx07ri0lxix6s8q0r31x7i4xxvhys5jxkixf5q34w8g"))))
1598 (build-system gnu-build-system)
1599 (arguments
1600 `(#:tests? #f ; there are none
1601 #:make-flags
1602 (list (string-append "SHELL="
1603 (assoc-ref %build-inputs "bash") "/bin/bash")
1604 (string-append "KALDI_ROOT="
1605 (assoc-ref %build-inputs "kaldi-src"))
1606 (string-append "KALDILIBDIR="
1607 (assoc-ref %build-inputs "kaldi") "/lib")
1608 "KALDI_FLAVOR=dynamic")
1609 #:phases
1610 (modify-phases %standard-phases
1611 (add-after 'unpack 'chdir
1612 (lambda _ (chdir "src") #t))
1613 (replace 'configure
1614 (lambda* (#:key inputs #:allow-other-keys)
1615 (let ((glib (assoc-ref inputs "glib")))
1616 (setenv "CXXFLAGS" "-fPIC")
1617 (setenv "CPLUS_INCLUDE_PATH"
1618 (string-append glib "/include/glib-2.0:"
1619 glib "/lib/glib-2.0/include:"
1620 (assoc-ref inputs "gstreamer")
1621 "/include/gstreamer-1.0")))
1622 (substitute* "Makefile"
1623 (("include \\$\\(KALDI_ROOT\\)/src/kaldi.mk") "")
1624 (("\\$\\(error Cannot find") "#"))
1625 #t))
1626 (add-before 'build 'build-depend
1627 (lambda* (#:key make-flags #:allow-other-keys)
1628 (apply invoke "make" "depend" make-flags)))
1629 (replace 'install
1630 (lambda* (#:key outputs #:allow-other-keys)
1631 (let* ((out (assoc-ref outputs "out"))
1632 (lib (string-append out "/lib/gstreamer-1.0")))
1633 (install-file "libgstkaldinnet2onlinedecoder.so" lib)
1634 #t))))))
1635 (inputs
1636 (list glib gstreamer jansson openfst kaldi))
1637 (native-inputs
1638 `(("bash" ,bash)
1639 ("glib:bin" ,glib "bin") ; glib-genmarshal
1640 ("kaldi-src" ,(package-source kaldi))
1641 ("pkg-config" ,pkg-config)))
1642 (home-page "https://kaldi-asr.org/")
1643 (synopsis "Gstreamer plugin for decoding speech")
1644 (description "This package provides a GStreamer plugin that wraps
1645 Kaldi's @code{SingleUtteranceNnet2Decoder}. It requires iVector-adapted DNN
1646 acoustic models. The iVectors are adapted to the current audio stream
1647 automatically.")
1648 (license license:asl2.0))))
1649
1650 (define-public kaldi-gstreamer-server
1651 ;; This is the tip of the py3 branch
1652 (let ((commit "f68cab490be7eb0da2af1475fbc16655f50a60cb")
1653 (revision "2"))
1654 (package
1655 (name "kaldi-gstreamer-server")
1656 (version (git-version "0" revision commit))
1657 (source (origin
1658 (method git-fetch)
1659 (uri (git-reference
1660 (url "https://github.com/alumae/kaldi-gstreamer-server")
1661 (commit commit)))
1662 (file-name (git-file-name name version))
1663 (sha256
1664 (base32
1665 "17lh1368vkg8ngrcbn2phvigzlmalrqg6djx2gg61qq1a0nj87dm"))))
1666 (build-system gnu-build-system)
1667 (arguments
1668 `(#:tests? #f ; there are no tests that can be run automatically
1669 #:modules ((guix build utils)
1670 (guix build gnu-build-system)
1671 (srfi srfi-26))
1672 #:phases
1673 (modify-phases %standard-phases
1674 (delete 'configure)
1675 (replace 'build
1676 (lambda* (#:key outputs #:allow-other-keys)
1677 ;; Disable hash randomization to ensure the generated .pycs
1678 ;; are reproducible.
1679 (setenv "PYTHONHASHSEED" "0")
1680 (with-directory-excursion "kaldigstserver"
1681 ;; See https://github.com/alumae/kaldi-gstreamer-server/issues/232
1682 (substitute* "master_server.py"
1683 (("\\.replace\\('\\\\.*") ")"))
1684
1685 ;; This is a Python 2 file
1686 (delete-file "decoder_test.py")
1687 (delete-file "test-buffer.py")
1688
1689 (for-each (lambda (file)
1690 (apply invoke
1691 `("python"
1692 "-m" "compileall"
1693 "-f" ; force rebuild
1694 ,file)))
1695 (find-files "." "\\.py$")))
1696 #t))
1697 (replace 'install
1698 (lambda* (#:key inputs outputs #:allow-other-keys)
1699 (let* ((out (assoc-ref outputs "out"))
1700 (bin (string-append out "/bin"))
1701 (share (string-append out "/share/kaldi-gstreamer-server/")))
1702 ;; Install Python files
1703 (with-directory-excursion "kaldigstserver"
1704 (for-each (cut install-file <> share)
1705 (find-files "." ".*")))
1706
1707 ;; Install sample configuration files
1708 (for-each (cut install-file <> share)
1709 (find-files "." "\\.yaml"))
1710
1711 ;; Install executables
1712 (mkdir-p bin)
1713 (let* ((server (string-append bin "/kaldi-gst-server"))
1714 (client (string-append bin "/kaldi-gst-client"))
1715 (worker (string-append bin "/kaldi-gst-worker"))
1716 (PYTHONPATH (getenv "GUIX_PYTHONPATH"))
1717 (GST_PLUGIN_PATH (string-append
1718 (assoc-ref inputs "gst-kaldi-nnet2-online")
1719 "/lib/gstreamer-1.0:${GST_PLUGIN_PATH}"))
1720 (wrap (lambda (wrapper what)
1721 (with-output-to-file wrapper
1722 (lambda _
1723 (format #t
1724 "#!~a
1725 export GUIX_PYTHONPATH=~a
1726 export GST_PLUGIN_PATH=~a
1727 exec ~a ~a/~a \"$@\"~%"
1728 (which "bash") PYTHONPATH GST_PLUGIN_PATH
1729 (which "python") share what)))
1730 (chmod wrapper #o555))))
1731 (for-each wrap
1732 (list server client worker)
1733 (list "master_server.py"
1734 "client.py"
1735 "worker.py")))
1736 #t))))))
1737 (inputs
1738 `(("gst-kaldi-nnet2-online" ,gst-kaldi-nnet2-online)
1739 ("python" ,python-wrapper)
1740 ("python-pygobject" ,python-pygobject)
1741 ("python-pyyaml" ,python-pyyaml)
1742 ("python-tornado" ,python-tornado-6)))
1743 (home-page "https://github.com/alumae/kaldi-gstreamer-server")
1744 (synopsis "Real-time full-duplex speech recognition server")
1745 (description "This is a real-time full-duplex speech recognition server,
1746 based on the Kaldi toolkit and the GStreamer framework and implemented in
1747 Python.")
1748 (license license:bsd-2))))
1749
1750 ;; Note that Tensorflow includes a "third_party" directory, which seems to not
1751 ;; only contain modified subsets of upstream library source code, but also
1752 ;; adapter headers provided by Google (such as the fft.h header, which is not
1753 ;; part of the upstream project code). The Tensorflow code includes headers
1754 ;; from the "third_party" directory. It does not look like we can replace
1755 ;; these headers with unmodified upstream files, so we keep them.
1756 (define-public tensorflow
1757 (package
1758 (name "tensorflow")
1759 (version "1.9.0")
1760 (source
1761 (origin
1762 (method git-fetch)
1763 (uri (git-reference
1764 (url "https://github.com/tensorflow/tensorflow")
1765 (commit (string-append "v" version))))
1766 (file-name (string-append "tensorflow-" version "-checkout"))
1767 (sha256
1768 (base32
1769 "0a9kwha395g3wgxfwln5j8vn9nkspmd75xldrlqdq540w996g8xa"))
1770 (patches
1771 (search-patches "tensorflow-c-api-fix.patch"))))
1772 (build-system cmake-build-system)
1773 (arguments
1774 `(#:tests? #f ; no "check" target
1775 #:build-type "Release"
1776 #:configure-flags
1777 (let ((protobuf (assoc-ref %build-inputs "protobuf"))
1778 (protobuf:native (assoc-ref %build-inputs "protobuf:native"))
1779 (jsoncpp (assoc-ref %build-inputs "jsoncpp"))
1780 (snappy (assoc-ref %build-inputs "snappy"))
1781 (sqlite (assoc-ref %build-inputs "sqlite")))
1782 (list
1783 ;; Use protobuf from Guix
1784 (string-append "-Dprotobuf_STATIC_LIBRARIES="
1785 protobuf "/lib/libprotobuf.so")
1786 (string-append "-DPROTOBUF_PROTOC_EXECUTABLE="
1787 protobuf:native "/bin/protoc")
1788
1789 ;; Use snappy from Guix
1790 (string-append "-Dsnappy_STATIC_LIBRARIES="
1791 snappy "/lib/libsnappy.so")
1792 ;; Yes, this is not actually the include directory but a prefix...
1793 (string-append "-Dsnappy_INCLUDE_DIR=" snappy)
1794
1795 ;; Use jsoncpp from Guix
1796 (string-append "-Djsoncpp_STATIC_LIBRARIES="
1797 jsoncpp "/lib/libjsoncpp.so")
1798 ;; Yes, this is not actually the include directory but a prefix...
1799 (string-append "-Djsoncpp_INCLUDE_DIR=" jsoncpp)
1800
1801 ;; Use sqlite from Guix
1802 (string-append "-Dsqlite_STATIC_LIBRARIES="
1803 sqlite "/lib/libsqlite.a")
1804
1805 ;; Use system libraries wherever possible. Currently, this
1806 ;; only affects zlib.
1807 "-Dsystemlib_ALL=ON"
1808 "-Dtensorflow_ENABLE_POSITION_INDEPENDENT_CODE=ON"
1809 "-Dtensorflow_BUILD_SHARED_LIB=ON"
1810 "-Dtensorflow_OPTIMIZE_FOR_NATIVE_ARCH=OFF"
1811 "-Dtensorflow_ENABLE_SSL_SUPPORT=OFF"
1812 "-Dtensorflow_BUILD_CONTRIB_KERNELS=OFF"))
1813 #:make-flags
1814 (list "CC=gcc")
1815 #:modules ((ice-9 ftw)
1816 (guix build utils)
1817 (guix build cmake-build-system)
1818 ((guix build python-build-system)
1819 #:select (python-version)))
1820 #:imported-modules (,@%cmake-build-system-modules
1821 (guix build python-build-system))
1822 #:phases
1823 (modify-phases %standard-phases
1824 (add-after 'unpack 'set-source-file-times-to-1980
1825 ;; At the end of the tf_python_build_pip_package target, a ZIP
1826 ;; archive should be generated via bdist_wheel, but it fails with
1827 ;; "ZIP does not support timestamps before 1980". Luckily,
1828 ;; SOURCE_DATE_EPOCH is respected, which we set to some time in
1829 ;; 1980.
1830 (lambda _ (setenv "SOURCE_DATE_EPOCH" "315532800") #t))
1831 (add-after 'unpack 'python3.9-compatibility
1832 (lambda _
1833 ;; See https://github.com/tensorflow/tensorflow/issues/20517#issuecomment-406373913
1834 (substitute* '("tensorflow/python/eager/pywrap_tfe_src.cc"
1835 "tensorflow/python/lib/core/ndarray_tensor.cc"
1836 "tensorflow/python/lib/core/py_func.cc")
1837 (("PyUnicode_AsUTF8") "(char *)PyUnicode_AsUTF8"))
1838 (substitute* "tensorflow/c/eager/c_api.h"
1839 (("unsigned char async")
1840 "unsigned char is_async"))
1841
1842 ;; Remove dependency on tensorboard, a complicated but probably
1843 ;; optional package.
1844 (substitute* "tensorflow/tools/pip_package/setup.py"
1845 ((".*'tensorboard >.*") ""))
1846
1847 ;; Fix the build with python-3.8, taken from rejected upstream patch:
1848 ;; https://github.com/tensorflow/tensorflow/issues/34197
1849 (substitute* (find-files "tensorflow/python" ".*\\.cc$")
1850 (("(nullptr,)(\\ +/. tp_print)" _ _ tp_print)
1851 (string-append "NULL, " tp_print)))
1852
1853 ;; Fix the build with numpy >= 1.19.
1854 ;; Suggested in https://github.com/tensorflow/tensorflow/issues/41086#issuecomment-656833081
1855 (substitute* "tensorflow/python/lib/core/bfloat16.cc"
1856 (("void BinaryUFunc\\(char\\*\\* args, npy_intp\\* dimensions, npy_intp\\* steps,")
1857 "void BinaryUFunc(char** args, npy_intp const* dimensions, npy_intp const* steps,")
1858 (("void CompareUFunc\\(char\\*\\* args, npy_intp\\* dimensions, npy_intp\\* steps,")
1859 "void CompareUFunc(char** args, npy_intp const* dimensions, npy_intp const* steps,"))))
1860 (add-after 'python3.9-compatibility 'chdir
1861 (lambda _ (chdir "tensorflow/contrib/cmake")))
1862 (add-after 'chdir 'disable-downloads
1863 (lambda* (#:key inputs #:allow-other-keys)
1864 (substitute* (find-files "external" "\\.cmake$")
1865 (("GIT_REPOSITORY.*") "")
1866 (("GIT_TAG.*") "")
1867 (("PREFIX ")
1868 "DOWNLOAD_COMMAND \"\"\nPREFIX "))
1869
1870 ;; Use packages from Guix
1871 (let ((grpc (assoc-ref inputs "grpc")))
1872 (substitute* "CMakeLists.txt"
1873 ;; Sqlite
1874 (("include\\(sqlite\\)") "")
1875 (("\\$\\{sqlite_STATIC_LIBRARIES\\}")
1876 (search-input-file inputs "/lib/libsqlite3.so"))
1877 (("sqlite_copy_headers_to_destination") "")
1878
1879 ;; PNG
1880 (("include\\(png\\)") "")
1881 (("\\$\\{png_STATIC_LIBRARIES\\}")
1882 (search-input-file inputs "/lib/libpng16.so"))
1883 (("png_copy_headers_to_destination") "")
1884
1885 ;; JPEG
1886 (("include\\(jpeg\\)") "")
1887 (("\\$\\{jpeg_STATIC_LIBRARIES\\}")
1888 (search-input-file inputs "/lib/libjpeg.so"))
1889 (("jpeg_copy_headers_to_destination") "")
1890
1891 ;; GIF
1892 (("include\\(gif\\)") "")
1893 (("\\$\\{gif_STATIC_LIBRARIES\\}")
1894 (search-input-file inputs "/lib/libgif.so"))
1895 (("gif_copy_headers_to_destination") "")
1896
1897 ;; lmdb
1898 (("include\\(lmdb\\)") "")
1899 (("\\$\\{lmdb_STATIC_LIBRARIES\\}")
1900 (search-input-file inputs "/lib/liblmdb.so"))
1901 (("lmdb_copy_headers_to_destination") "")
1902
1903 ;; Protobuf
1904 (("include\\(protobuf\\)") "")
1905 (("protobuf_copy_headers_to_destination") "")
1906 (("^ +protobuf") "")
1907
1908 ;; gRPC
1909 (("include\\(grpc\\)")
1910 "find_package(grpc REQUIRED NAMES gRPC)")
1911 (("list\\(APPEND tensorflow_EXTERNAL_DEPENDENCIES grpc\\)") "")
1912
1913 ;; Eigen
1914 (("include\\(eigen\\)")
1915 (string-append "find_package(eigen REQUIRED NAMES Eigen3)
1916 set(eigen_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/external/eigen_archive "
1917 (assoc-ref inputs "eigen") "/include/eigen3)"))
1918 (("^ +eigen") "")
1919
1920 ;; snappy
1921 (("include\\(snappy\\)")
1922 "add_definitions(-DTF_USE_SNAPPY)")
1923 (("list\\(APPEND tensorflow_EXTERNAL_DEPENDENCIES snappy\\)") "")
1924
1925 ;; jsoncpp
1926 (("include\\(jsoncpp\\)") "")
1927 (("^ +jsoncpp") ""))
1928
1929 (substitute* "tf_core_framework.cmake"
1930 ((" grpc") "")
1931 (("\\$\\{GRPC_BUILD\\}/grpc_cpp_plugin")
1932 (which "grpc_cpp_plugin"))
1933 ;; Link with gRPC libraries
1934 (("add_library\\(tf_protos_cc.*" m)
1935 (string-append m
1936 (format #f "\ntarget_link_libraries(tf_protos_cc PRIVATE \
1937 ~a/lib/libgrpc++_unsecure.a \
1938 ~a/lib/libgrpc_unsecure.a \
1939 ~a/lib/libaddress_sorting.a \
1940 ~a/lib/libgpr.a \
1941 ~a//lib/libcares.so
1942 )\n"
1943 grpc grpc grpc grpc
1944 (assoc-ref inputs "c-ares"))))))
1945 (substitute* "tf_tools.cmake"
1946 (("add_dependencies\\(\\$\\{proto_text.*") ""))
1947 ;; Remove dependency on bundled grpc
1948 (substitute* "tf_core_distributed_runtime.cmake"
1949 (("tf_core_cpu grpc") "tf_core_cpu"))
1950
1951 ;; This directory is a dependency of many targets.
1952 (mkdir-p "protobuf")))
1953 (add-after 'configure 'unpack-third-party-sources
1954 (lambda* (#:key inputs outputs #:allow-other-keys)
1955 ;; This is needed to configure bundled packages properly.
1956 (setenv "CONFIG_SHELL" (which "bash"))
1957 (for-each
1958 (lambda (name)
1959 (let* ((what (assoc-ref inputs (string-append name "-src")))
1960 (name* (string-map (lambda (c)
1961 (if (char=? c #\-)
1962 #\_ c)) name))
1963 (where (string-append "../build/" name* "/src/" name*)))
1964 (cond
1965 ((string-suffix? ".zip" what)
1966 (mkdir-p where)
1967 (with-directory-excursion where
1968 (invoke "unzip" what)))
1969 ((string-suffix? ".tar.gz" what)
1970 (mkdir-p where)
1971 (invoke "tar" "xf" what
1972 "-C" where "--strip-components=1"))
1973 (else
1974 (let ((parent (dirname where)))
1975 (mkdir-p parent)
1976 (with-directory-excursion parent
1977 (when (file-exists? name*)
1978 (delete-file-recursively name*))
1979 (copy-recursively what name*)
1980 (map make-file-writable
1981 (find-files name* ".*"))))))))
1982 (list "boringssl"
1983 "cub"
1984 "double-conversion"
1985 "farmhash"
1986 "fft2d"
1987 "highwayhash"
1988 "nsync"
1989 "re2"))
1990
1991 (rename-file "../build/cub/src/cub/cub-1.8.0/"
1992 "../build/cub/src/cub/cub/")
1993
1994 (setenv "LDFLAGS"
1995 (string-append "-Wl,-rpath="
1996 (assoc-ref outputs "out") "/lib"))))
1997 (add-after 'unpack 'fix-python-build
1998 (lambda* (#:key inputs outputs #:allow-other-keys)
1999 (mkdir-p "protobuf-src")
2000 (invoke "tar" "xf" (assoc-ref inputs "protobuf:src")
2001 "-C" "protobuf-src" "--strip-components=1")
2002 (mkdir-p "eigen-src")
2003 (copy-recursively (assoc-ref inputs "eigen:src") "eigen-src")
2004
2005 (substitute* "tensorflow/contrib/cmake/tf_python.cmake"
2006 ;; Take protobuf source files from our source package.
2007 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/protobuf/src/protobuf/src/google")
2008 (string-append (getcwd) "/protobuf-src/src/google")))
2009
2010 (substitute* '("tensorflow/contrib/cmake/tf_shared_lib.cmake"
2011 "tensorflow/contrib/cmake/tf_python.cmake")
2012 ;; Take Eigen source files from our source package.
2013 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/eigen/src/eigen/")
2014 (string-append (getcwd) "/eigen-src/"))
2015 ;; Take Eigen headers from our own package.
2016 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/external/eigen_archive")
2017 (search-input-directory inputs "/include/eigen3")))
2018
2019 ;; Correct the RUNPATH of ops libraries generated for Python.
2020 ;; TODO: this doesn't work :(
2021 ;; /gnu/store/...-tensorflow-1.9.0/lib/python3.7/site-packages/tensorflow/contrib/seq2seq/python/ops/lib_beam_search_ops.so:
2022 ;; warning: RUNPATH contains bogus entries: ("/tmp/guix-build-tensorflow-1.9.0.drv-0/source/tensorflow/contrib/build")
2023 ;; /gnu/store/...-tensorflow-1.9.0/lib/python3.7/site-packages/tensorflow/contrib/seq2seq/python/ops/lib_beam_search_ops.so:
2024 ;; error: depends on 'libpywrap_tensorflow_internal.so', which
2025 ;; cannot be found in RUNPATH ...
2026 (substitute* "tensorflow/contrib/cmake/tf_cc_ops.cmake"
2027 (("set_target_properties.*")
2028 (string-append "set_target_properties(${_AT_TARGET} PROPERTIES \
2029 COMPILE_FLAGS ${target_compile_flags} \
2030 INSTALL_RPATH_USE_LINK_PATH TRUE \
2031 INSTALL_RPATH " (assoc-ref outputs "out") "/lib)\n")))))
2032 (add-after 'unpack 'patch-cmake-file-to-install-c-headers
2033 (lambda _
2034 (substitute* "tensorflow/contrib/cmake/tf_c.cmake"
2035 (("if\\(tensorflow_BUILD_PYTHON_BINDINGS" m)
2036 (string-append
2037 "install(DIRECTORY ${tensorflow_source_dir}/tensorflow/c/ \
2038 DESTINATION include/tensorflow/c FILES_MATCHING PATTERN \"*.h\")\n" m)))))
2039 (add-after 'build 'build-c-bindings
2040 (lambda* (#:key outputs parallel-build? #:allow-other-keys)
2041 (invoke "make" "-j" (if parallel-build?
2042 (number->string (parallel-job-count))
2043 "1")
2044 "tf_c")))
2045 (add-after 'install 'build-pip-package
2046 (lambda* (#:key outputs parallel-build? #:allow-other-keys)
2047 (invoke "make" "-j" (if parallel-build?
2048 (number->string (parallel-job-count))
2049 "1")
2050 "tf_python_build_pip_package")))
2051 (add-after 'build-pip-package 'install-python
2052 (lambda* (#:key inputs outputs #:allow-other-keys)
2053 (let ((out (assoc-ref outputs "out"))
2054 (wheel (car (find-files "../build/tf_python/dist/" "\\.whl$")))
2055 (python-version (python-version
2056 (assoc-ref inputs "python"))))
2057 (invoke "python" "-m" "pip" "install" wheel
2058 (string-append "--prefix=" out))
2059
2060 ;; XXX: broken RUNPATH, see fix-python-build phase.
2061 (delete-file
2062 (string-append
2063 out "/lib/python" python-version
2064 "/site-packages/tensorflow/contrib/"
2065 "seq2seq/python/ops/lib_beam_search_ops.so"))))))))
2066 (native-inputs
2067 `(("pkg-config" ,pkg-config)
2068 ("protobuf:native" ,protobuf-3.6) ; protoc
2069 ("protobuf:src" ,(package-source protobuf-3.6))
2070 ("eigen:src" ,(package-source eigen-for-tensorflow))
2071 ;; install_pip_packages.sh wants setuptools 39.1.0 specifically.
2072 ("python-setuptools" ,python-setuptools-for-tensorflow)
2073
2074 ;; The commit hashes and URLs for third-party source code are taken
2075 ;; from "tensorflow/workspace.bzl".
2076 ("boringssl-src"
2077 ,(let ((commit "ee7aa02")
2078 (revision "1"))
2079 (origin
2080 (method git-fetch)
2081 (uri (git-reference
2082 (url "https://boringssl.googlesource.com/boringssl")
2083 (commit commit)))
2084 (file-name (string-append "boringssl-0-" revision
2085 (string-take commit 7)
2086 "-checkout"))
2087 (sha256
2088 (base32
2089 "1jf693q0nw0adsic6cgmbdx6g7wr4rj4vxa8j1hpn792fqhd8wgw")))))
2090 ("cub-src"
2091 ,(let ((version "1.8.0"))
2092 (origin
2093 (method url-fetch)
2094 (uri (string-append "https://mirror.bazel.build/github.com/NVlabs/"
2095 "cub/archive/" version ".zip"))
2096 (file-name (string-append "cub-" version ".zip"))
2097 (sha256
2098 (base32
2099 "1hsqikqridb90dkxkjr2918dcry6pfh46ccnwrzawl56aamhdykb")))))
2100 ("double-conversion-src"
2101 ,(let ((commit "5664746")
2102 (revision "1"))
2103 (origin
2104 (method git-fetch)
2105 (uri (git-reference
2106 (url "https://github.com/google/double-conversion")
2107 (commit commit)))
2108 (file-name
2109 (git-file-name "double-conversion"
2110 (string-append "0-" revision "."
2111 (string-take commit 7))))
2112 (sha256
2113 (base32
2114 "1h5lppqqxcvdg5jq42i5msgwx20ryij3apvmndflngrgdpc04gn1")))))
2115 ("farmhash-src"
2116 ,(let ((commit "816a4ae622e964763ca0862d9dbd19324a1eaf45"))
2117 (origin
2118 (method url-fetch)
2119 (uri (string-append
2120 "https://mirror.bazel.build/github.com/google/farmhash/archive/"
2121 commit ".tar.gz"))
2122 (file-name (string-append "farmhash-0-" (string-take commit 7)
2123 ".tar.gz"))
2124 (sha256
2125 (base32
2126 "185b2xdxl4d4cnsnv6abg8s22gxvx8673jq2yaq85bz4cdy58q35")))))
2127 ;; The license notice on the home page at
2128 ;; http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html says:
2129 ;; Copyright Takuya OOURA, 1996-2001
2130 ;;
2131 ;; You may use, copy, modify and distribute this code for any purpose
2132 ;; (include commercial use) and without fee. Please refer to this
2133 ;; package when you modify this code.
2134 ;;
2135 ;; We take the identical tarball from the Bazel mirror, because the URL
2136 ;; at the home page is not versioned and might change.
2137 ("fft2d-src"
2138 ,(origin
2139 (method url-fetch)
2140 (uri "https://mirror.bazel.build/www.kurims.kyoto-u.ac.jp/~ooura/fft.tgz")
2141 (file-name "fft2d.tar.gz")
2142 (sha256
2143 (base32
2144 "15jjkfvhqvl2c0753d2di8hz0pyzn598g74wqy79awdrf1y67fsj"))))
2145 ("highwayhash-src"
2146 ,(let ((commit "be5edafc2e1a455768e260ccd68ae7317b6690ee")
2147 (revision "1"))
2148 (origin
2149 (method git-fetch)
2150 (uri (git-reference
2151 (url "https://github.com/google/highwayhash")
2152 (commit commit)))
2153 (file-name (string-append "highwayhash-0-" revision
2154 (string-take commit 7)
2155 "-checkout"))
2156 (sha256
2157 (base32
2158 "154jwf98cyy54hldr94pgjn85zynly3abpnc1avmb8a18lzwjyb6")))))
2159 ("nsync-src"
2160 ,(let ((version "0559ce013feac8db639ee1bf776aca0325d28777")
2161 (revision "1"))
2162 (origin
2163 (method url-fetch)
2164 (uri (string-append "https://mirror.bazel.build/"
2165 "github.com/google/nsync/archive/"
2166 version ".tar.gz"))
2167 (file-name (string-append "nsync-0." revision
2168 "-" (string-take version 7)
2169 ".tar.gz"))
2170 (sha256
2171 (base32
2172 "0qdkyqym34x739mmzv97ah5r7ph462v5xkxqxvidmcfqbi64b132")))))
2173 ("re2-src"
2174 ,(let ((commit "e7efc48")
2175 (revision "1"))
2176 (origin
2177 (method git-fetch)
2178 (uri (git-reference
2179 (url "https://github.com/google/re2")
2180 (commit commit)))
2181 (file-name (string-append "re2-0-" revision
2182 (string-take commit 7)
2183 "-checkout"))
2184 (sha256
2185 (base32
2186 "161g9841rjfsy5pn52fcis0s9hdr7rxvb06pad38j5rppfihvign")))))
2187 ("googletest" ,googletest)
2188 ("swig" ,swig)
2189 ("unzip" ,unzip)))
2190 (propagated-inputs
2191 `(("python-absl-py" ,python-absl-py)
2192 ("python-astor" ,python-astor)
2193 ("python-gast" ,python-gast)
2194 ("python-grpcio" ,python-grpcio)
2195 ("python-numpy" ,python-numpy)
2196 ("python-protobuf" ,python-protobuf-3.6)
2197 ("python-six" ,python-six)
2198 ("python-termcolo" ,python-termcolor)
2199 ("python-wheel" ,python-wheel)))
2200 (inputs
2201 `(("c-ares" ,c-ares)
2202 ("eigen" ,eigen-for-tensorflow)
2203 ("gemmlowp" ,gemmlowp-for-tensorflow)
2204 ("lmdb" ,lmdb)
2205 ("libjpeg" ,libjpeg-turbo)
2206 ("libpng" ,libpng)
2207 ("giflib" ,giflib)
2208 ("grpc" ,grpc-1.16.1 "static")
2209 ("grpc:bin" ,grpc-1.16.1)
2210 ("jsoncpp" ,jsoncpp-for-tensorflow)
2211 ("snappy" ,snappy)
2212 ("sqlite" ,sqlite)
2213 ("protobuf" ,protobuf-3.6)
2214 ("python" ,python-wrapper)
2215 ("zlib" ,zlib)))
2216 (home-page "https://tensorflow.org")
2217 (synopsis "Machine learning framework")
2218 (description
2219 "TensorFlow is a flexible platform for building and training machine
2220 learning models. It provides a library for high performance numerical
2221 computation and includes high level Python APIs, including both a sequential
2222 API for beginners that allows users to build models quickly by plugging
2223 together building blocks and a subclassing API with an imperative style for
2224 advanced research.")
2225 (license license:asl2.0)))
2226
2227 (define-public tensorflow-lite
2228 (package
2229 (name "tensorflow-lite")
2230 (version "2.5.0")
2231 (source
2232 (origin
2233 (method git-fetch)
2234 (uri (git-reference
2235 (url "https://github.com/tensorflow/tensorflow")
2236 (commit (string-append "v" version))))
2237 (file-name (git-file-name name version))
2238 (sha256
2239 (base32
2240 "1jdw2i1rq06zqd6aabh7bbm0avsg4pygnfmd7gviv0blhih9054l"))))
2241 (build-system cmake-build-system)
2242 (arguments
2243 `(#:tests? #false ; no "check" target
2244 #:build-type "Release"
2245 #:configure-flags
2246 (list
2247 "-DTFLITE_ENABLE_GPU=OFF"
2248 "-DTFLITE_ENABLE_RUY=OFF"
2249
2250 ;; TODO: The build system attempts to build xnnpack from source. We
2251 ;; would like to use our xnnpack package here, but this requires more
2252 ;; work.
2253 "-DTFLITE_ENABLE_XNNPACK=OFF"
2254
2255 ;; Pretend we've already fetched abseil. We won't actually build it
2256 ;; but use the existing package.
2257 "-Dabseil-cpp_POPULATED=TRUE"
2258
2259 ;; Don't fetch the sources. We have already built flatbuffers.
2260 "-Dflatbuffers_POPULATED=TRUE"
2261
2262 "-DFFT2D_SOURCE_DIR=/tmp/fft2d"
2263 "-Dneon2sse_SOURCE_DIR=/tmp/neon2sse"
2264 "-Dneon2sse_BINARY_DIR=/tmp/neon2sse-bin"
2265 "-DFARMHASH_SOURCE_DIR=/tmp/farmhash"
2266 "-Dgemmlowp_SOURCE_DIR=/tmp/gemmlowp"
2267 (string-append "-DRUY_SOURCE_DIR="
2268 (assoc-ref %build-inputs "ruy-src")))
2269 #:phases
2270 (modify-phases %standard-phases
2271 (add-after 'unpack 'chdir
2272 (lambda _ (chdir "tensorflow/lite")))
2273 (add-after 'chdir 'copy-sources
2274 (lambda* (#:key inputs #:allow-other-keys)
2275 ;; Use external cmake finders instead of these stubs that won't
2276 ;; find anything but the bundled sources.
2277 (delete-file "tools/cmake/modules/Findabsl.cmake")
2278 (delete-file "tools/cmake/modules/Findeigen.cmake")
2279
2280 (substitute* "CMakeLists.txt"
2281 (("find_package\\(eigen REQUIRED")
2282 "find_package(eigen REQUIRED NAMES Eigen3"))
2283 (substitute* "tools/cmake/modules/Findflatbuffers.cmake"
2284 (("get_target_property.*")
2285 (format #false "set(FLATBUFFERS_INCLUDE_DIRS ~a/include)\n"
2286 (assoc-ref inputs "flatbuffers"))))
2287
2288 ;; Don't fetch source code; we already have everything we need.
2289 (substitute* '("tools/cmake/modules/fft2d.cmake"
2290 "tools/cmake/modules/ruy.cmake"
2291 "tools/cmake/modules/farmhash.cmake"
2292 "tools/cmake/modules/neon2sse.cmake"
2293 "tools/cmake/modules/gemmlowp.cmake")
2294 (("OverridableFetchContent_Populate.*") ""))
2295
2296 (mkdir-p "/tmp/farmhash")
2297 (with-directory-excursion "/tmp/farmhash"
2298 (invoke "tar" "--strip-components=1"
2299 "-xf" (assoc-ref inputs "farmhash-src")))
2300
2301 (mkdir-p "/tmp/fft2d")
2302 (with-directory-excursion "/tmp/fft2d"
2303 (invoke "tar" "--strip-components=1"
2304 "-xf" (assoc-ref inputs "fft2d-src")))
2305
2306 (copy-recursively (assoc-ref inputs "neon2sse-src")
2307 "/tmp/neon2sse/")
2308 (copy-recursively (assoc-ref inputs "gemmlowp-src")
2309 "/tmp/gemmlowp/")))
2310 (add-after 'copy-sources 'prepare-shared-library-build
2311 (lambda _ (chdir "c")))
2312 (replace 'install
2313 (lambda* (#:key outputs #:allow-other-keys)
2314 (let* ((out (assoc-ref outputs "out"))
2315 (lib (string-append out "/lib"))
2316 (headers (string-append out "/include/tensorflow/lite")))
2317 (install-file "../build/libtensorflowlite_c.so" lib)
2318 (with-directory-excursion ".."
2319 (for-each
2320 (lambda (file)
2321 (let ((target-dir (string-append headers "/" (dirname file))))
2322 (install-file file target-dir)))
2323 (find-files "." "\\.h$")))))))))
2324 (inputs
2325 `(("abseil-cpp" ,abseil-cpp-20200923.3)
2326 ("eigen" ,eigen-for-tensorflow-lite)
2327 ("flatbuffers" ,flatbuffers)
2328 ("python" ,python)))
2329 (native-inputs
2330 `(("pkg-config" ,pkg-config)
2331 ("gemmlowp-src"
2332 ;; The commit hash is taken from
2333 ;; "tensorflow/lite/tools/cmake/modules/gemmlowp.cmake".
2334 ,(let ((commit "fda83bdc38b118cc6b56753bd540caa49e570745"))
2335 (origin
2336 (method git-fetch)
2337 (uri (git-reference
2338 (url "https://github.com/google/gemmlowp")
2339 (commit commit)))
2340 (file-name (git-file-name "gemmlowp" (string-take commit 8)))
2341 (sha256
2342 (base32
2343 "1sbp8kmr2azwlvfbzryy1frxi99jhsh1nc93bdbxdf8zdgpv0kxl")))))
2344 ("neon2sse-src"
2345 ,(let ((commit "a1652fd5253afbf3e39357b012974f93511f6108"))
2346 (origin
2347 (method git-fetch)
2348 (uri (git-reference
2349 (url "https://github.com/intel/ARM_NEON_2_x86_SSE")
2350 (commit commit)))
2351 (file-name (git-file-name "neon2sse" (string-take commit 8)))
2352 (sha256
2353 (base32
2354 "1q8gkxag9wlnwdwad2pclsrkwzrdjy94hyrkayrsvxyj7szb5y8i")))))
2355 ("farmhash-src"
2356 ,(let ((commit "816a4ae622e964763ca0862d9dbd19324a1eaf45"))
2357 (origin
2358 (method url-fetch)
2359 (uri (string-append
2360 "https://mirror.bazel.build/github.com/google/farmhash/archive/"
2361 commit ".tar.gz"))
2362 (file-name (git-file-name "farmhash" (string-take commit 8)))
2363 (sha256
2364 (base32
2365 "185b2xdxl4d4cnsnv6abg8s22gxvx8673jq2yaq85bz4cdy58q35")))))
2366 ("fft2d-src"
2367 ,(origin
2368 (method url-fetch)
2369 (uri (string-append "https://storage.googleapis.com/"
2370 "mirror.tensorflow.org/"
2371 "www.kurims.kyoto-u.ac.jp/~ooura/fft2d.tgz"))
2372 (file-name "fft2d.tar.gz")
2373 (sha256
2374 (base32
2375 "1jfflzi74fag9z4qmgwvp90aif4dpbr1657izmxlgvf4hy8fk9xd"))))
2376 ("ruy-src"
2377 ,(let ((commit "9c56af3fce210a8a103eda19bd6f47c08a9e3d90"))
2378 (origin
2379 (method git-fetch)
2380 (uri (git-reference
2381 (url "https://github.com/google/ruy")
2382 (commit commit)
2383 (recursive? #true)))
2384 (file-name (git-file-name "ruy" (string-take commit 8)))
2385 (sha256
2386 (base32
2387 "1cfd5gk6kaj8kbl3h98gx1ap8czd59y6p8qq8nr28fklpyzf5cis")))))))
2388 (home-page "https://tensorflow.org")
2389 (synopsis "Machine learning framework")
2390 (description
2391 "TensorFlow is a flexible platform for building and training machine
2392 learning models. This package provides the \"lite\" variant for mobile
2393 devices.")
2394 (license license:asl2.0)))
2395
2396 (define-public dmlc-core
2397 (package
2398 (name "dmlc-core")
2399 (version "0.5")
2400 (source
2401 (origin
2402 (method git-fetch)
2403 (uri (git-reference
2404 (url "https://github.com/dmlc/dmlc-core")
2405 (commit (string-append "v" version))))
2406 (file-name (git-file-name name version))
2407 (sha256
2408 (base32 "1x4ad1jhn84fywlk031fmv1kxyiscclmrqn9hhj8gz0mh7z9vcrh"))))
2409 (build-system cmake-build-system)
2410 (arguments
2411 `(#:configure-flags
2412 (list "-DGOOGLE_TEST=ON")))
2413 (native-inputs
2414 `(("googletest" ,googletest)
2415 ("python" ,python-wrapper)))
2416 (home-page "https://github.com/dmlc/dmlc-core")
2417 (synopsis "Common bricks library for machine learning")
2418 (description
2419 "DMLC-Core is the backbone library to support all DMLC projects,
2420 offers the bricks to build efficient and scalable distributed machine
2421 learning libraries.")
2422 (license license:asl2.0)))
2423
2424 (define-public xgboost
2425 (package
2426 (name "xgboost")
2427 (version "1.5.2")
2428 (source
2429 (origin
2430 (method git-fetch)
2431 (uri (git-reference
2432 (url "https://github.com/dmlc/xgboost")
2433 (commit (string-append "v" version))))
2434 (file-name (git-file-name name version))
2435 (patches (search-patches "xgboost-use-system-dmlc-core.patch"))
2436 (sha256
2437 (base32 "0qx04y7cz8z7qv6bk9q7d7ba9b7xzj53l83l2x9ykdwhzacc3dn0"))))
2438 (build-system cmake-build-system)
2439 (arguments
2440 `(#:configure-flags (list "-DGOOGLE_TEST=ON")))
2441 (native-inputs
2442 `(("googletest" ,googletest)
2443 ("python" ,python-wrapper)))
2444 (inputs
2445 (list dmlc-core))
2446 (home-page "https://xgboost.ai/")
2447 (synopsis "Gradient boosting (GBDT, GBRT or GBM) library")
2448 (description
2449 "XGBoost is an optimized distributed gradient boosting library designed
2450 to be highly efficient, flexible and portable. It implements machine learning
2451 algorithms under the Gradient Boosting framework. XGBoost provides a parallel
2452 tree boosting (also known as GBDT, GBM) that solve many data science problems
2453 in a fast and accurate way.")
2454 (license license:asl2.0)))
2455
2456 (define-public python-xgboost
2457 (package
2458 (inherit xgboost)
2459 (name "python-xgboost")
2460 (source (package-source xgboost))
2461 (build-system python-build-system)
2462 (arguments
2463 `(#:phases
2464 (modify-phases %standard-phases
2465 (add-after 'unpack 'preparations
2466 (lambda _
2467 ;; Move python-package content to parent directory to silence
2468 ;; some warnings about files not being found if we chdir.
2469 (rename-file "python-package/xgboost" "xgboost")
2470 (rename-file "python-package/README.rst" "README.rst")
2471 (rename-file "python-package/setup.cfg" "setup.cfg")
2472 (rename-file "python-package/setup.py" "setup.py")
2473 ;; Skip rebuilding libxgboost.so.
2474 (substitute* "setup.py"
2475 (("ext_modules=\\[CMakeExtension\\('libxgboost'\\)\\],") "")
2476 (("'install_lib': InstallLib,") ""))))
2477 (add-after 'install 'install-version-and-libxgboost
2478 (lambda* (#:key inputs outputs #:allow-other-keys)
2479 (let* ((out (assoc-ref outputs "out"))
2480 (pylib (string-append out "/lib/python"
2481 ,(version-major+minor
2482 (package-version python))
2483 "/site-packages"))
2484 (xgbdir (string-append pylib "/xgboost"))
2485 (version-file (string-append xgbdir "/VERSION"))
2486 (libxgboost (string-append (assoc-ref inputs "xgboost")
2487 "/lib/libxgboost.so")))
2488 (with-output-to-file version-file
2489 (lambda ()
2490 (display ,(package-version xgboost))))
2491 (mkdir-p (string-append xgbdir "/lib"))
2492 (symlink libxgboost (string-append xgbdir "/lib"
2493 "/libxgboost.so")))))
2494 (replace 'check
2495 ;; Python-specific tests are located in tests/python.
2496 (lambda* (#:key inputs outputs tests? #:allow-other-keys)
2497 (when tests?
2498 (add-installed-pythonpath inputs outputs)
2499 (invoke "pytest" "tests/python"
2500 ;; FIXME: CLI tests fail with PermissionError.
2501 "--ignore" "tests/python/test_cli.py" "-k"
2502 (string-append
2503 "not test_cli_regression_demo"
2504 ;; The tests below open a network connection.
2505 " and not test_model_compatibility"
2506 " and not test_get_group"
2507 " and not test_cv_no_shuffle"
2508 " and not test_cv"
2509 " and not test_training"
2510 ;; "'['./runexp.sh']' returned non-zero exit status 1"
2511 " and not test_cli_binary_classification"))))))))
2512 (native-inputs
2513 (list python-pandas python-pytest python-scikit-learn))
2514 (inputs
2515 (list xgboost))
2516 (propagated-inputs
2517 (list python-numpy python-scipy))
2518 (synopsis "Python interface for the XGBoost library")))
2519
2520 (define-public python-iml
2521 (package
2522 (name "python-iml")
2523 (version "0.6.2")
2524 (source
2525 (origin
2526 (method url-fetch)
2527 (uri (pypi-uri "iml" version))
2528 (sha256
2529 (base32
2530 "1k8szlpm19rcwcxdny9qdm3gmaqq8akb4xlvrzyz8c2d679aak6l"))))
2531 (build-system python-build-system)
2532 (propagated-inputs
2533 (list python-ipython python-numpy python-pandas python-scipy))
2534 (native-inputs
2535 (list python-nose))
2536 (home-page "https://github.com/interpretable-ml/iml")
2537 (synopsis "Interpretable Machine Learning (iML) package")
2538 (description "Interpretable ML (iML) is a set of data type objects,
2539 visualizations, and interfaces that can be used by any method designed to
2540 explain the predictions of machine learning models (or really the output of
2541 any function). It currently contains the interface and IO code from the Shap
2542 project, and it will potentially also do the same for the Lime project.")
2543 (license license:expat)))
2544
2545 (define-public python-keras-applications
2546 (package
2547 (name "python-keras-applications")
2548 (version "1.0.8")
2549 (source
2550 (origin
2551 (method url-fetch)
2552 (uri (pypi-uri "Keras_Applications" version))
2553 (sha256
2554 (base32
2555 "1rcz31ca4axa6kzhjx4lwqxbg4wvlljkj8qj9a7p9sfd5fhzjyam"))))
2556 (build-system python-build-system)
2557 ;; The tests require Keras, but this package is needed to build Keras.
2558 (arguments '(#:tests? #f))
2559 (propagated-inputs
2560 (list python-h5py python-numpy))
2561 (native-inputs
2562 (list python-pytest python-pytest-cov python-pytest-pep8
2563 python-pytest-xdist))
2564 (home-page "https://github.com/keras-team/keras-applications")
2565 (synopsis "Reference implementations of popular deep learning models")
2566 (description
2567 "This package provides reference implementations of popular deep learning
2568 models for use with the Keras deep learning framework.")
2569 (license license:expat)))
2570
2571 (define-public python-keras-preprocessing
2572 (package
2573 (name "python-keras-preprocessing")
2574 (version "1.1.0")
2575 (source
2576 (origin
2577 (method url-fetch)
2578 (uri (pypi-uri "Keras_Preprocessing" version))
2579 (sha256
2580 (base32
2581 "1r98nm4k1svsqjyaqkfk23i31bl1kcfcyp7094yyj3c43phfp3as"))))
2582 (build-system python-build-system)
2583 (propagated-inputs
2584 (list python-numpy python-six))
2585 (native-inputs
2586 (list python-pandas
2587 python-pillow
2588 python-pytest
2589 python-pytest-cov
2590 python-pytest-xdist
2591 tensorflow))
2592 (home-page "https://github.com/keras-team/keras-preprocessing/")
2593 (synopsis "Data preprocessing and augmentation for deep learning models")
2594 (description
2595 "Keras Preprocessing is the data preprocessing and data augmentation
2596 module of the Keras deep learning library. It provides utilities for working
2597 with image data, text data, and sequence data.")
2598 (license license:expat)))
2599
2600 (define-public python-keras
2601 (package
2602 (name "python-keras")
2603 (version "2.2.4")
2604 (source
2605 (origin
2606 (method url-fetch)
2607 (uri (pypi-uri "Keras" version))
2608 (patches (search-patches "python-keras-integration-test.patch"))
2609 (sha256
2610 (base32
2611 "1j8bsqzh49vjdxy6l1k4iwax5vpjzniynyd041xjavdzvfii1dlh"))))
2612 (build-system python-build-system)
2613 (arguments
2614 `(#:phases
2615 (modify-phases %standard-phases
2616 (add-after 'unpack 'remove-tests-for-unavailable-features
2617 (lambda _
2618 (delete-file "keras/backend/theano_backend.py")
2619 (delete-file "keras/backend/cntk_backend.py")
2620 (delete-file "tests/keras/backend/backend_test.py")
2621 ;; FIXME: This doesn't work because Tensorflow is missing the
2622 ;; coder ops library.
2623 (delete-file "tests/keras/test_callbacks.py")))
2624 (replace 'check
2625 (lambda* (#:key tests? #:allow-other-keys)
2626 (when tests?
2627 ;; These tests attempt to download data files from the internet.
2628 (delete-file "tests/integration_tests/test_datasets.py")
2629 (delete-file "tests/integration_tests/imagenet_utils_test.py")
2630 ;; Backport https://github.com/keras-team/keras/pull/12479.
2631 (substitute* "tests/keras/engine/test_topology.py"
2632 (("np.ones\\(\\(3, 2\\)\\)")
2633 "1."))
2634 (invoke "python" "-m" "pytest" "tests"
2635 "-p" "no:pep8"
2636 ;; FIXME: python-build-system lacks PARALLEL-TESTS?
2637 "-n" (number->string (parallel-job-count))
2638 "-k"
2639 (string-append
2640 ;; The following test fails only in the build
2641 ;; container; skip it.
2642 "not test_selu "
2643 ;; The following test was found flaky and removed in
2644 ;; recent versions.
2645 "and not test_stateful_metrics"))))))))
2646 (propagated-inputs
2647 (list python-h5py
2648 python-keras-applications
2649 python-keras-preprocessing
2650 python-numpy
2651 python-pydot
2652 python-pyyaml
2653 python-scipy
2654 python-six
2655 tensorflow
2656 graphviz))
2657 (native-inputs
2658 (list python-pandas
2659 python-pytest
2660 python-pytest-cov
2661 python-pytest-pep8
2662 python-pytest-timeout
2663 python-pytest-xdist
2664 python-sphinx
2665 python-requests))
2666 (home-page "https://github.com/keras-team/keras")
2667 (synopsis "High-level deep learning framework")
2668 (description "Keras is a high-level neural networks API, written in Python
2669 and capable of running on top of TensorFlow. It was developed with a focus on
2670 enabling fast experimentation. Use Keras if you need a deep learning library
2671 that:
2672 @itemize
2673 @item Allows for easy and fast prototyping (through user friendliness,
2674 modularity, and extensibility).
2675 @item Supports both convolutional networks and recurrent networks, as well as
2676 combinations of the two.
2677 @item Runs seamlessly on CPU and GPU.
2678 @end itemize\n")
2679 (license license:expat)))
2680
2681 (define-public gloo
2682 (let ((version "0.0.0") ; no proper version tag
2683 (commit "c22a5cfba94edf8ea4f53a174d38aa0c629d070f")
2684 (revision "1"))
2685 (package
2686 (name "gloo")
2687 (version (git-version version revision commit))
2688 (source
2689 (origin
2690 (method git-fetch)
2691 (uri (git-reference
2692 (url "https://github.com/facebookincubator/gloo")
2693 (commit commit)))
2694 (file-name (git-file-name name version))
2695 (sha256
2696 (base32
2697 "1crmqgybzkgkpbmcx16912gsl5qsj49swa0ikx6mhqgph0chrh11"))))
2698 (build-system cmake-build-system)
2699 (native-inputs
2700 (list googletest))
2701 (inputs
2702 (list openssl))
2703 (arguments
2704 `(#:configure-flags '("-DBUILD_TEST=1")
2705 #:phases
2706 (modify-phases %standard-phases
2707 (replace 'check
2708 (lambda* (#:key tests? #:allow-other-keys)
2709 (when tests?
2710 (invoke "make" "gloo_test")))))))
2711 (synopsis "Collective communications library")
2712 (description
2713 "Gloo is a collective communications library. It comes with a
2714 number of collective algorithms useful for machine learning applications.
2715 These include a barrier, broadcast, and allreduce.")
2716 (home-page "https://github.com/facebookincubator/gloo")
2717 (license license:bsd-3))))
2718
2719 (define-public python-umap-learn
2720 (package
2721 (name "python-umap-learn")
2722 (version "0.5.3")
2723 (source
2724 (origin
2725 (method git-fetch) ;no tests in pypi release
2726 (uri (git-reference
2727 (url "https://github.com/lmcinnes/umap")
2728 (commit version)))
2729 (file-name (git-file-name name version))
2730 (sha256
2731 (base32
2732 "1315jkb0h1b579y9m59632f0nnpksilm01nxx46in0rq8zna8vsb"))))
2733 (build-system python-build-system)
2734 (arguments
2735 (list
2736 #:phases
2737 #~(modify-phases %standard-phases
2738 ;; Numba needs a writable dir to cache functions.
2739 (add-before 'check 'set-numba-cache-dir
2740 (lambda _
2741 (setenv "NUMBA_CACHE_DIR" "/tmp")))
2742 (replace 'check
2743 (lambda* (#:key tests? #:allow-other-keys)
2744 (when tests?
2745 (setenv "HOME" "/tmp")
2746 (invoke "pytest" "-vv" "umap"
2747 ;; This test can fail because trust may only be
2748 ;; 0.9679405204460967 >= 0.97
2749 "-k" "not test_densmap_trustworthiness_on_iris_supervised")))))))
2750 (native-inputs (list python-pytest))
2751 (propagated-inputs
2752 (list python-numba
2753 python-numpy
2754 python-pynndescent
2755 python-scikit-learn
2756 python-scipy
2757 python-tqdm))
2758 (home-page "https://github.com/lmcinnes/umap")
2759 (synopsis "Uniform Manifold Approximation and Projection")
2760 (description "Uniform Manifold Approximation and Projection is a dimension
2761 reduction technique that can be used for visualization similarly to t-SNE, but
2762 also for general non-linear dimension reduction.")
2763 (license license:bsd-3)))
2764
2765 (define-public nnpack
2766 (let ((version "0.0")
2767 (commit "c07e3a0400713d546e0dea2d5466dd22ea389c73")
2768 (revision "1"))
2769 (package
2770 (name "nnpack")
2771 (version (git-version version revision commit))
2772 (home-page "https://github.com/Maratyszcza/NNPACK")
2773 (source (origin
2774 (method git-fetch)
2775 (uri (git-reference (url home-page) (commit commit)))
2776 (file-name (git-file-name name version))
2777 (sha256
2778 (base32
2779 "0s0kk3a35w3yzf0q447p72350sbsh4qhg6vm3y2djbj4xpg7jc8v"))
2780 (patches (search-patches "nnpack-system-libraries.patch"))))
2781 (build-system cmake-build-system)
2782 ;; XXX: The test suite runs but it's very expensive, and on x86_64 CPUs
2783 ;; that lack the right ISA extensions, tests fail with:
2784 ;;
2785 ;; Expected equality of these values:
2786 ;; nnp_status_success
2787 ;; Which is: 0
2788 ;; status
2789 ;; Which is: 51
2790 ;;
2791 ;; where 51 is 'nnp_status_unsupported_hardware'.
2792 (arguments '(#:tests? #f))
2793 (synopsis "Acceleration package for neural network computations")
2794 (description
2795 "NNPACK is an acceleration package for neural network computations.
2796 NNPACK aims to provide high-performance implementations of convnet layers for
2797 multi-core CPUs.
2798
2799 NNPACK is not intended to be directly used by machine learning researchers;
2800 instead it provides low-level performance primitives leveraged in leading deep
2801 learning frameworks, such as PyTorch, Caffe2, MXNet, tiny-dnn, Caffe, Torch,
2802 and Darknet.")
2803 (inputs
2804 (list cpuinfo
2805 fp16
2806 fxdiv
2807 psimd
2808 pthreadpool
2809 googletest))
2810 (native-inputs
2811 (list python python-peachpy python-six))
2812 (license license:bsd-2))))
2813
2814 (define-public xnnpack
2815 ;; There's currently no tag on this repo.
2816 (let ((version "0.0")
2817 (commit "ae108ef49aa5623b896fc93d4298c49d1750d9ba")
2818 (revision "2"))
2819 (package
2820 (name "xnnpack")
2821 (version (git-version version revision commit))
2822 (home-page "https://github.com/google/XNNPACK") ;fork of QNNPACK
2823 (source (origin
2824 (method git-fetch)
2825 (uri (git-reference (url home-page) (commit commit)))
2826 (file-name (git-file-name name version))
2827 (sha256
2828 (base32
2829 "0q68q2jxiiiblx45q4337k13ppgh5vqjwrwznchcnpb8hawjj3zl"))
2830 (patches (search-patches "xnnpack-system-libraries.patch"))))
2831 (build-system cmake-build-system)
2832 (arguments
2833 '(#:configure-flags '("-DXNNPACK_USE_SYSTEM_LIBS=YES"
2834 "-DBUILD_SHARED_LIBS=ON"
2835 "-DXNNPACK_LIBRARY_TYPE=shared"
2836 "-DXNNPACK_BUILD_TESTS=FALSE" ;FIXME: see below
2837 "-DXNNPACK_BUILD_BENCHMARKS=FALSE")
2838
2839 ;; FIXME: Building tests leads to a CMake error:
2840 ;;
2841 ;; ADD_LIBRARY cannot create target "all_microkernels" because
2842 ;; another target with the same name already exists.
2843 #:tests? #f))
2844 (inputs
2845 (list cpuinfo
2846 pthreadpool
2847 googletest
2848 googlebenchmark
2849 fxdiv
2850 fp16
2851 psimd))
2852 (synopsis "Optimized floating-point neural network inference operators")
2853 (description
2854 "XNNPACK is a highly optimized library of floating-point neural network
2855 inference operators for ARM, WebAssembly, and x86 platforms. XNNPACK is not
2856 intended for direct use by deep learning practitioners and researchers;
2857 instead it provides low-level performance primitives for accelerating
2858 high-level machine learning frameworks, such as TensorFlow Lite,
2859 TensorFlow.js, PyTorch, and MediaPipe.")
2860 (license license:bsd-3))))
2861
2862 ;; Please also update python-torchvision when updating this package.
2863 (define-public python-pytorch
2864 (package
2865 (name "python-pytorch")
2866 (version "1.12.0")
2867 (source (origin
2868 (method git-fetch)
2869 (uri (git-reference
2870 (url "https://github.com/pytorch/pytorch")
2871 (commit (string-append "v" version))
2872 (recursive? #t)))
2873 (file-name (git-file-name name version))
2874 (sha256
2875 (base32
2876 "0pdqi91qzgyx947zv4pw2fdj9vpqvdhfzw1ydjd4mpqm8g5njgnz"))
2877 (patches (search-patches "python-pytorch-system-libraries.patch"
2878 "python-pytorch-runpath.patch"))
2879 (modules '((guix build utils)))
2880 (snippet
2881 '(begin
2882 ;; XXX: Let's be clear: this package is a bundling fest. We
2883 ;; delete as much as we can, but there's still a lot left.
2884 (for-each (lambda (directory)
2885 (delete-file-recursively
2886 (string-append "third_party/" directory)))
2887 '("benchmark" "cpuinfo" "eigen"
2888
2889 ;; FIXME: QNNPACK (of which XNNPACK is a fork)
2890 ;; needs these.
2891 ;; "FP16" "FXdiv" "gemmlowp" "psimd"
2892
2893 "gloo" "googletest" "ios-cmake" "NNPACK"
2894 "onnx" "protobuf" "pthreadpool"
2895 "pybind11" "python-enum" "python-peachpy"
2896 "python-six" "tbb" "XNNPACK" "zstd"))))))
2897 (build-system python-build-system)
2898 (arguments
2899 '(#:phases (modify-phases %standard-phases
2900 (add-before 'build 'use-system-libraries
2901 (lambda* (#:key outputs #:allow-other-keys)
2902 ;; Tell 'setup.py' to let 'CMakeLists.txt' know that we
2903 ;; want to use "system libraries" instead of the bundled
2904 ;; ones.
2905 (setenv "USE_SYSTEM_LIBS" "1")
2906
2907 (substitute* "cmake/Dependencies.cmake"
2908 (("if\\(USE_SYSTEM_BIND11\\)")
2909 "if(TRUE)"))
2910
2911 ;; XXX: Disable that for simplicity for now.
2912 (setenv "USE_FBGEMM" "0")))
2913 (add-before 'build 'make-things-writable
2914 (lambda _
2915 ;; The 'build_caffe2' function in
2916 ;; 'tools/build_pytorch_libs.py', called from the
2917 ;; top-level 'setup.py', needs write access to this
2918 ;; directory.
2919 (for-each make-file-writable
2920 (find-files "caffe2/proto" "."
2921 #:directories? #t))))
2922 (replace 'check
2923 (lambda* (#:key inputs outputs tests? #:allow-other-keys)
2924 ;; Run the test suite following the instructions in
2925 ;; 'CONTRIBUTING.md'. XXX: Unfortunately this doesn't
2926 ;; work, unless you set GUIX_PYTHONPATH presumably.
2927 (when tests?
2928 (add-installed-pythonpath inputs outputs)
2929 (invoke "python" "test/run_test.py"))))
2930 (add-after 'install 'remove-test-executables
2931 (lambda* (#:key inputs outputs #:allow-other-keys)
2932 ;; Remove test executables, but keep other executables
2933 ;; such as 'torch_shm_manager' and and .so files such as
2934 ;; 'libtorch_global_deps.so'.
2935 (let ((python-site (site-packages inputs outputs)))
2936 (for-each delete-file
2937 (find-files python-site
2938 "(^test_cpp_rpc|_test)$")))))
2939 (add-after 'install 'remove-caffe2-onnx-scripts
2940 (lambda* (#:key outputs #:allow-other-keys)
2941 (let* ((out (assoc-ref outputs "out"))
2942 (bin (string-append out "/bin")))
2943 ;; Remove 'convert-caffe2-to-onnx' and
2944 ;; 'convert-onnx-to-caffe2': they seem to be
2945 ;; deprecated and they cause a failure of the
2946 ;; 'sanity-check' phase:
2947 ;;
2948 ;; ImportError: cannot import name 'metanet_pb2' from partially initialized module 'caffe2.proto' (most likely due to a circular import)
2949 (for-each delete-file
2950 (find-files bin "^convert-.*caffe2"))
2951
2952 (substitute* (find-files out "^entry_points\\.txt$")
2953 (("^convert-.*" all)
2954 (string-append "# " all "\n")))))))
2955
2956 ;; XXX: Tests attempt to download data such as
2957 ;; <https://raw.githubusercontent.com/pytorch/test-infra/master/stats/slow-tests.json>.
2958 ;; We're also missing some Python modules, such as expecttest.
2959 #:tests? #f))
2960 (native-inputs
2961 (list cmake ninja))
2962 (inputs
2963 (list eigen
2964 ;; ("fmt" ,fmt)
2965 fp16
2966 gemmlowp
2967 googletest
2968 googlebenchmark
2969 gloo
2970 nnpack
2971 openblas
2972 openmpi
2973 pthreadpool
2974 protobuf
2975 pybind11
2976 sleef
2977 xnnpack
2978 zstd))
2979 (propagated-inputs
2980 (list python-astunparse
2981 python-click
2982 python-numpy
2983 python-pyyaml
2984 python-cffi
2985 python-typing-extensions
2986 python-future
2987 python-six
2988 python-requests
2989 onnx ;propagated for its Python modules
2990 onnx-optimizer
2991 cpuinfo))
2992 (home-page "https://pytorch.org/")
2993 (synopsis "Python library for tensor computation and deep neural networks")
2994 (description
2995 "PyTorch is a Python package that provides two high-level features:
2996
2997 @itemize
2998 @item tensor computation (like NumPy) with strong GPU acceleration;
2999 @item deep neural networks (DNNs) built on a tape-based autograd system.
3000 @end itemize
3001
3002 You can reuse Python packages such as NumPy, SciPy, and Cython to extend
3003 PyTorch when needed.
3004
3005 Note: currently this package does not provide GPU support.")
3006 (license license:bsd-3)))
3007
3008 (define-public python-pytorch-for-r-torch
3009 (package
3010 (inherit python-pytorch)
3011 (name "python-pytorch")
3012 (version "1.11.0")
3013 (source (origin
3014 (method git-fetch)
3015 (uri (git-reference
3016 (url "https://github.com/pytorch/pytorch")
3017 (commit (string-append "v" version))
3018 (recursive? #t)))
3019 (file-name (git-file-name name version))
3020 (sha256
3021 (base32
3022 "1zbk7y74r0ycsfa7x59jnhwhs1gj5rs3n89p15y0212iszgbljq8"))
3023 (patches (search-patches "python-pytorch-system-libraries.patch"
3024 "python-pytorch-runpath.patch"))
3025 (modules '((guix build utils)))
3026 (snippet
3027 '(begin
3028 ;; XXX: Let's be clear: this package is a bundling fest. We
3029 ;; delete as much as we can, but there's still a lot left.
3030 (for-each (lambda (directory)
3031 (delete-file-recursively
3032 (string-append "third_party/" directory)))
3033 '("benchmark" "cpuinfo" "eigen"
3034
3035 ;; FIXME: QNNPACK (of which XNNPACK is a fork)
3036 ;; needs these.
3037 ;; "FP16" "FXdiv" "gemmlowp" "psimd"
3038
3039 "gloo" "googletest" "ios-cmake" "NNPACK"
3040 "onnx" "protobuf" "pthreadpool"
3041 "pybind11" "python-enum" "python-peachpy"
3042 "python-six" "tbb" "XNNPACK" "zstd"))))))))
3043
3044 ;; Keep this in sync with python-pytorch
3045 (define-public python-torchvision
3046 (package
3047 (name "python-torchvision")
3048 (version "0.13.0")
3049 (source (origin
3050 (method git-fetch)
3051 (uri (git-reference
3052 (url "https://github.com/pytorch/vision")
3053 (commit (string-append "v" version))
3054 (recursive? #t)))
3055 (file-name (git-file-name name version))
3056 (sha256
3057 (base32
3058 "19f6s3ffwkdvjjbvib18c8n7vhysg58smxzq3rvii1c0z4g3b0cw"))))
3059 (build-system python-build-system)
3060 (arguments
3061 `(#:tests? #false ;the test suite is expensive and there is no easy way
3062 ;to subset it.
3063 #:phases
3064 (modify-phases %standard-phases
3065 (replace 'check
3066 (lambda* (#:key tests? #:allow-other-keys)
3067 (when tests?
3068 (invoke "pytest" "-vv")))))))
3069 (inputs
3070 (list libpng
3071 libjpeg-turbo))
3072 (propagated-inputs
3073 (list python-numpy
3074 python-typing-extensions
3075 python-requests
3076 python-pillow
3077 python-pillow-simd
3078 python-pytorch))
3079 (native-inputs
3080 (list which python-pytest))
3081 (home-page "https://pytorch.org/vision/stable/index.html")
3082 (synopsis " Datasets, transforms and models specific to computer vision")
3083 (description
3084 "The torchvision package consists of popular datasets, model architectures,
3085 and common image transformations for computer vision.")
3086 (license license:bsd-3)))
3087
3088 (define-public python-torchfile
3089 (package
3090 (name "python-torchfile")
3091 (version "0.1.0")
3092 (source (origin
3093 (method url-fetch)
3094 (uri (pypi-uri "torchfile" version))
3095 (sha256
3096 (base32
3097 "0vhklj6krl9r0kdynb4kcpwp8y1ihl2zw96byallay3k9c9zwgd5"))))
3098 (build-system python-build-system)
3099 (arguments '(#:tests? #false)) ;there are no tests
3100 (propagated-inputs
3101 (list python-numpy))
3102 (home-page "https://github.com/bshillingford/python-torchfile")
3103 (synopsis "Torch7 binary serialized file parser")
3104 (description "This package enables you to deserialize Lua torch-serialized objects from
3105 Python.")
3106 (license license:bsd-3)))
3107
3108 (define-public python-hmmlearn
3109 (package
3110 (name "python-hmmlearn")
3111 (version "0.2.6")
3112 (source
3113 (origin
3114 (method url-fetch)
3115 (uri (pypi-uri "hmmlearn" version))
3116 (sha256
3117 (base32
3118 "1my0j3rzp17438idr32ssh0j969a98yjblx5igx5kgiiigr9qa1a"))
3119 (snippet
3120 #~(begin
3121 (use-modules ((guix build utils)))
3122 (delete-file "lib/hmmlearn/_hmmc.c")))))
3123 (build-system python-build-system)
3124 (arguments
3125 `(#:phases
3126 (modify-phases %standard-phases
3127 (replace 'check
3128 (lambda* (#:key inputs outputs tests? #:allow-other-keys)
3129 (when tests?
3130 (add-installed-pythonpath inputs outputs)
3131 (with-directory-excursion (string-append (assoc-ref outputs "out") "/lib")
3132 (invoke "python" "-m" "pytest"))))))))
3133 (propagated-inputs
3134 (list python-cython python-numpy python-scikit-learn python-scipy
3135 python-setuptools-scm))
3136 (native-inputs
3137 (list python-pytest))
3138 (home-page "https://github.com/hmmlearn/hmmlearn")
3139 (synopsis "Hidden Markov Models with scikit-learn like API")
3140 (description
3141 "Hmmlearn is a set of algorithms for unsupervised learning and inference
3142 of Hidden Markov Models.")
3143 (license license:bsd-3)))
3144
3145 ;; Keep this in sync with the r-torch package.
3146 (define-public liblantern
3147 (package
3148 (name "liblantern")
3149 (version "0.8.1")
3150 (source
3151 (origin
3152 (method git-fetch)
3153 (uri (git-reference
3154 (url "https://github.com/mlverse/torch")
3155 (commit (string-append "v" version))))
3156 (file-name (git-file-name name version))
3157 (sha256
3158 (base32 "1q57jsqzv9b70svr6whf04yd08np3x15qq1zm06fbl0sqf0kfn7p"))))
3159 (build-system cmake-build-system)
3160 (arguments
3161 (list
3162 #:tests? #false ;no test target
3163 #:phases
3164 (let ((python-version (version-major+minor (package-version python))))
3165 #~(modify-phases %standard-phases
3166 (add-after 'unpack 'chdir
3167 (lambda _ (chdir "lantern")))
3168 (add-after 'chdir 'do-not-download-binaries
3169 (lambda* (#:key inputs #:allow-other-keys)
3170 (substitute* "CMakeLists.txt"
3171 (("find_package\\(Torch.*") "set(TORCH_CXX_FLAGS \"-ltorch\")\n")
3172 (("retrieve_lib\\(.*") ""))
3173 (let ((site-packages (string-append "/lib/python"
3174 #$python-version
3175 "/site-packages")))
3176 (setenv "LIBRARY_PATH"
3177 (string-append
3178 (search-input-directory
3179 inputs (string-append site-packages "/torch/lib"))
3180 ":" (or (getenv "LIBRARY_PATH") "")))
3181 (setenv "CPLUS_INCLUDE_PATH"
3182 (string-append
3183 (search-input-directory
3184 inputs (string-append
3185 site-packages "/torch/include/torch/csrc/api/include/"))
3186 ":"
3187 (search-input-directory
3188 inputs (string-append site-packages "/torch/include/"))
3189 ":"
3190 (or (getenv "CPLUS_INCLUDE_PATH") "")))
3191 (setenv "C_INCLUDE_PATH"
3192 (string-append
3193 (search-input-directory
3194 inputs (string-append site-packages "/torch/include/"))
3195 ":"
3196 (or (getenv "C_INCLUDE_PATH") ""))))))
3197 (replace 'install
3198 (lambda _
3199 (install-file
3200 "../build/liblantern.so"
3201 (string-append #$output "/lib"))
3202 (copy-recursively
3203 "../lantern/include"
3204 (string-append #$output "/include"))))))))
3205 (inputs (list python-pytorch-for-r-torch))
3206 (home-page "https://github.com/mlverse/torch/")
3207 (synopsis "C API to libtorch")
3208 (description
3209 "Lantern provides a C API to the libtorch machine learning library.")
3210 (license license:expat)))
3211
3212 (define-public python-lap
3213 (package
3214 (name "python-lap")
3215 (version "0.4.0")
3216 (source (origin
3217 (method url-fetch)
3218 (uri (pypi-uri "lap" version))
3219 (sha256
3220 (base32
3221 "0fqfxpq4jg9h4wxjw540gjmvfg1ccc1nssk7i9njg7qfdybxknn4"))))
3222 (build-system python-build-system)
3223 (arguments
3224 `(#:phases
3225 (modify-phases %standard-phases
3226 (replace 'build
3227 (lambda* (#:key inputs #:allow-other-keys)
3228 (invoke "python" "setup.py" "build"
3229 "--cpu-baseline=sse2")))
3230 (replace 'check
3231 (lambda* (#:key tests? #:allow-other-keys)
3232 (when tests?
3233 ;; The tests must be run from elsewhere.
3234 (mkdir-p "/tmp/test")
3235 (copy-recursively "lap/tests" "/tmp/test")
3236 (with-directory-excursion "/tmp/test"
3237 (invoke "pytest" "-vv"))))))))
3238 (propagated-inputs
3239 (list python-numpy
3240 python-scipy))
3241 (native-inputs
3242 (list python-cython python-pytest))
3243 (home-page "https://github.com/gatagat/lap")
3244 (synopsis "Linear Assignment Problem solver (LAPJV/LAPMOD).")
3245 (description "Lap is a linear assignment problem solver using Jonker-Volgenant
3246 algorithm for dense (LAPJV) or sparse (LAPMOD) matrices.")
3247 (license license:bsd-2)))
3248
3249 (define-public python-visdom
3250 (package
3251 (name "python-visdom")
3252 (version "0.1.8.9")
3253 (source (origin
3254 (method url-fetch)
3255 (uri (pypi-uri "visdom" version))
3256 (sha256
3257 (base32
3258 "09kiczx2i5asqsv214fz7sx8wlyldgbqvxwrd0alhjn24cvx4fn7"))))
3259 (build-system python-build-system)
3260 (propagated-inputs
3261 (list python-jsonpatch
3262 python-numpy
3263 python-pillow
3264 python-pyzmq
3265 python-requests
3266 python-scipy
3267 python-six
3268 python-torchfile
3269 python-tornado
3270 python-websocket-client))
3271 (home-page "https://github.com/fossasia/visdom")
3272 (synopsis "Visualizations of live, rich data for Torch and Numpy")
3273 (description
3274 "This package provides a tool for visualizing live, rich data for Torch
3275 and Numpy.")
3276 (license license:asl2.0)))
3277
3278 (define-public python-pyro-api
3279 (package
3280 (name "python-pyro-api")
3281 (version "0.1.2")
3282 (source (origin
3283 (method url-fetch)
3284 (uri (pypi-uri "pyro-api" version))
3285 (sha256
3286 (base32
3287 "086r2h6x9i5d9ayl1x65lx6p84rlydzsn8xingxc588ab3ch1fd1"))))
3288 (build-system python-build-system)
3289 (arguments '(#:tests? #false)) ;requires pyro
3290 (native-inputs
3291 (list python-flake8
3292 python-ipython
3293 python-pytest
3294 python-sphinx
3295 python-sphinx-rtd-theme))
3296 (home-page "https://github.com/pyro-ppl/pyro-api")
3297 (synopsis "Generic API for dispatch to Pyro backends.")
3298 (description "This package provides a generic API for dispatch to Pyro backends.")
3299 (license license:asl2.0)))
3300
3301 (define-public python-pyro-ppl
3302 (package
3303 (name "python-pyro-ppl")
3304 (version "1.8.1")
3305 ;; The sources on pypi don't include tests.
3306 (source
3307 (origin
3308 (method git-fetch)
3309 (uri (git-reference
3310 (url "https://github.com/pyro-ppl/pyro")
3311 (commit version)))
3312 (file-name (git-file-name name version))
3313 (sha256
3314 (base32 "0ns20mr8qgjshzbplrfzaz1xhb9ldbgvrj2rzlsxvns2bi1ddyl5"))))
3315 (build-system python-build-system)
3316 (arguments
3317 `(#:phases
3318 (modify-phases %standard-phases
3319 (replace 'check
3320 (lambda* (#:key tests? #:allow-other-keys)
3321 ;; This tests features that are only implemented when non-free
3322 ;; software is available (Intel MKL or CUDA).
3323 (for-each delete-file
3324 (list "tests/distributions/test_spanning_tree.py"
3325 "tests/infer/mcmc/test_mcmc_api.py"))
3326
3327 ;; Four test_gamma_elbo tests fail with bad values for unknown
3328 ;; reasons.
3329 (delete-file "tests/distributions/test_rejector.py")
3330 ;; This test fails sometimes.
3331 (delete-file "tests/optim/test_optim.py")
3332 (invoke "pytest" "-vv" "--stage=unit"))))))
3333 (propagated-inputs
3334 (list python-numpy
3335 python-opt-einsum
3336 python-pyro-api
3337 python-pytorch
3338 python-tqdm))
3339 (native-inputs
3340 (list ninja
3341 jupyter
3342 python-black
3343 python-flake8
3344 python-graphviz
3345 python-isort
3346 python-lap
3347 python-matplotlib
3348 python-mypy
3349 python-nbformat
3350 python-nbsphinx
3351 python-nbstripout
3352 python-nbval
3353 python-pandas
3354 python-pillow
3355 python-pypandoc
3356 python-pytest
3357 python-pytest-cov
3358 python-pytest-xdist
3359 python-scikit-learn
3360 python-scipy
3361 python-seaborn
3362 python-sphinx
3363 python-sphinx-rtd-theme
3364 python-torchvision
3365 python-visdom
3366 python-wget
3367 python-yapf))
3368 (home-page "https://pyro.ai")
3369 (synopsis "Python library for probabilistic modeling and inference")
3370 (description
3371 "This package provides a Python library for probabilistic modeling and
3372 inference.")
3373 (license license:asl2.0)))