class_docstr: A suite of tests for profile directed typing in TorchScript.
class_docstr_tok: ["A","suite","of","tests","for","profile","directed","typing","in","TorchScript","."]
code: def test_any(self):
      def test_multiple_types(a):
          assert not isinstance(a, bool)
          return a
  
      def test_multiple_type_refinement(a):
          if isinstance(a, bool):
              return 1
          elif isinstance(a, int):
              return 1 + a
          elif isinstance(a, float):
              return 1 + int(a)
          else:
              return -1
  
      make_global(test_multiple_types, test_multiple_type_refinement)
  
      scripted_fn = torch.jit.script(
          test_multiple_types,
          example_inputs=[(1,), ("abc",), (8.9,), ([3, 4, 5],)],
      )
      self.assertEqual(scripted_fn(10), test_multiple_types(10))
      self.assertEqual(scripted_fn("def"), test_multiple_types("def"))
      self.assertEqual(
          scripted_fn(7.89999), test_multiple_types(7.89999)
      )
      self.assertEqual(
          scripted_fn([10, 11, 14]), test_multiple_types([10, 11, 14])
      )
  
      scripted_fn = torch.jit.script(
          test_multiple_type_refinement,
          example_inputs=[
              (1,),
              ("abc",),
              (8.9,),
              ([3, 4, 5],),
              (True,),
              ({"a": True},),
          ],
      )
      self.assertEqual(
          scripted_fn(10), test_multiple_type_refinement(10)
      )
      self.assertEqual(
          scripted_fn("def"), test_multiple_type_refinement("def")
      )
      self.assertEqual(
          scripted_fn(7.89999), test_multiple_type_refinement(7.89999)
      )
      self.assertEqual(
          scripted_fn([10, 11, 14]),
          test_multiple_type_refinement([10, 11, 14]),
      )
      self.assertEqual(
          scripted_fn(False), test_multiple_type_refinement(False)
      )
      self.assertEqual(
          scripted_fn({"abc": True, "def": False}),
          test_multiple_type_refinement({"abc": True, "def": False}),
      )
  
imports: import os
  import sys
  import torch
  from torch.testing._internal.jit_utils import JitTestCase, make_global
  from torch.jit._monkeytype_config import _IS_MONKEYTYPE_INSTALLED
  from typing import List, Dict, Tuple, Any, Optional, NamedTuple
  from torch.testing._internal.common_utils import NoTest
label_desc: Use image node_id 13 for calling the TestPDT obj's underlying member method code with example usage: obj.test_any() and returns: a, int, unknown, unknown, unknown