class_docstr: This is a modified version of the L_2 optimized attack of Carlini and Wagner (2016). It controls the L_Inf
  norm, i.e. the maximum perturbation applied to each pixel.
docstr: Generate adversarial samples and return them in an array.
  
  :param x: An array with the original inputs to be attacked.
  :param y: Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes) or indices of shape
            (nb_samples,). If `self.targeted` is true, then `y_val` represents the target labels. Otherwise, the
            targets are the original class labels.
  :return: An array holding the adversarial examples.
docstr_tok: ["Generate","adversarial","samples","and","return","them","in","an","array",".",":","param","x",":","An","array","with","the","original","inputs","to","be","attacked",".",":","param","y",":","Target","values","(","class","labels",")","one-hot-encoded","of","shape","(","nb_samples",",","nb_classes",")","or","indices","of","shape","(","nb_samples",",",")",".","If","`","self.targeted","`","is","true",",","then","`","y_val","`","represents","the","target","labels",".","Otherwise",",","the","targets","are","the","original","class","labels",".",":","return",":","An","array","holding","the","adversarial","examples","."]
code: def generate(
      self, x: np.ndarray, y: Optional[np.ndarray] = None, **kwargs
  ) -> np.ndarray:
      """
      Generate adversarial samples and return them in an array.
  
      :param x: An array with the original inputs to be attacked.
      :param y: Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes) or indices of shape
                (nb_samples,). If `self.targeted` is true, then `y_val` represents the target labels. Otherwise, the
                targets are the original class labels.
      :return: An array holding the adversarial examples.
      """
      if y is not None:
          y = check_and_transform_label_format(
              y, nb_classes=self.estimator.nb_classes
          )
      x_adv = x.astype(ART_NUMPY_DTYPE)
  
      if self.estimator.clip_values is not None:
          clip_min, clip_max = self.estimator.clip_values
      else:
          clip_min, clip_max = np.amin(x), np.amax(x)
  
      # Assert that, if attack is targeted, y_val is provided:
      if self.targeted and y is None:
          raise ValueError(
              "Target labels `y` need to be provided for a targeted attack."
          )
  
      # No labels provided, use model prediction as correct class
      if y is None:
          y = get_labels_np_array(
              self.estimator.predict(x, batch_size=self.batch_size)
          )
  
      if self.estimator.nb_classes == 2 and y.shape[1] == 1:
          raise ValueError(  # pragma: no cover
              "This attack has not yet been tested for binary classification with a single output classifier."
          )
  
      # Compute perturbation with implicit batching
      for sample_id in trange(
          x.shape[0], desc="C&W L_inf", disable=not self.verbose
      ):
          sample_done = False
          tau = 1.0
          delta_i_best = 1.0
          while tau > 1.0 / 256.0 and not sample_done:
              sample_done = True
  
              const = self.initial_const
              while const < self.largest_const:
                  x_batch = x[[sample_id]]
                  y_batch = y[[sample_id]]
  
                  x_adv_batch = self._generate_single(
                      x_batch,
                      y_batch,
                      clip_min,
                      clip_max,
                      const=const,
                      tau=tau,
                  )
  
                  # Update depending on attack success:
                  _, loss, loss_1, loss_2 = self._loss(
                      x_adv_batch, y_batch, x_batch, const, tau
                  )
  
                  delta_i = np.max(np.abs(x_adv_batch - x[sample_id]))
  
                  logger.debug(
                      "tau: %4.3f, const: %4.5f, loss: %4.3f, loss_1: %4.3f, loss_2: %4.3f, delta_i: %4.3f",
                      tau,
                      const,
                      loss,
                      loss_1,
                      loss_2,
                      delta_i,
                  )
  
                  if (
                      np.argmax(
                          self.estimator.predict(x_adv_batch), axis=1
                      )
                      != np.argmax(y_batch, axis=1)
                      and delta_i < delta_i_best
                  ):
                      x_adv[sample_id] = x_adv_batch
                      delta_i_best = delta_i
                      sample_done = False
  
                  const *= self.const_factor
  
              tau_actual = np.max(
                  np.abs(x_adv[sample_id] - x[sample_id])
              )
  
              if tau_actual < tau:
                  tau = tau_actual
  
              tau *= self.decrease_factor
  
      return x_adv
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import Optional, Tuple, TYPE_CHECKING
  import numpy
  from tqdm.auto import trange
  from art.config import ART_NUMPY_DTYPE
  from art.optimizers import Adam
  from art.estimators.estimator import BaseEstimator
  from art.estimators.classification.classifier import ClassGradientsMixin
  from art.attacks.attack import EvasionAttack
  from art.utils import compute_success, get_labels_np_array, tanh_to_original, original_to_tanh
  from art.utils import check_and_transform_label_format
label_desc: Use image node_id 5 for calling the CarliniLInfMethod obj's underlying member method code with example usage: obj.generate(x, y) and returns: x_adv