docstr: Tests that undistortion_factor produces the expected outputs.
docstr_tok: ["Tests","that","undistortion_factor","produces","the","expected","outputs","."]
code: def test_undistortion_factor_random_negative_distortion_coefficient(
      self, num_iterations, tolerance
  ):
      """Tests that undistortion_factor produces the expected outputs."""
      distorted_squared_radii = _get_random_radii() * 2.0
      distortion_coefficient = _get_random_coefficient() * -0.2
  
      (
          undistortion,
          mask,
      ) = quadratic_radial_distortion.undistortion_factor(
          distorted_squared_radii,
          distortion_coefficient,
          num_iterations,
      )
      distortion_coefficient = _make_shape_compatible(
          distortion_coefficient
      )
      undistorted_squared_radii = (
          tf.square(undistortion) * distorted_squared_radii
      )
      # See explanation in the implementation comments for this formula.
      expected_overflow_mask = (
          distorted_squared_radii * distortion_coefficient + 4.0 / 27.0
          < 0
      )
      redistorted_squared_radii = (
          tf.square(
              1.0 + distortion_coefficient * undistorted_squared_radii
          )
          * undistorted_squared_radii
      )
      valid_mask = np.logical_not(expected_overflow_mask)
      redistorted_squared_radii_when_valid = self.evaluate(
          redistorted_squared_radii
      )[valid_mask]
      distorted_squared_radii_when_valid = distorted_squared_radii[
          valid_mask
      ]
  
      with self.subTest(name="distortion"):
          self.assertAllClose(
              distorted_squared_radii_when_valid,
              redistorted_squared_radii_when_valid,
              rtol=tolerance,
              atol=tolerance,
          )
  
      # We assert correctness of the mask, and of all the pixels that are not in
      # overflow, distorting again the undistorted radii and comparing to the
      # original distorted_squared_radii.
      with self.subTest(name="mask"):
          self.assertAllEqual(expected_overflow_mask, mask)
  
imports: from absl.testing import parameterized
  import numpy
  import tensorflow
  from tensorflow_graphics.rendering.camera import quadratic_radial_distortion
  from tensorflow_graphics.util import test_case
label_desc: Use image node_id 7 for calling the QuadraticRadialDistortionTest obj's underlying member method code with example usage: obj.test_undistortion_factor_random_negative_distortion_coefficient(num_iterations, tolerance) without return types