class_docstr: Encoder that encodes long or float tensors into scaled integer tensors.
docstr: Helper function to wrap data if needed
docstr_tok: ["Helper","function","to","wrap","data","if","needed"]
code: def encode(self, x, device=None):
      """Helper function to wrap data if needed"""
      if isinstance(x, CrypTensor):
          return x
      elif isinstance(x, int) or isinstance(x, float):
          # Squeeze in order to get a 0-dim tensor with value `x`
          return torch.tensor(
              [self._scale * x], dtype=torch.long, device=device
          ).squeeze()
      elif isinstance(x, list):
          return (
              torch.tensor(x, dtype=torch.float, device=device)
              .mul_(self._scale)
              .long()
          )
      elif is_float_tensor(x):
          return (self._scale * x).long()
      # For integer types cast to long prior to scaling to avoid overflow.
      elif is_int_tensor(x):
          return self._scale * x.long()
      elif isinstance(x, np.ndarray):
          return self._scale * torch.from_numpy(x).long().to(device)
      elif isinstance(x, DTensor):
          return DTensor(
              x.shardings.map_shard(
                  lambda v: self.encode(v, device=device),
                  dtype=torch.long,
              )
          )
      elif torch.is_tensor(x):
          raise TypeError("Cannot encode input with dtype %s" % x.dtype)
      else:
          raise TypeError("Unknown tensor type: %s." % type(x))
  
file_path: FATE/python/fate/arch/protocol/mpc/encoder.py
imports: import math
  import numpy
  import torch
  from fate.arch.tensor import DTensor
  from .common.tensor_types import is_float_tensor, is_int_tensor
  from .config import cfg
  from .cryptensor import CrypTensor
label_desc: Use image node_id 2 for calling the FixedPointEncoder obj's underlying member method code with example usage: obj.encode(x, device) and returns: x, torch, torch, unknown, unknown, unknown, DTensor