class_docstr: This class tests all functions of the ArithmeticSharedTensor.
docstr: Test index_add function of encrypted tensor
docstr_tok: ["Test","index_add","function","of","encrypted","tensor"]
code: def test_index_add(self) -> None:
      """Test index_add function of encrypted tensor"""
      index_add_functions = ["index_add", "index_add_"]
      tensor_size1 = [5, 5, 5, 5]
      index = torch.tensor([1, 2, 3, 4, 4, 2, 1, 3], dtype=torch.long)
      for dimension in range(0, 4):
          tensor_size2 = [5, 5, 5, 5]
          tensor_size2[dimension] = index.size(0)
          for func in index_add_functions:
              for tensor_type in [lambda x: x, ArithmeticSharedTensor]:
                  tensor1 = get_random_test_tensor(
                      size=tensor_size1, is_float=True
                  )
                  tensor2 = get_random_test_tensor(
                      size=tensor_size2, is_float=True
                  )
                  encrypted = ArithmeticSharedTensor(tensor1)
                  encrypted2 = tensor_type(tensor2)
  
                  reference = getattr(tensor1, func)(
                      dimension, index, tensor2
                  )
                  encrypted_out = getattr(encrypted, func)(
                      dimension, index, encrypted2
                  )
                  private = tensor_type == ArithmeticSharedTensor
                  self._check(
                      encrypted_out,
                      reference,
                      "%s %s failed"
                      % ("private" if private else "public", func),
                  )
                  if func.endswith("_"):
                      # Check in-place index_add worked
                      self._check(
                          encrypted,
                          reference,
                          "%s %s failed"
                          % ("private" if private else "public", func),
                      )
                  else:
                      # Check original is not modified
                      self._check(
                          encrypted,
                          tensor1,
                          "%s %s failed"
                          % ("private" if private else "public", func),
                      )
  
imports: import itertools
  import logging
  import unittest
  import crypten
  import crypten.communicator
  import torch
  import torch.nn.functional
  from crypten.common.rng import generate_random_ring_element
  from crypten.common.tensor_types import is_float_tensor
  from crypten.common.util import count_wraps
  from crypten.mpc.primitives import ArithmeticSharedTensor
  from test.multiprocess_test_case import get_random_test_tensor, MultiProcessTestCase
label_desc: Use image node_id 11 for calling the TestArithmetic obj's underlying member method code with example usage: obj.test_index_add() without return types