docstr: input (FloatTensor): ``(n, num_classes)``.
  target (LongTensor): ``(n,)``, the indices of the target classes
docstr_tok: ["input","(","FloatTensor",")",":","``","(","n",",","num_classes",")","``",".","target","(","LongTensor",")",":","``","(","n",",",")","``",",","the","indices","of","the","target","classes"]
code: def forward(ctx, input, target):
      """
      input (FloatTensor): ``(n, num_classes)``.
      target (LongTensor): ``(n,)``, the indices of the target classes
      """
      input_batch, classes = input.size()
  
      z_k = input.gather(1, target.unsqueeze(1)).squeeze()
      tau_z, support_size = _threshold_and_support(input, dim=1)
      support = input > tau_z
      x = torch.where(
          support,
          input**2 - tau_z**2,
          torch.tensor(0.0, device=input.device),
      ).sum(dim=1)
      ctx.save_for_backward(input, target, tau_z)
      # clamping necessary because of numerical errors: loss should be lower
      # bounded by zero, but negative values near zero are possible without
      # the clamp
      return torch.clamp(x / 2 - z_k + 0.5, min=0.0)
  
file_path: OpenNMT-py/onmt/modules/sparse_losses.py
imports: import torch
  import torch.nn
  from torch.autograd import Function
  from torch.cuda.amp import custom_fwd, custom_bwd
  from onmt.modules.sparse_activations import _threshold_and_support
label_desc: Use image node_id 1 for calling the SparsemaxLossFunction obj's underlying member method code with example usage: obj.forward(ctx, input, target) and returns: torch