class_docstr: This class tests all functions of BinarySharedTensor.
class_docstr_tok: ["This","class","tests","all","functions","of","BinarySharedTensor","."]
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 ["__xor__", "__and__", "__or__"]:
          for tensor_type in [lambda x: x, BinarySharedTensor]:
              tensor1 = get_random_test_tensor(is_float=False)
              tensor2 = get_random_test_tensor(is_float=False)
  
              reference = getattr(tensor1, op)(tensor2)
  
              encrypted1 = BinarySharedTensor(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, BinarySharedTensor)
              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
              inplace_op = op[:2] + "i" + op[2:]
              encrypted_out = getattr(encrypted1, inplace_op)(
                  encrypted2
              )
              self._check(
                  encrypted1,
                  reference,
                  "%s in-place %s does not modify input"
                  % ("private" if private else "public", inplace_op),
              )
              self._check(
                  encrypted_out,
                  reference,
                  "%s in-place %s produces incorrect output"
                  % ("private" if private else "public", inplace_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 torch
  from crypten.common.tensor_types import is_int_tensor
  from crypten.mpc.primitives import BinarySharedTensor
  from test.multiprocess_test_case import get_random_test_tensor, MultiProcessTestCase
label_desc: Use image node_id 16 for calling the TestBinary obj's underlying member method code with example usage: obj.test_inplace() without return types