code: def test_index(self):
      def consec(size, start=0):
          numel = torch.tensor(size).prod().item()
          return torch.arange(numel).view(size)
  
      def check_indexing(indexing, tensor):
          template = dedent(
              """
              def func(x):
                  return x{}
              """
          )
  
          self._check_code(template.format(indexing), "func", [tensor])
  
      def check_dynamic_indexing(indexing, tensor, value1, value2):
          value1 = torch.tensor(value1)
          value2 = torch.tensor(value2)
  
          template = dedent(
              """
              def func(x, value1, value2):
                  i = int(value1)
                  j = int(value2)
                  return x{}
              """
          )
  
          self._check_code(
              template.format(indexing),
              "func",
              [tensor, value1, value2],
          )
  
      # basic slices
      check_indexing("[0]", consec((3, 3)))
      check_indexing("[1]", consec((3, 3), 10))
      check_indexing("[2]", consec((3, 3), 19))
      check_indexing("[2]", consec((3,)))
      check_indexing("[-1]", consec((3, 3), 19))
      check_indexing("[0:2]", consec((3, 3, 3)))
      check_indexing("[1:-1]", consec((3, 3, 3)))
      check_indexing("[-3:-1]", consec((6, 3)))
      check_indexing("[1:]", consec((3, 3)))
      check_indexing("[:1]", consec((3, 3)))
      check_indexing("[:]", consec((3, 2)))
  
      # multi-dim: indexes
      check_indexing("[0, 1]", consec((3, 3)))
      check_indexing("[0, 1]", consec((3, 3, 2)))
      check_indexing("[1, 0, 2]", consec((3, 3, 3)))
      check_indexing("[2, -1]", consec((3, 3)))
  
      # multi-dim: mixed slicing and indexing
      check_indexing("[0, 1:2]", consec((3, 3)))
      check_indexing("[0, :1]", consec((3, 3, 2)))
      check_indexing("[1, 2:]", consec((3, 3, 3)))
      check_indexing("[-1, 1:, 0]", consec((3, 3, 3, 3)))
      check_indexing("[1:, -1, 0]", consec((3, 3, 3, 3)))
      check_indexing("[-1, 2:, 1:2]", consec((3, 3, 3, 3)))
      check_indexing("[-1, 1:, 0]", consec((3, 3, 3, 3)))
      check_indexing("[-1, :, 0, 2]", consec((3, 3, 3, 3)))
  
      # zero-sized slices
      check_indexing("[0:0]", consec((2, 2)))
      check_indexing("[0:0, 1]", consec((3, 3)))
  
      # trivial expression usage
      check_indexing("[1+1]", consec((3, 3)))
      check_indexing("[1:(0 + 2)]", consec((3, 3, 3)))
  
      # None for new dimensions
      check_indexing("[None, 0]", consec((3, 3)))
      check_indexing("[1, None]", consec((3, 3), 10))
      check_indexing("[None, None, 2]", consec((3, 3), 19))
      check_indexing("[None, 2, None]", consec((3,)))
      check_indexing("[0:2, None]", consec((3, 3, 3)))
      check_indexing("[None, 1:-1]", consec((3, 3, 3)))
      check_indexing("[None, -3:-1, None]", consec((6, 3)))
      check_indexing("[-1, None, 2:, None, 1:2]", consec((3, 3, 3, 3)))
      check_indexing(
          "[None, -1, None, 2:, None, 1:2, None]", consec((3, 3, 3, 3))
      )
  
      # dynamic expression usage
      check_dynamic_indexing("[i + j]", consec((3, 3)), 0, 1)
      check_dynamic_indexing("[i:j, i]", consec((3, 3, 2)), 0, 2)
  
imports: import os
  import sys
  import tempfile
  import random
  from textwrap import dedent
  import torch
  from torch.testing._internal.jit_utils import JitTestCase, execWrapper
label_desc: Use image node_id 11 for calling the TestPythonBuiltinOP obj's underlying member method code with example usage: obj.test_index() and returns: torch