code: def test_scatter_expanded_index(self, device, dtype):
      def helper(input_size, idx_size):
          input = torch.randn(input_size, device=device).to(dtype=dtype)
          input2 = input.clone()
  
          shape = [1] * len(input_size)
          shape[0] = idx_size
          dim_size = input_size[0]
          idx = torch.randint(0, dim_size, shape)
  
          # The fast path on scatter when index is expanded
          # will depend on sorted index where the collected src indice
          # for each row in input will be mapped to rowptrs in a CSR format.
          # Create some empty rows by masking:
          mask = (idx > 1) * (idx < 4)
          idx[mask] = 0
  
          expanded_shape = input_size
          expanded_shape[0] = idx_size
          idx = idx.expand(expanded_shape)
          idx2 = idx.contiguous()
          src = torch.randn(expanded_shape, device=device).to(
              dtype=dtype
          )
  
          out = input.scatter_add(0, idx, src)
          out2 = input2.scatter_add(0, idx2, src)
          self.assertEqual(out, out2)
  
          for reduce in ["sum", "prod", "mean", "amax", "amin"]:
              for include_self in [True, False]:
                  out = input.scatter_reduce(
                      0,
                      idx,
                      src,
                      reduce=reduce,
                      include_self=include_self,
                  )
                  out2 = input2.scatter_reduce(
                      0,
                      idx2,
                      src,
                      reduce=reduce,
                      include_self=include_self,
                  )
                  self.assertEqual(out, out2)
  
      helper([50, 17], 100)
      helper([50, 1], 100)
      helper([50, 8, 7], 100)
      helper([50, 3, 4, 5], 100)
  
imports: import random
  import torch
  from torch.testing import make_tensor
  from torch.testing._internal.common_utils import parametrize, run_tests, TestCase, DeterministicGuard
  from torch.testing._internal.common_device_type import instantiate_device_type_tests, onlyCPU, dtypes, dtypesIfCUDA, toleranceOverride, tol
  from torch.testing._internal.common_dtype import get_all_dtypes
label_desc: Use image node_id 16 for calling the TestScatterGather obj's underlying member method code with example usage: obj.test_scatter_expanded_index(device, dtype) without return types