class_docstr: Test cases for common functionality.
class_docstr_tok: ["Test","cases","for","common","functionality","."]
docstr: Tests tensor encoding and decoding.
docstr_tok: ["Tests","tensor","encoding","and","decoding","."]
code: def test_encode_decode(self) -> None:
      """Tests tensor encoding and decoding."""
      for float in [False, True]:
          if float:
              fpe = FixedPointEncoder(precision_bits=16)
          else:
              fpe = FixedPointEncoder(precision_bits=0)
          tensor = get_test_tensor(float=float)
          decoded = fpe.decode(fpe.encode(tensor))
          self._check(
              decoded,
              tensor,
              "Encoding/decoding a %s failed." % "float"
              if float
              else "long",
          )
  
      # Make sure encoding a subclass of CrypTensor is a no-op
      cfg.mpc.provider = "TFP"
      crypten.init()
  
      tensor = get_test_tensor(float=True)
      encrypted_tensor = crypten.cryptensor(tensor)
      encrypted_tensor = fpe.encode(encrypted_tensor)
      self._check(
          encrypted_tensor.get_plain_text(),
          tensor,
          "Encoding an EncryptedTensor failed.",
      )
  
      # Try a few other types.
      fpe = FixedPointEncoder(precision_bits=0)
      for dtype in [torch.uint8, torch.int8, torch.int16]:
          tensor = torch.zeros(5, dtype=dtype).random_()
          decoded = fpe.decode(fpe.encode(tensor)).type(dtype)
          self._check(
              decoded, tensor, "Encoding/decoding a %s failed." % dtype
          )
  
file_path: CrypTen/test/test_common.py
imports: import sys
  import unittest
  import crypten
  import torch
  from crypten.common.util import chebyshev_series
  from crypten.config import cfg
  from crypten.encoder import FixedPointEncoder, nearest_integer_division
label_desc: Use image node_id 2 for calling the TestCommon obj's underlying member method code with example usage: obj.test_encode_decode() without return types