class_docstr: Tests for methods in root_finder_newton module.
class_docstr_tok: ["Tests","for","methods","in","root_finder_newton","module","."]
docstr: Tests that the newton root finder works on a square root example.
docstr_tok: ["Tests","that","the","newton","root","finder","works","on","a","square","root","example","."]
code: def test_newton_root(self):
      """Tests that the newton root finder works on a square root example."""
  
      # Set up the problem of finding the square roots of three numbers.
      constants = np.array([4.0, 9.0, 16.0])
      initial_values = np.ones(len(constants))
  
      def objective_and_gradient(values):
          objective = values**2 - constants
          gradient = 2.0 * values
          return objective, gradient
  
      # Obtain and evaluate a tensor containing the roots.
      root_values, converged, failed = self.evaluate(
          newton_root(objective_and_gradient, initial_values)
      )
  
      # Reference values.
      roots_bench = np.array([2.0, 3.0, 4.0])
      converged_bench = np.array([True, True, True])
      failed_bench = np.array([False, False, False])
  
      # Assert that the values we obtained are close to the true values.
      np.testing.assert_array_equal(converged, converged_bench)
      np.testing.assert_array_equal(failed, failed_bench)
      np.testing.assert_almost_equal(
          root_values, roots_bench, decimal=7
      )
  
file_path: tf-quant-finance/tf_quant_finance/math/root_search/newton_test.py
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  import tf_quant_finance
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 1 for calling the RootFinderNewtonTest obj's underlying member method code with example usage: obj.test_newton_root() and returns: objective,  gradient