class_docstr: This class tests all functions of the ArithmeticSharedTensor.
docstr: Test inplace vs. out-of-place functions
docstr_tok: ["Test","inplace","vs.","out-of-place","functions"]
code: def test_inplace(self) -> None:
      """Test inplace vs. out-of-place functions"""
      for op in ["add", "sub", "mul", "div"]:
          for tensor_type in [lambda x: x, ArithmeticSharedTensor]:
              tensor1 = get_random_test_tensor(is_float=True)
              tensor2 = get_random_test_tensor(is_float=True)
  
              # ArithmeticSharedTensors can't divide by negative
              # private values - MPCTensor overrides this to allow negatives
              if op == "div" and tensor_type == ArithmeticSharedTensor:
                  continue
  
              reference = getattr(torch, op)(tensor1, tensor2)
  
              encrypted1 = ArithmeticSharedTensor(tensor1)
              encrypted2 = tensor_type(tensor2)
  
              input_plain_id = id(encrypted1.share)
              input_encrypted_id = id(encrypted1)
  
              # Test that out-of-place functions do not modify the input
              private = isinstance(encrypted2, ArithmeticSharedTensor)
              encrypted_out = getattr(encrypted1, op)(encrypted2)
              self._check(
                  encrypted1,
                  tensor1,
                  "%s out-of-place %s modifies input"
                  % ("private" if private else "public", op),
              )
              self._check(
                  encrypted_out,
                  reference,
                  "%s out-of-place %s produces incorrect output"
                  % ("private" if private else "public", op),
              )
              self.assertFalse(
                  id(encrypted_out.share) == input_plain_id
              )
              self.assertFalse(id(encrypted_out) == input_encrypted_id)
  
              # Test that in-place functions modify the input
              encrypted_out = getattr(encrypted1, op + "_")(encrypted2)
              self._check(
                  encrypted1,
                  reference,
                  "%s in-place %s_ does not modify input"
                  % ("private" if private else "public", op),
              )
              self._check(
                  encrypted_out,
                  reference,
                  "%s in-place %s_ produces incorrect output"
                  % ("private" if private else "public", op),
              )
              self.assertTrue(id(encrypted_out.share) == input_plain_id)
              self.assertTrue(id(encrypted_out) == input_encrypted_id)
  
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 32 for calling the TestArithmetic obj's underlying member method code with example usage: obj.test_inplace() without return types