code: def _test_function_x_y(x, y):
      """Builds a function that passes through the given points.
  
      Args:
        x: A tf.Tensor of shape [n].
        y: A tf.Tensor of shape [n] or [b, n] if batching is desired.
  
      Returns:
        A callable that takes a tf.Tensor `t` as input and returns as output the
        value and derivative of the interpolated function at `t`.
      """
      batches = y.shape[0] if len(y.shape) == 2 else None
      deg = len(x) - 1
      poly = np.polyfit(x, y.T, deg)
      poly = [tf.convert_to_tensor(c, dtype=tf.float32) for c in poly]
  
      def f(t):
          t = tf.convert_to_tensor(t, dtype=tf.float32)
          if batches is not None and not tuple(t.shape):
              # Broadcast a scalar through all batches.
              t = tf.tile(t[..., tf.newaxis], [batches])
          f, df = value_and_gradient(
              lambda t_: tf.math.polyval(poly, t_), t
          )
          return ValueAndGradient(
              x=t, f=tf.squeeze(f), df=tf.squeeze(df)
          )
  
      return f
  
imports: import collections
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math.gradient import value_and_gradient
  from tensorflow_probability.python.optimizer.linesearch.internal import hager_zhang_lib
label_desc: Use image node_id 2 for calling a global function with example usage: _test_function_x_y(x, y) and returns: f, ValueAndGradient