class_docstr: Tests for `pairwise_distance_lib.PairwiseDistance`.
class_docstr_tok: ["Tests","for","`","pairwise_distance_lib.PairwiseDistance","`","."]
docstr: Tests the overrides of Layer.__call__.
docstr_tok: ["Tests","the","overrides","of","Layer.__call__","."]
code: def testCallOverride(self):
      """Tests the overrides of Layer.__call__."""
  
      # Default distance configuration is mean squared error.
      def _distance_fn(x, y):
          return np.mean(np.square(x - y))
  
      # Common input.
      sources = np.array([[1.0, 1.0, 1.0, 1.0]])
      targets = np.array([[[4.0, 3.0, 2.0, 1.0]]])
      unweighted_distance = _distance_fn(sources, targets)
  
      def _make_symbolic_weights_model():
          """Makes a model where the weights are provided as input."""
          # Shape doesn't include batch dimension.
          inputs = {
              "sources": tf.keras.Input(4),
              "targets": tf.keras.Input((1, 4)),
              "weights": tf.keras.Input((1, 1)),
          }
          pairwise_distance_fn = (
              pairwise_distance_lib.PairwiseDistance()
          )
          outputs = pairwise_distance_fn(**inputs)
          return tf.keras.Model(inputs=inputs, outputs=outputs)
  
      weights = np.array([[[2.0]]])
      expected_distance = unweighted_distance * weights
      model = _make_symbolic_weights_model()
      self.assertNear(
          self.evaluate(
              model(
                  {
                      "sources": sources,
                      "targets": targets,
                      "weights": weights,
                  }
              )
          ),
          expected_distance,
          _ERR_TOL,
      )
  
      def _make_fixed_weights_model(weights):
          """Makes a model where the weights are a static constant."""
          # Shape doesn't include batch dimension.
          inputs = {
              "sources": tf.keras.Input(4),
              "targets": tf.keras.Input((1, 4)),
          }
          pairwise_distance_fn = (
              pairwise_distance_lib.PairwiseDistance()
          )
          outputs = pairwise_distance_fn(weights=weights, **inputs)
          return tf.keras.Model(inputs=inputs, outputs=outputs)
  
      model = _make_fixed_weights_model(0.25)
      expected_distance = 0.25 * unweighted_distance
      self.assertNear(
          self.evaluate(
              model(
                  {
                      "sources": sources,
                      "targets": targets,
                  }
              )
          ),
          expected_distance,
          _ERR_TOL,
      )
      # Considers invalid input.
      with self.assertRaisesRegex(ValueError, "No targets provided"):
          pairwise_distance_lib.PairwiseDistance()(np.ones(5))
  
file_path: neural-structured-learning/neural_structured_learning/keras/layers/pairwise_distance_test.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import neural_structured_learning.configs
  from neural_structured_learning.keras.layers import pairwise_distance
  import numpy
  from scipy import special
  import tensorflow
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 5 for calling the PairwiseDistanceTest obj's underlying member method code with example usage: obj.testCallOverride() and returns: np, tf, tf