class_docstr: Sparse L1 Descent Attack [#Tra19]_.
  
  Args:
      rel_stepsize: Stepsize relative to epsilon.
      abs_stepsize: If given, it takes precedence over rel_stepsize.
      steps : Number of update steps.
      random_start : Controls whether to randomly start within allowed epsilon ball.
  
  References:
      .. [#Tra19] Florian Tramèr, Dan Boneh, "Adversarial Training and
      Robustness for Multiple Perturbations"
      https://arxiv.org/abs/1904.13000
class_docstr_tok: ["Sparse","L1","Descent","Attack","[","#","Tra19","]","_.","Args",":","rel_stepsize",":","Stepsize","relative","to","epsilon",".","abs_stepsize",":","If","given",",","it","takes","precedence","over","rel_stepsize",".","steps",":","Number","of","update","steps",".","random_start",":","Controls","whether","to","randomly","start","within","allowed","epsilon","ball",".","References",":","..","[","#","Tra19","]","Florian","Tram\u00e8r",",","Dan","Boneh",",","``","Adversarial","Training","and","Robustness","for","Multiple","Perturbations","''","https",":","\/\/arxiv.org\/abs\/1904.13000"]
code: def normalize(
      self, gradients: ep.Tensor, *, x: ep.Tensor, bounds: Bounds
  ) -> ep.Tensor:
      bad_pos = ep.logical_or(
          ep.logical_and(x == bounds.lower, gradients < 0),
          ep.logical_and(x == bounds.upper, gradients > 0),
      )
      gradients = ep.where(bad_pos, ep.zeros_like(gradients), gradients)
  
      abs_gradients = gradients.abs()
      quantiles = np.quantile(
          flatten(abs_gradients).numpy(), q=self.quantile, axis=-1
      )
      keep = abs_gradients >= atleast_kd(
          ep.from_numpy(gradients, quantiles), gradients.ndim
      )
      e = ep.where(keep, gradients.sign(), ep.zeros_like(gradients))
      return normalize_lp_norms(e, p=1)
  
file_path: foolbox/foolbox/attacks/sparse_l1_descent_attack.py
imports: from typing import Optional
  import eagerpy
  import numpy
  from ..devutils import flatten
  from ..devutils import atleast_kd
  from ..types import Bounds
  from .gradient_descent_base import L1BaseGradientDescent
  from .gradient_descent_base import normalize_lp_norms
label_desc: Use image node_id 1 for calling the SparseL1DescentAttack obj's underlying member method code with example usage: obj.normalize(gradients) and returns: normalize_lp_norms