docstr: Clips the perturbations to epsilon and returns the new perturbed
  
  Args:
      references: A batch of reference inputs.
      perturbed: A batch of perturbed inputs.
  
  Returns:
      A tenosr like perturbed but with the perturbation clipped to epsilon.
docstr_tok: ["Clips","the","perturbations","to","epsilon","and","returns","the","new","perturbed","Args",":","references",":","A","batch","of","reference","inputs",".","perturbed",":","A","batch","of","perturbed","inputs",".","Returns",":","A","tenosr","like","perturbed","but","with","the","perturbation","clipped","to","epsilon","."]
code: def clip_perturbation(
      self, references: T, perturbed: T, epsilon: float
  ) -> T:
      """Clips the perturbations to epsilon and returns the new perturbed
  
      Args:
          references: A batch of reference inputs.
          perturbed: A batch of perturbed inputs.
  
      Returns:
          A tenosr like perturbed but with the perturbation clipped to epsilon.
      """
      (x, y), restore_type = ep.astensors_(references, perturbed)
      p = y - x
      if self.p == ep.inf:
          clipped_perturbation = ep.clip(p, -epsilon, epsilon)
          return restore_type(x + clipped_perturbation)
      norms = ep.norms.lp(flatten(p), self.p, axis=-1)
      norms = ep.maximum(norms, 1e-12)  # avoid divsion by zero
      factor = epsilon / norms
      factor = ep.minimum(
          1, factor
      )  # clipping -> decreasing but not increasing
      if self.p == 0:
          if (factor == 1).all():
              return perturbed
          raise NotImplementedError(
              "reducing L0 norms not yet supported"
          )
      factor = atleast_kd(factor, x.ndim)
      clipped_perturbation = factor * p
      return restore_type(x + clipped_perturbation)
  
file_path: foolbox/foolbox/distances.py
imports: from abc import ABC, abstractmethod
  from typing import TypeVar
  import eagerpy
  from .devutils import flatten
  from .devutils import atleast_kd
label_desc: Use image node_id 5 for calling the LpDistance obj's underlying member method code with example usage: obj.clip_perturbation(references, perturbed, epsilon) and returns: restore_type, restore_type, perturbed