code: def pairwise_distance(feature: TensorLike, squared: bool = False):
      """Computes the pairwise distance matrix with numerical stability.
  
      output[i, j] = || feature[i, :] - feature[j, :] ||_2
  
      Args:
        feature: 2-D Tensor of size `[number of data, feature dimension]`.
        squared: Boolean, whether or not to square the pairwise distances.
  
      Returns:
        pairwise_distances: 2-D Tensor of size `[number of data, number of data]`.
      """
      pairwise_distances_squared = tf.math.add(
          tf.math.reduce_sum(
              tf.math.square(feature), axis=[1], keepdims=True
          ),
          tf.math.reduce_sum(
              tf.math.square(tf.transpose(feature)),
              axis=[0],
              keepdims=True,
          ),
      ) - 2.0 * tf.matmul(feature, tf.transpose(feature))
  
      # Deal with numerical inaccuracies. Set small negatives to zero.
      pairwise_distances_squared = tf.math.maximum(
          pairwise_distances_squared, 0.0
      )
      # Get the mask where the zero distances are at.
      error_mask = tf.math.less_equal(pairwise_distances_squared, 0.0)
  
      # Optionally take the sqrt.
      if squared:
          pairwise_distances = pairwise_distances_squared
      else:
          pairwise_distances = tf.math.sqrt(
              pairwise_distances_squared
              + tf.cast(error_mask, dtype=tf.dtypes.float32) * 1e-16
          )
  
      # Undo conditionally adding 1e-16.
      pairwise_distances = tf.math.multiply(
          pairwise_distances,
          tf.cast(
              tf.math.logical_not(error_mask), dtype=tf.dtypes.float32
          ),
      )
  
      num_data = tf.shape(feature)[0]
      # Explicitly set diagonals to zero.
      mask_offdiagonals = tf.ones_like(
          pairwise_distances
      ) - tf.linalg.diag(tf.ones([num_data]))
      pairwise_distances = tf.math.multiply(
          pairwise_distances, mask_offdiagonals
      )
      return pairwise_distances
  
imports: import tensorflow
  from tensorflow_addons.utils.types import TensorLike
label_desc: Use image node_id 1 for calling a global function with example usage: pairwise_distance(feature, squared) and returns: pairwise_distances