pytorch/test/cpp/api/jit.cpp
David Riazati 6f53b4efea Remove implicit bool casts (#11503)
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
2018-09-13 11:26:45 -07:00

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());
}
}