summary refs log tree commit diff
path: root/gnu
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2022-02-11 15:40:29 +0100
committerRicardo Wurmus <rekado@elephly.net>2022-02-11 15:44:42 +0100
commit7146e553b94992e89349fe76915e59de88418d8f (patch)
tree8a959e2155e4e846d3fab9aee83e65d8d84ce895 /gnu
parent7b676317b3e49fe0bd2a44741d8d383f5c85d76a (diff)
downloadguix-7146e553b94992e89349fe76915e59de88418d8f.tar.gz
gnu: Add liblantern.
* gnu/packages/machine-learning.scm (liblantern): New variable.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/packages/machine-learning.scm62
1 files changed, 62 insertions, 0 deletions
diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm
index 0c01617297..2f7e1ac5d9 100644
--- a/gnu/packages/machine-learning.scm
+++ b/gnu/packages/machine-learning.scm
@@ -3113,3 +3113,65 @@ Note: currently this package does not provide GPU support.")
      "Hmmlearn is a set of algorithms for unsupervised learning and inference
 of Hidden Markov Models.")
     (license license:bsd-3)))
+
+;; Keep this in sync with the r-torch package.
+(define-public liblantern
+  (package
+    (name "liblantern")
+    (version "0.6.0")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/mlverse/torch")
+             (commit (string-append "v" version))))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "1gabwic46m4m7qld1yi4brw05n9jx58ri3y0pi6jf9jndfi1qnfp"))))
+    (build-system cmake-build-system)
+    (arguments
+     (list
+      #:tests? #false                   ;no test target
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'chdir
+            (lambda _ (chdir "lantern")))
+          (add-after 'chdir 'do-not-download-binaries
+            (lambda* (#:key inputs #:allow-other-keys)
+              (substitute* "CMakeLists.txt"
+                (("find_package\\(Torch.*") "set(TORCH_CXX_FLAGS \"-ltorch\")\n")
+                (("retrieve_lib\\(.*") ""))
+              (setenv "LIBRARY_PATH"
+                      (string-append
+                       (search-input-directory
+                        inputs "/lib/python3.9/site-packages/torch/lib")
+                       ":" (or (getenv "LIBRARY_PATH") "")))
+              (setenv "CPLUS_INCLUDE_PATH"
+                      (string-append
+                       (search-input-directory
+                        inputs "lib/python3.9/site-packages/torch/include/torch/csrc/api/include/")
+                       ":"
+                       (search-input-directory
+                        inputs "lib/python3.9/site-packages/torch/include/")
+                       ":"
+                       (or (getenv "CPLUS_INCLUDE_PATH") "")))
+              (setenv "C_INCLUDE_PATH"
+                      (string-append
+                       (search-input-directory
+                        inputs "lib/python3.9/site-packages/torch/include/")
+                       ":"
+                       (or (getenv "C_INCLUDE_PATH") "")))))
+          (replace 'install
+            (lambda _
+              (install-file
+               "../build/liblantern.so"
+               (string-append #$output "/lib"))
+              (copy-recursively
+               "../lantern/include"
+               (string-append #$output "/include")))))))
+    (inputs (list python-pytorch-for-r-torch))
+    (home-page "https://github.com/mlverse/torch/")
+    (synopsis "C API to libtorch")
+    (description
+     "Lantern provides a C API to the libtorch machine learning library.")
+    (license license:expat)))