code: def test_fast_minimum_norm_targeted_attack(
      fmodel_and_data_ext_for_attacks: ModeAndDataAndDescription,
      attack_and_p: Tuple[FMNAttackLp, Union[int, float]],
  ) -> None:
      (
          (fmodel, x, y),
          real,
          low_dimensional_input,
      ) = fmodel_and_data_ext_for_attacks
  
      if isinstance(x, ep.NumPyTensor):
          pytest.skip()
  
      x = (x - fmodel.bounds.lower) / (
          fmodel.bounds.upper - fmodel.bounds.lower
      )
      fmodel = fmodel.transform_bounds((0, 1))
  
      unique_preds = np.unique(fmodel(x).argmax(-1).numpy())
      target_classes = ep.from_numpy(
          y,
          np.array(
              [
                  unique_preds[
                      (np.argmax(y_it == unique_preds) + 1)
                      % len(unique_preds)
                  ]
                  for y_it in y.numpy()
              ]
          ),
      )
      criterion = fbn.TargetedMisclassification(target_classes)
      adv_before_attack = criterion(x, fmodel(x))
      assert not adv_before_attack.all()
  
      init_attack = fa.DatasetAttack()
      init_attack.feed(fmodel, x)
      init_advs = init_attack.run(fmodel, x, criterion)
  
      attack, p = attack_and_p
      advs = attack.run(fmodel, x, criterion, starting_points=init_advs)
  
      init_norms = ep.norms.lp(flatten(init_advs - x), p=p, axis=-1)
      norms = ep.norms.lp(flatten(advs - x), p=p, axis=-1)
  
      is_smaller = norms < init_norms
  
      assert fbn.accuracy(fmodel, advs, target_classes) == 1.0
      assert is_smaller.any()
  
file_path: foolbox/tests/test_fast_minimum_norm_attack.py
imports: from typing import Tuple, Union, List
  import eagerpy
  import foolbox
  import foolbox.attacks
  from foolbox.devutils import flatten
  from foolbox.attacks.fast_minimum_norm import FMNAttackLp
  import pytest
  import numpy
  from conftest import ModeAndDataAndDescription
label_desc: Use image node_id 3 for calling a global function with example usage: test_fast_minimum_norm_targeted_attack(fmodel_and_data_ext_for_attacks, attack_and_p) without return types