homebrew-core/Formula/libtorch.rb
2019-11-28 12:50:58 -05:00

70 lines
2.1 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.3.1",
:revision => "ee77ccbb6da4e2efd83673e798acf7081bc03564"
revision 1
bottle do
cellar :any
sha256 "b6d4961d7c1baaff41dd09ec6a37c1a4bc991886b2c24155572eaa693f687a3f" => :catalina
sha256 "d75117d358cdc75fdd03caff3fc77b3a0ef91bf3d457d4eccf6c77d1b9332eee" => :mojave
sha256 "4f4e8bff70d04eeef62e99411cc9bafedfb14082e50f500911c809bd20433b5d" => :high_sierra
end
depends_on "cmake" => :build
depends_on "python" => :build
depends_on "eigen"
depends_on "libomp"
depends_on "protobuf"
resource "PyYAML" do
url "https://files.pythonhosted.org/packages/e3/e8/b3212641ee2718d556df0f23f78de8303f068fe29cdaa7a91018849582fe/PyYAML-5.1.2.tar.gz"
sha256 "01adf0b6c6f61bd11af6e10ca52b7d4057dd0be0343eb9283c878cf3af56aee4"
end
resource "typing" do
url "https://files.pythonhosted.org/packages/67/b0/b2ea2bd67bfb80ea5d12a5baa1d12bda002cab3b6c9b48f7708cd40c34bf/typing-3.7.4.1.tar.gz"
sha256 "91dfe6f3f706ee8cc32d38edbbf304e9b7583fb37108fef38229617f8b3eba23"
end
def install
venv = virtualenv_create(libexec, "python3")
venv.pip_install resources
args = %W[
-DBUILD_CUSTOM_PROTOBUF=OFF
-DBUILD_PYTHON=OFF
-DPYTHON_EXECUTABLE=#{libexec}/bin/python
-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++11", "-L#{lib}", "-ltorch", "-lc10",
"-I#{include}/torch/csrc/api/include", "test.cpp", "-o", "test"
system "./test"
end
end