code: def test_non_default_margin():
      cl_obj = contrastive.ContrastiveLoss(margin=2.0)
      y_true = tf.constant([0, 0, 1, 1, 0, 1], dtype=tf.dtypes.int64)
      y_pred = tf.constant(
          [0.1, 0.3, 1.3, 0.7, 1.1, 0.5], dtype=tf.dtypes.float32
      )
      loss = cl_obj(y_true, y_pred)
  
      # Loss = y * (y`)^2 + (1 - y) * (max(m - y`, 0))^2
      #      = [max(2 - 0.1, 0)^2, max(2 - 0.3, 0)^2,
      #         1.3^2, 0.7^2, max(2 - 1.1, 0)^2, 0.5^2]
      #      = [1.9^2, 1.7^2, 1.3^2, 0.7^2, 0.9^2, 0.5^2]
      #      = [3.61, 2.89, 1.69, 0.49, 0.81, 0.25]
      # Reduced loss = (3.61 + 2.89 + 1.69 + 0.49 + 0.81 + 0.25) / 6
      #              = 1.623333
  
      np.testing.assert_allclose(loss, 1.623333, atol=1e-6, rtol=1e-6)
  
file_path: addons/tensorflow_addons/losses/tests/contrastive_test.py
imports: import numpy
  import tensorflow
  from tensorflow_addons.losses import contrastive
label_desc: Use image node_id 5 for calling a global function with example usage: test_non_default_margin() without return types