code: def _one_hot_to_index(tensor, dim, keepdim, device=None):
      """
      Converts a one-hot tensor output from an argmax / argmin function to a
      tensor containing indices from the input tensor from which the result of the
      argmax / argmin was obtained.
      """
      if dim is None:
          result = tensor.flatten()
          result = result * torch.tensor(
              list(range(tensor.nelement())), device=device
          )
          return result.sum()
      else:
          size = [1] * tensor.dim()
          size[dim] = tensor.size(dim)
          result = tensor * torch.tensor(
              list(range(tensor.size(dim))), device=device
          ).view(size)
          return result.sum(dim, keepdim=keepdim)
  
file_path: CrypTen/crypten/common/functions/maximum.py
imports: import math
  import crypten
  import torch
  from crypten.config import cfg
label_desc: Use image node_id 14 for calling a global function with example usage: _one_hot_to_index(tensor, dim, keepdim, device) and returns: result, result