mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Summary: This PR is a large codemod to rewrite all C++ API tests with GoogleTest (gtest) instead of Catch. You can largely trust me to have correctly code-modded the tests, so it's not required to review every of the 2000+ changed lines. However, additional things I changed were: 1. Moved the cmake parts for these tests into their own `CMakeLists.txt` under `test/cpp/api` and calling `add_subdirectory` from `torch/CMakeLists.txt` 2. Fixing DataParallel tests which weren't being compiled because `USE_CUDA` wasn't correctly being set at all. 3. Updated README ezyang ebetica Pull Request resolved: https://github.com/pytorch/pytorch/pull/11953 Differential Revision: D9998883 Pulled By: goldsborough fbshipit-source-id: affe3f320b0ca63e7e0019926a59076bb943db80
30 lines
719 B
C++
30 lines
719 B
C++
#include <gtest/gtest.h>
|
|
|
|
#include <torch/jit.h>
|
|
#include <torch/tensor.h>
|
|
|
|
#include <string>
|
|
|
|
TEST(TorchScriptTest, CanCompileMultipleFunctions) {
|
|
auto module = torch::jit::compile(R"JIT(
|
|
def test_mul(a, b):
|
|
return a * b
|
|
def test_relu(a, b):
|
|
return torch.relu(a + b)
|
|
def test_while(a, i):
|
|
while bool(i < 10):
|
|
a += a
|
|
i += 1
|
|
return a
|
|
)JIT");
|
|
auto a = torch::ones(1);
|
|
auto b = torch::ones(1);
|
|
|
|
ASSERT_EQ(1, module->run_method("test_mul", a, b).toTensor().toCLong());
|
|
|
|
ASSERT_EQ(2, module->run_method("test_relu", a, b).toTensor().toCLong());
|
|
|
|
ASSERT_TRUE(
|
|
0x200 == module->run_method("test_while", a, b).toTensor().toCLong());
|
|
}
|