docstr: sparsemax: normalizing sparse transform (a la softmax) via bisection
  
  Solves the projection:
  
      min_p ||x - p||_2   s.t.    p >= 0, sum(p) == 1.
  
  Parameters
  ----------
  dim : int
      The dimension along which to apply sparsemax.
  
  n_iter : int
      Number of bisection iterations. For float32, 24 iterations should
      suffice for machine precision.
docstr_tok: ["sparsemax",":","normalizing","sparse","transform","(","a","la","softmax",")","via","bisection","Solves","the","projection",":","min_p","||x","-","p||_2","s.t",".","p",">","=","0",",","sum","(","p",")","==","1",".","Parameters","--","--","--","--","--","dim",":","int","The","dimension","along","which","to","apply","sparsemax",".","n_iter",":","int","Number","of","bisection","iterations",".","For","float32",",","24","iterations","should","suffice","for","machine","precision","."]
code: def __init__(self, dim=-1, n_iter=None):
      """sparsemax: normalizing sparse transform (a la softmax) via bisection
  
      Solves the projection:
  
          min_p ||x - p||_2   s.t.    p >= 0, sum(p) == 1.
  
      Parameters
      ----------
      dim : int
          The dimension along which to apply sparsemax.
  
      n_iter : int
          Number of bisection iterations. For float32, 24 iterations should
          suffice for machine precision.
      """
      self.dim = dim
      self.n_iter = n_iter
      super().__init__()
  
imports: import torch
  import torch.nn
  from torch.autograd import Function
label_desc: Use image node_id 1 to create a new SparsemaxBisect object from inherited base classes: nn with example: obj = SparsemaxBisect(dim, n_iter)