class_docstr: This class implements the black-box attack `SimBA`.
  
  | Paper link: https://arxiv.org/abs/1905.07121
class_docstr_tok: ["This","class","implements","the","black-box","attack","`","SimBA","`",".","|","Paper","link",":","https",":","\/\/arxiv.org\/abs\/1905.07121"]
docstr: Defines a block order, starting with top-left (initial_size x initial_size) submatrix
  expanding by stride rows and columns whenever exhausted
  randomized within the block and across channels.
  e.g. (initial_size=2, stride=1)
  [1, 3, 6]
  [2, 4, 9]
  [5, 7, 8]
  
  :param img_size: image size (i.e., width or height).
  :param channels: the number of channels.
  :param initial size: initial size for submatrix.
  :param stride: stride size for expansion.
  
  :return order: An array holding the block order of DCT attacks.
docstr_tok: ["Defines","a","block","order",",","starting","with","top-left","(","initial_size","x","initial_size",")","submatrix","expanding","by","stride","rows","and","columns","whenever","exhausted","randomized","within","the","block","and","across","channels",".","e.g",".","(","initial_size=2",",","stride=1",")","[","1",",","3",",","6","]","[","2",",","4",",","9","]","[","5",",","7",",","8","]",":","param","img_size",":","image","size","(","i.e.",",","width","or","height",")",".",":","param","channels",":","the","number","of","channels",".",":","param","initial","size",":","initial","size","for","submatrix",".",":","param","stride",":","stride","size","for","expansion",".",":","return","order",":","An","array","holding","the","block","order","of","DCT","attacks","."]
code: def _block_order(self, img_size, channels, initial_size=2, stride=1):
      """
      Defines a block order, starting with top-left (initial_size x initial_size) submatrix
      expanding by stride rows and columns whenever exhausted
      randomized within the block and across channels.
      e.g. (initial_size=2, stride=1)
      [1, 3, 6]
      [2, 4, 9]
      [5, 7, 8]
  
      :param img_size: image size (i.e., width or height).
      :param channels: the number of channels.
      :param initial size: initial size for submatrix.
      :param stride: stride size for expansion.
  
      :return order: An array holding the block order of DCT attacks.
      """
      order = np.zeros((channels, img_size, img_size)).astype(
          ART_NUMPY_DTYPE
      )
      total_elems = channels * initial_size * initial_size
      perm = np.random.permutation(total_elems)
      order[:, :initial_size, :initial_size] = perm.reshape(
          (channels, initial_size, initial_size)
      )
      for i in range(initial_size, img_size, stride):
          num_elems = channels * (2 * stride * i + stride * stride)
          perm = np.random.permutation(num_elems) + total_elems
          num_first = channels * stride * (stride + i)
          order[:, : (i + stride), i : (i + stride)] = perm[
              :num_first
          ].reshape((channels, -1, stride))
          order[:, i : (i + stride), :i] = perm[num_first:].reshape(
              (channels, stride, -1)
          )
          total_elems += num_elems
  
      if self.estimator.channels_first:
          return order.reshape(1, -1).squeeze().argsort()
  
      return (
          order.transpose((1, 2, 0)).reshape(1, -1).squeeze().argsort()
      )
  
file_path: adversarial-robustness-toolbox/art/attacks/evasion/simba.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import Optional, TYPE_CHECKING
  import numpy
  from scipy.fftpack import idct
  from tqdm.auto import trange
  from art.attacks.attack import EvasionAttack
  from art.estimators.estimator import BaseEstimator, NeuralNetworkMixin
  from art.estimators.classification.classifier import ClassifierMixin
  from art.config import ART_NUMPY_DTYPE
  from art.utils import is_probability
label_desc: Use image node_id 4 for calling the SimBA obj's underlying member method code with example usage: obj._block_order(img_size, channels, initial_size, stride) and returns: order, order