code: def _threshold_and_support(input, dim=0):
      """Sparsemax building block: compute the threshold
  
      Args:
          input: any dimension
          dim: dimension along which to apply the sparsemax
  
      Returns:
          the threshold value
      """
  
      input_srt, _ = torch.sort(input, descending=True, dim=dim)
      input_cumsum = input_srt.cumsum(dim) - 1
      rhos = _make_ix_like(input, dim)
      support = rhos * input_srt > input_cumsum
  
      support_size = support.sum(dim=dim).unsqueeze(dim)
      tau = input_cumsum.gather(dim, support_size - 1)
      tau /= support_size.to(input.dtype)
      return tau, support_size
  
file_path: OpenNMT-py/onmt/modules/sparse_activations.py
imports: import torch
  from torch.autograd import Function
  from torch.cuda.amp import custom_fwd, custom_bwd
  import torch.nn
label_desc: Use image node_id 2 for calling a global function with example usage: _threshold_and_support(input, dim) and returns: tau,  support_size