code: def loss_fn(
      x,
      x_new,
      y_true,
      y_pred,
      confidence,
      const=0,
      targeted=False,
      clip_min=0,
      clip_max=1,
  ):
      other = clip_tanh(x, clip_min=clip_min, clip_max=clip_max)
      l2_dist = l2(x_new, other)
  
      real = tf.reduce_sum(y_true * y_pred, 1)
      other = tf.reduce_max(
          (1.0 - y_true) * y_pred - y_true * 10_000, 1
      )
  
      if targeted:
          # if targeted, optimize for making the other class most likely
          loss_1 = tf.maximum(0.0, other - real + confidence)
      else:
          # if untargeted, optimize for making this class least likely.
          loss_1 = tf.maximum(0.0, real - other + confidence)
  
      # sum up losses
      loss_2 = tf.reduce_sum(l2_dist)
      loss_1 = tf.reduce_sum(const * loss_1)
      loss = loss_1 + loss_2
      return loss, l2_dist
  
file_path: cleverhans/cleverhans/tf2/attacks/carlini_wagner_l2.py
imports: import numpy
  import tensorflow
  from cleverhans.tf2.utils import get_or_guess_labels, set_with_mask
label_desc: Use image node_id 3 for calling a global function with example usage: loss_fn(x, x_new, y_true, y_pred, confidence, const, targeted, clip_min, clip_max) and returns: loss,  l2_dist