code: def test_gradient_with_additional_parameters(
      self, params, bijector_fn, forward_fn, domain_constraint_fn, y
  ):
      y = tf.convert_to_tensor(y)
      params = [tf.convert_to_tensor(x) for x in params]
  
      # Define a drop-in replacement for 'bijector_fn'.
      implicit_bijector_fn = lambda *params: sfwii.ScalarFunctionWithInferredInverse(  # pylint: disable=g-long-lambda
          forward_fn,
          domain_constraint_fn=domain_constraint_fn,
          additional_scalar_parameters_requiring_gradients=params,
      )
  
      # Check the inverse and its first-order derivatives.
      x, [dx_dy, dx_dparams] = gradient.value_and_gradient(
          lambda y, params: bijector_fn(*params).inverse(y), y, params
      )
      implicit_x, [
          implicit_dx_dy,
          implicit_dx_dparams,
      ] = gradient.value_and_gradient(
          lambda y, params: implicit_bijector_fn(*params).inverse(y),
          y,
          params,
      )
      self.assertAllClose(x, implicit_x)
      self.assertAllClose(dx_dy, implicit_dx_dy)
      self.assertAllCloseNested(dx_dparams, implicit_dx_dparams)
  
      # Check second-order derivatives, by way of ildj and its gradient.
      y = tf.identity(y)  # Bypass the global bijector cache.
      ildj, [dildj_dy, dildj_dparams] = gradient.value_and_gradient(
          lambda y, params: bijector_fn(
              *params
          ).inverse_log_det_jacobian(y),
          y,
          params,
      )
      implicit_ildj, [
          implicit_dildj_dy,
          implicit_dildj_dparams,
      ] = gradient.value_and_gradient(
          lambda y, params: implicit_bijector_fn(  # pylint: disable=g-long-lambda
              *params
          ).inverse_log_det_jacobian(
              y
          ),
          y,
          params,
      )
      self.assertAllClose(ildj, implicit_ildj)
      self.assertAllClose(
          0.0 if dildj_dy is None else dildj_dy, implicit_dildj_dy
      )
      self.assertAllCloseNested(
          [0 if g is None else g for g in dildj_dparams],
          implicit_dildj_dparams,
      )
  
      # Directly test second-order derivatives wrt params, since ildj doesn't use
      # them.
      y = tf.identity(y)  # Bypass the global bijector cache.
      _, second_derivatives_wrt_params = gradient.value_and_gradient(
          lambda params: gradient.value_and_gradient(  # pylint: disable=g-long-lambda
              lambda params: bijector_fn(*params).inverse(y),
              params,
              auto_unpack_single_arg=False,
          )[
              1
          ],
          params,
          auto_unpack_single_arg=False,
      )
      (
          _,
          implicit_second_derivatives_wrt_params,
      ) = gradient.value_and_gradient(
          lambda params: gradient.value_and_gradient(  # pylint: disable=g-long-lambda
              lambda params: implicit_bijector_fn(*params).inverse(y),
              params,
              auto_unpack_single_arg=False,
          )[
              1
          ],
          params,
          auto_unpack_single_arg=False,
      )
      self.assertAllCloseNested(
          [
              0.0 if g is None else g
              for g in second_derivatives_wrt_params
          ],
          implicit_second_derivatives_wrt_params,
      )
  
imports: from absl.testing import parameterized
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import chain
  from tensorflow_probability.python.bijectors import power
  from tensorflow_probability.python.bijectors import scale
  from tensorflow_probability.python.bijectors import shift
  from tensorflow_probability.python.distributions import beta
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.distributions import student_t
  from tensorflow_probability.python.distributions import uniform
  from tensorflow_probability.python.experimental.bijectors import scalar_function_with_inferred_inverse
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math import gradient
label_desc: Use image node_id 6 for calling the ScalarFunctionWithInferredInverseTests obj's underlying member method code with example usage: obj.test_gradient_with_additional_parameters(params, bijector_fn, forward_fn, domain_constraint_fn, y) without return types