class_docstr: Encrypted tensor object that uses binary sharing to perform computations.
  
  Binary shares are computed by splitting each value of the input tensor
  into n separate random values that xor together to the input tensor value,
  where n is the number of parties present in the protocol (world_size).
class_docstr_tok: ["Encrypted","tensor","object","that","uses","binary","sharing","to","perform","computations",".","Binary","shares","are","computed","by","splitting","each","value","of","the","input","tensor","into","n","separate","random","values","that","xor","together","to","the","input","tensor","value",",","where","n","is","the","number","of","parties","present","in","the","protocol","(","world_size",")","."]
docstr: Add all tensors along a given dimension using a log-reduction
docstr_tok: ["Add","all","tensors","along","a","given","dimension","using","a","log-reduction"]
code: def sum(self, dim=None):
      """Add all tensors along a given dimension using a log-reduction"""
      if dim is None:
          x = self.flatten()
      else:
          x = self.transpose(0, dim)
  
      # Add all BinarySharedTensors
      while x.size(0) > 1:
          extra = None
          if x.size(0) % 2 == 1:
              extra = x[0]
              x = x[1:]
          x0 = x[: (x.size(0) // 2)]
          x1 = x[(x.size(0) // 2) :]
          x = x0 + x1
          if extra is not None:
              x.share = torch_cat([x.share, extra.share.unsqueeze(0)])
  
      if dim is None:
          x = x.squeeze()
      else:
          x = x.transpose(0, dim).squeeze(dim)
      return x
  
imports: import crypten.communicator
  import torch
  from crypten.common.functions import regular
  from crypten.common.rng import generate_kbit_random_tensor
  from crypten.common.tensor_types import is_tensor
  from crypten.common.util import torch_cat, torch_stack
  from crypten.cuda import CUDALongTensor
  from crypten.encoder import FixedPointEncoder
  from .None import beaver, circuit
label_desc: Use image node_id 40 for calling the BinarySharedTensor obj's underlying member method code with example usage: obj.sum(dim) and returns: x