class_docstr: An implementation of sparsemax (Martins & Astudillo, 2016). See
  :cite:`DBLP:journals/corr/MartinsA16` for detailed description.
  By Ben Peters and Vlad Niculae
docstr: sparsemax: normalizing sparse transform (a la softmax)
  
  Parameters
  ----------
  ctx : torch.autograd.function._ContextMethodMixin
  input : torch.Tensor
      any shape
  dim : int
      dimension along which to apply sparsemax
  
  Returns
  -------
  output : torch.Tensor
      same shape as input
docstr_tok: ["sparsemax",":","normalizing","sparse","transform","(","a","la","softmax",")","Parameters","--","--","--","--","--","ctx",":","torch.autograd.function._ContextMethodMixin","input",":","torch.Tensor","any","shape","dim",":","int","dimension","along","which","to","apply","sparsemax","Returns","--","--","--","-","output",":","torch.Tensor","same","shape","as","input"]
code: def forward(ctx, input, dim=-1):
      """sparsemax: normalizing sparse transform (a la softmax)
  
      Parameters
      ----------
      ctx : torch.autograd.function._ContextMethodMixin
      input : torch.Tensor
          any shape
      dim : int
          dimension along which to apply sparsemax
  
      Returns
      -------
      output : torch.Tensor
          same shape as input
  
      """
      ctx.dim = dim
      max_val, _ = input.max(dim=dim, keepdim=True)
      input -= max_val  # same numerical stability trick as for softmax
      tau, supp_size = SparsemaxFunction._threshold_and_support(
          input, dim=dim
      )
      output = torch.clamp(input - tau, min=0)
      ctx.save_for_backward(supp_size, output)
      return output
  
imports: from torch import nn
  from torch.autograd import Function
  import torch.nn.functional
  import torch
label_desc: Use image node_id 1 for calling the SparsemaxFunction obj's underlying member method code with example usage: obj.forward(ctx, input, dim) and returns: output