docstr: Tests that bracketing works in batching mode.
docstr_tok: ["Tests","that","bracketing","works","in","batching","mode","."]
code: def test_bracket_batching(self):
      """Tests that bracketing works in batching mode."""
      wolfe_threshold = 1e-6
      # We build an example function with 4 batches, each for one of the
      # following cases:
      # - a) Minimum bracketed from the beginning.
      # - b) Minimum bracketed after one expansion.
      # - c) Needs bisect from the beginning.
      # - d) Needs one round of expansion and then bisect.
      x = np.array([0.0, 1.0, 2.5, 5.0])
      y = np.array(
          [
              [1.0, 1.2, 1.4, 1.1],
              [1.0, 0.9, -2.5, 1.2],
              [1.0, 1.1, -3.0, 1.2],
              [1.0, 0.9, -2.0, 1.1],
          ]
      )
      dy = np.array(
          [
              [-0.8, 0.6, -0.5, -0.8],
              [-0.8, -0.7, -0.5, 0.6],
              [-0.8, -0.7, -0.3, -0.8],
              [-0.8, -0.7, 1.6, -0.8],
          ]
      )
      fun = _test_function_x_y_dy(x, y, dy)
  
      val_a = fun(0.0)
      val_b = fun(1.0)
      f_lim = val_a.f + (wolfe_threshold * tf.abs(val_a.f))
  
      expected_left = np.array([0.0, 1.0, 0.0, 0.0])
      expected_right = np.array([1.0, 5.0, 0.5, 2.5])
  
      result = self.evaluate(
          hzl.bracket(
              fun, _interval(val_a, val_b), f_lim, max_iterations=5
          )
      )
      self.assertEqual(
          result.num_evals, 2
      )  # Once bracketing, once bisecting.
      self.assertTrue(np.all(result.stopped))
      self.assertTrue(np.all(~result.failed))
      self.assertTrue(np.all(result.left.df < 0))  # Opposite slopes.
      self.assertTrue(np.all(result.right.df >= 0))
      self.assertArrayNear(result.left.x, expected_left, 1e-5)
      self.assertArrayNear(result.right.x, expected_right, 1e-5)
  
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 7 for calling the HagerZhangLibTest obj's underlying member method code with example usage: obj.test_bracket_batching() without return types