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_pdt(self):
      def test_sum(a, b):
          return a + b
  
      make_global(test_sum)
      scripted_fn_add = torch.jit.script(
          test_sum, example_inputs=[(3, 4)]
      )
      self.assertEqual(scripted_fn_add(10, 2), test_sum(10, 2))
  
      def test_sub(a, b):
          return a - b
  
      make_global(test_sub)
      scripted_fn_sub = torch.jit.script(
          test_sub, example_inputs=[(3.9, 4.10)]
      )
      self.assertEqual(scripted_fn_sub(6.5, 2.9), test_sub(6.5, 2.9))
  
      def test_mul(a, b):
          return a * b
  
      make_global(test_mul)
      scripted_fn_mul = torch.jit.script(
          test_mul, example_inputs=[(-10, 9)]
      )
      self.assertEqual(scripted_fn_mul(-1, 3), test_mul(-1, 3))
  
      def test_args_complex(real, img):
          return torch.complex(real, img)
  
      make_global(test_args_complex)
      scripted_fn_complex = torch.jit.script(
          test_args_complex,
          example_inputs=[(torch.rand(3, 4), torch.rand(3, 4))],
      )
      arg1, arg2 = torch.rand(3, 4), torch.rand(3, 4)
      self.assertEqual(
          scripted_fn_complex(arg1, arg2), test_args_complex(arg1, arg2)
      )
  
      def test_bool(a):
          if a:
              return -1
          else:
              return 0
  
      make_global(test_bool)
      scripted_fn_bool = torch.jit.script(
          test_bool, example_inputs=[(True,)]
      )
      self.assertEqual(scripted_fn_bool(True), test_bool(True))
  
      def test_str(a):
          if a == "":
              return False
          else:
              return True
  
      make_global(test_str)
      scripted_fn_str = torch.jit.script(
          test_str, example_inputs=[("",)]
      )
      self.assertEqual(scripted_fn_str("abc"), test_str("abc"))
  
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 9 for calling the TestPDT obj's underlying member method code with example usage: obj.test_pdt() and returns: unknown, unknown, unknown, torch, unknown, int, False, True