code: def test_gen_adv_neighbor_respects_per_feature_constraints(
      self, gen_adv_neighbor_fn
  ):
      w1 = tf.constant(1.0, shape=(2, 2, 3))
      w2 = tf.constant(-1.0, shape=(2, 2))
      f1 = np.array(
          [
              [
                  [[0.0, 0.1, 0.2], [0.3, 0.4, 0.5]],
                  [[0.6, 0.7, 0.8], [0.9, 1.0, 1.1]],
              ]
          ],
          dtype=np.float32,
      )
      f2 = np.array([[[0.0, 0.33], [0.66, 1.0]]], dtype=np.float32)
      x = {"f1": tf.constant(f1), "f2": tf.constant(f2)}
  
      def loss_fn(x):
          return tf.reduce_sum(w1 * x["f1"]) + tf.reduce_sum(
              w2 * x["f2"]
          )
  
      adv_step_size = 0.5
      adv_config = configs.AdvNeighborConfig(
          adv_step_size=adv_step_size,
          adv_grad_norm="infinity",
          clip_value_min={"f2": 0.0},
          clip_value_max={"f1": 1.0},
      )
      adv_neighbor = gen_adv_neighbor_fn(x, loss_fn, adv_config)
      actual_neighbor = self.evaluate(adv_neighbor)
  
      # gradient = w, perturbation = adv_step_size * sign(w)
      expected_neighbor = {
          "f1": np.minimum(f1 + adv_step_size, 1.0),
          "f2": np.maximum(f2 - adv_step_size, 0.0),
      }
      self.assertAllClose(expected_neighbor, actual_neighbor)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl.testing import parameterized
  import neural_structured_learning.configs
  from neural_structured_learning.lib import adversarial_neighbor
  import numpy
  import tensorflow
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 50 for calling the GenAdvNeighborTest obj's underlying member method code with example usage: obj.test_gen_adv_neighbor_respects_per_feature_constraints(gen_adv_neighbor_fn) and returns: unknown