x: int = 2
fn(x)
self.assertEqual(len(w), 0)
+
+ def test_empty_container_special_cases(self):
+ # Should not throw "Boolean value of Tensor with no values is
+ # ambiguous" error
+ torch._jit_internal.check_empty_containers(torch.Tensor([]))
+
+ # Should not throw "Boolean value of Tensor with more than
+ # one value is ambiguous" error
+ torch._jit_internal.check_empty_containers(torch.rand(2, 3))
self.assertEqual(test_bool_arith_not(torch.zeros(3)), 1)
self.assertTrue(str(test_bool_arith_not.graph).count('if') == 0)
-
def test_conditional_casting(self):
def test_bool_cast_tensor(x):
if x:
def check_empty_containers(obj) -> None:
- if not obj:
+ if obj == [] or obj == {} or obj == ():
warnings.warn("The inner type of a container is lost when "
"calling torch.jit.isinstance in eager mode. For "
"example, List[int] would become list and "