mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/11780 Differential Revision: D9889925 Pulled By: gchanan fbshipit-source-id: 5eca849c36ced00b8ae7482b7945b445a3e1687e
32 lines
774 B
C++
32 lines
774 B
C++
#include "catch_utils.hpp"
|
|
|
|
#include <torch/jit.h>
|
|
#include <torch/tensor.h>
|
|
|
|
#include <string>
|
|
|
|
CATCH_TEST_CASE("torch script") {
|
|
CATCH_SECTION("multiple functions") {
|
|
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);
|
|
|
|
CATCH_REQUIRE(1 == module->run_method("test_mul", a, b).toTensor().toCLong());
|
|
|
|
CATCH_REQUIRE(2 == module->run_method("test_relu", a, b).toTensor().toCLong());
|
|
|
|
CATCH_REQUIRE(
|
|
0x200 == module->run_method("test_while", a, b).toTensor().toCLong());
|
|
}
|
|
}
|