2018-09-18 14:59:41 +00:00
|
|
|
#include "catch_utils.hpp"
|
2018-09-06 19:29:34 +00:00
|
|
|
|
|
|
|
|
#include <torch/jit.h>
|
|
|
|
|
#include <torch/tensor.h>
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2018-09-18 14:59:41 +00:00
|
|
|
CATCH_TEST_CASE("torch script") {
|
|
|
|
|
CATCH_SECTION("multiple functions") {
|
2018-09-06 19:29:34 +00:00
|
|
|
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):
|
2018-09-13 18:10:00 +00:00
|
|
|
while bool(i < 10):
|
2018-09-06 19:29:34 +00:00
|
|
|
a += a
|
|
|
|
|
i += 1
|
|
|
|
|
return a
|
|
|
|
|
)JIT");
|
|
|
|
|
auto a = torch::ones(1);
|
|
|
|
|
auto b = torch::ones(1);
|
|
|
|
|
|
2018-09-18 14:59:41 +00:00
|
|
|
CATCH_REQUIRE(1 == module->run_method("test_mul", a, b).toTensor().toCLong());
|
2018-09-06 19:29:34 +00:00
|
|
|
|
2018-09-18 14:59:41 +00:00
|
|
|
CATCH_REQUIRE(2 == module->run_method("test_relu", a, b).toTensor().toCLong());
|
2018-09-06 19:29:34 +00:00
|
|
|
|
2018-09-18 14:59:41 +00:00
|
|
|
CATCH_REQUIRE(
|
2018-09-06 19:29:34 +00:00
|
|
|
0x200 == module->run_method("test_while", a, b).toTensor().toCLong());
|
|
|
|
|
}
|
|
|
|
|
}
|