mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 00:21:07 +01:00
Summary: In order to comply with Python's rules on implicit casting of non-booleans to booleans, this PR removes implicit casting in favor of explicit casts via `bool()` cc zdevito Pull Request resolved: https://github.com/pytorch/pytorch/pull/11503 Differential Revision: D9780869 Pulled By: driazati fbshipit-source-id: c753acaca27f4e79dddf424c6b04674f44a6aad9
32 lines
738 B
C++
32 lines
738 B
C++
#include <catch.hpp>
|
|
|
|
#include <torch/jit.h>
|
|
#include <torch/tensor.h>
|
|
|
|
#include <string>
|
|
|
|
TEST_CASE("torch script") {
|
|
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);
|
|
|
|
REQUIRE(1 == module->run_method("test_mul", a, b).toTensor().toCLong());
|
|
|
|
REQUIRE(2 == module->run_method("test_relu", a, b).toTensor().toCLong());
|
|
|
|
REQUIRE(
|
|
0x200 == module->run_method("test_while", a, b).toTensor().toCLong());
|
|
}
|
|
}
|