class_docstr: Implementation of the HopSkipJump attack from Jianbo et al. (2019). This is a powerful black-box attack that
  only requires final class prediction, and is an advanced version of the boundary attack.
  
  | Paper link: https://arxiv.org/abs/1904.02144
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,).
  :param mask: An array with a mask broadcastable to input `x` defining where to apply adversarial perturbations.
               Shape needs to be broadcastable to the shape of x and can also be of the same shape as `x`. Any
               features for which the mask is zero will not be adversarially perturbed.
  :type mask: `np.ndarray`
  :param x_adv_init: Initial array to act as initial adversarial examples. Same shape as `x`.
  :type x_adv_init: `np.ndarray`
  :param resume: Allow users to continue their previous attack.
  :type resume: `bool`
  :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",",",")",".",":","param","mask",":","An","array","with","a","mask","broadcastable","to","input","`","x","`","defining","where","to","apply","adversarial","perturbations",".","Shape","needs","to","be","broadcastable","to","the","shape","of","x","and","can","also","be","of","the","same","shape","as","`","x","`",".","Any","features","for","which","the","mask","is","zero","will","not","be","adversarially","perturbed",".",":","type","mask",":","`","np.ndarray","`",":","param","x_adv_init",":","Initial","array","to","act","as","initial","adversarial","examples",".","Same","shape","as","`","x","`",".",":","type","x_adv_init",":","`","np.ndarray","`",":","param","resume",":","Allow","users","to","continue","their","previous","attack",".",":","type","resume",":","`","bool","`",":","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,).
      :param mask: An array with a mask broadcastable to input `x` defining where to apply adversarial perturbations.
                   Shape needs to be broadcastable to the shape of x and can also be of the same shape as `x`. Any
                   features for which the mask is zero will not be adversarially perturbed.
      :type mask: `np.ndarray`
      :param x_adv_init: Initial array to act as initial adversarial examples. Same shape as `x`.
      :type x_adv_init: `np.ndarray`
      :param resume: Allow users to continue their previous attack.
      :type resume: `bool`
      :return: An array holding the adversarial examples.
      """
      mask = kwargs.get("mask")
  
      if y is None:
          # Throw error if attack is targeted, but no targets are provided
          if self.targeted:  # pragma: no cover
              raise ValueError(
                  "Target labels `y` need to be provided for a targeted attack."
              )
  
          # Use model predictions as correct outputs
          y = get_labels_np_array(self.estimator.predict(x, batch_size=self.batch_size))  # type: ignore
  
      y = check_and_transform_label_format(
          y, nb_classes=self.estimator.nb_classes
      )
  
      if (
          self.estimator.nb_classes == 2 and y.shape[1] == 1
      ):  # pragma: no cover
          raise ValueError(
              "This attack has not yet been tested for binary classification with a single output classifier."
          )
  
      # Check whether users need a stateful attack
      resume = kwargs.get("resume")
  
      if resume is not None and resume:
          start = self.curr_iter
      else:
          start = 0
  
      # Check the mask
      if mask is not None:
          if len(mask.shape) == len(x.shape):
              mask = mask.astype(ART_NUMPY_DTYPE)
          else:
              mask = np.array(
                  [mask.astype(ART_NUMPY_DTYPE)] * x.shape[0]
              )
      else:
          mask = np.array([None] * x.shape[0])
  
      # Get clip_min and clip_max from the classifier or infer them from data
      if self.estimator.clip_values is not None:
          clip_min, clip_max = self.estimator.clip_values
      else:
          clip_min, clip_max = np.min(x), np.max(x)
  
      # Prediction from the original images
      preds = np.argmax(
          self.estimator.predict(x, batch_size=self.batch_size), axis=1
      )
  
      # Prediction from the initial adversarial examples if not None
      x_adv_init = kwargs.get("x_adv_init")
  
      if x_adv_init is not None:
          # Add mask param to the x_adv_init
          for i in range(x.shape[0]):
              if mask[i] is not None:
                  x_adv_init[i] = x_adv_init[i] * mask[i] + x[i] * (
                      1 - mask[i]
                  )
  
          # Do prediction on the init
          init_preds = np.argmax(
              self.estimator.predict(
                  x_adv_init, batch_size=self.batch_size
              ),
              axis=1,
          )
  
      else:
          init_preds = [None] * len(x)
          x_adv_init = [None] * len(x)
  
      # Assert that, if attack is targeted, y is provided
      if self.targeted and y is None:  # pragma: no cover
          raise ValueError(
              "Target labels `y` need to be provided for a targeted attack."
          )
  
      # Some initial setups
      x_adv = x.astype(ART_NUMPY_DTYPE)
  
      y = np.argmax(y, axis=1)
  
      # Generate the adversarial samples
      for ind, val in enumerate(
          tqdm(x_adv, desc="HopSkipJump", disable=not self.verbose)
      ):
          self.curr_iter = start
  
          if self.targeted:
              x_adv[ind] = self._perturb(
                  x=val,
                  y=y[ind],  # type: ignore
                  y_p=preds[ind],
                  init_pred=init_preds[ind],
                  adv_init=x_adv_init[ind],
                  mask=mask[ind],
                  clip_min=clip_min,
                  clip_max=clip_max,
              )
  
          else:
              x_adv[ind] = self._perturb(
                  x=val,
                  y=-1,
                  y_p=preds[ind],
                  init_pred=init_preds[ind],
                  adv_init=x_adv_init[ind],
                  mask=mask[ind],
                  clip_min=clip_min,
                  clip_max=clip_max,
              )
  
      y = to_categorical(y, self.estimator.nb_classes)  # type: ignore
  
      logger.info(
          "Success rate of HopSkipJump attack: %.2f%%",
          100
          * compute_success(
              self.estimator,
              x,
              y,
              x_adv,
              self.targeted,
              batch_size=self.batch_size,
          ),
      )
  
      return x_adv
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import Optional, Tuple, Union, TYPE_CHECKING
  import numpy
  from tqdm.auto import tqdm
  from art.config import ART_NUMPY_DTYPE
  from art.attacks.attack import EvasionAttack
  from art.estimators.estimator import BaseEstimator
  from art.estimators.classification import ClassifierMixin
  from art.utils import compute_success, to_categorical, check_and_transform_label_format, get_labels_np_array
label_desc: Use image node_id 2 for calling the HopSkipJump obj's underlying member method code with example usage: obj.generate(x, y) and returns: x_adv