homebrew-core/Formula/libtorch.rb

79 lines
2.3 KiB
Ruby

class Libtorch < Formula
include Language::Python::Virtualenv
desc "Tensors and dynamic neural networks"
homepage "https://pytorch.org/"
url "https://github.com/pytorch/pytorch.git",
tag: "v1.7.1",
revision: "57bffc3a8e4fee0cce31e1ff1f662ccf7b16db57"
license "BSD-3-Clause"
revision 1
livecheck do
url :stable
strategy :github_latest
end
bottle do
sha256 cellar: :any, big_sur: "b0688c3e965b190612de4ebc1b3b8e37b5b334e0c250ede0f69257e6bd4be7df"
sha256 cellar: :any, catalina: "4fc2881e79a5ddd302c9239c577480086b7988d052000d784fd30c8666024a30"
sha256 cellar: :any, mojave: "c11f64cab20420978c90c49259c7bce8da7e03f0bba6f6d51d3041b3788697da"
end
depends_on "cmake" => :build
depends_on "python@3.9" => :build
depends_on "eigen"
depends_on "libomp"
depends_on "libyaml"
depends_on "protobuf"
depends_on "pybind11"
resource "PyYAML" do
url "https://files.pythonhosted.org/packages/64/c2/b80047c7ac2478f9501676c988a5411ed5572f35d1beff9cae07d321512c/PyYAML-5.3.1.tar.gz"
sha256 "b8eac752c5e14d3eca0e6dd9199cd627518cb5ec06add0de9d32baeee6fe645d"
end
resource "typing" do
url "https://files.pythonhosted.org/packages/05/d9/6eebe19d46bd05360c9a9aae822e67a80f9242aabbfc58b641b957546607/typing-3.7.4.3.tar.gz"
sha256 "1187fb9c82fd670d10aa07bbb6cfcfe4bdda42d6fab8d5134f04e8c4d0b71cc9"
end
def install
venv = virtualenv_create(libexec, Formula["python@3.9"].opt_bin/"python3")
venv.pip_install resources
args = %W[
-DBUILD_CUSTOM_PROTOBUF=OFF
-DBUILD_PYTHON=OFF
-DPYTHON_EXECUTABLE=#{libexec}/bin/python
-Dpybind11_PREFER_third_party=OFF
-DUSE_CUDA=OFF
-DUSE_METAL=OFF
-DUSE_MKLDNN=OFF
-DUSE_NNPACK=OFF
-DUSE_SYSTEM_EIGEN_INSTALL=ON
]
mkdir "build" do
system "cmake", "..", *std_cmake_args, *args
system "make"
system "make", "install"
end
end
test do
(testpath/"test.cpp").write <<~EOS
#include <torch/torch.h>
#include <iostream>
int main() {
torch::Tensor tensor = torch::rand({2, 3});
std::cout << tensor << std::endl;
}
EOS
system ENV.cxx, "-std=c++14", "-L#{lib}", "-ltorch", "-ltorch_cpu", "-lc10",
"-I#{include}/torch/csrc/api/include", "test.cpp", "-o", "test"
system "./test"
end
end