code: def square_distance(
      X: tf.Tensor, X2: Optional[tf.Tensor]
  ) -> tf.Tensor:
      """
      Returns ||X - X2ᵀ||²
  
      Due to the implementation and floating-point imprecision, the
      result may actually be very slightly negative for entries very
      close to each other.
      """
      if X2 is None:
          Xs = tf.reduce_sum(tf.square(X), axis=-1, keepdims=True)
          dist = -2 * tf.matmul(X, X, transpose_b=True)
          dist += Xs + tf.linalg.adjoint(Xs)
          return dist
      Xs = tf.reduce_sum(tf.square(X), axis=-1)
      X2s = tf.reduce_sum(tf.square(X2), axis=-1)
      dist = -2 * tf.tensordot(X, X2, [[-1], [-1]])
      dist += broadcasting_elementwise(tf.add, Xs, X2s)
      return dist
  
file_path: GPflow/gpflow/utilities/ops.py
imports: import copy
  from typing import Any, Callable, List, Optional
  import tensorflow
  import tensorflow_probability
  from check_shapes import check_shapes
label_desc: Use image node_id 4 for calling a global function with example usage: square_distance(X, X2) and returns: dist, dist