docstr: Tests that gradient calculation in 1 dimension.
docstr_tok: ["Tests","that","gradient","calculation","in","1","dimension","."]
code: def test_gradient_1d(self, use_analytic_pricing):
      """Tests that gradient calculation in 1 dimension."""
      # 1 year cap with quarterly resets.
      dtype = tf.float64
      mean_reversion_1d = tf.convert_to_tensor(
          self.mean_reversion_1d, dtype=dtype
      )
      volatility_1d = tf.convert_to_tensor(
          self.volatility_1d, dtype=dtype
      )
      # strikes of shape [1, 4] so that prices are of shape [1]
      strikes = self.strikes[None]
      with tf.GradientTape(persistent=True) as tape:
          tape.watch([mean_reversion_1d, volatility_1d])
          price = tff.models.hull_white.cap_floor_price(
              strikes=strikes,
              expiries=self.expiries,
              maturities=self.maturities,
              daycount_fractions=self.daycount_fractions,
              notional=100.0,
              mean_reversion=mean_reversion_1d,
              volatility=volatility_1d,
              reference_rate_fn=self.discount_rate_1d_fn,
              use_analytic_pricing=use_analytic_pricing,
              num_samples=10_000,
              time_step=0.1,
              random_type=tff.math.random.RandomType.STATELESS_ANTITHETIC,
              seed=[42, 42],
              dtype=dtype,
          )
          grad_mr = tape.gradient(price, mean_reversion_1d)
          grad_vol = tape.gradient(price, volatility_1d)
      self.assertEqual(price.dtype, dtype)
      self.assertAllEqual(price.shape, [1])
      price = self.evaluate(price)
      with self.subTest("GradMeanReversion"):
          self.assertAllClose(grad_mr, -0.16, rtol=1e-2, atol=1e-2)
      with self.subTest("GradVolatility"):
          self.assertAllClose(grad_vol, 20.32, rtol=1e-2, atol=1e-2)
  
file_path: tf-quant-finance/tf_quant_finance/models/hull_white/cap_floor_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 3 for calling the HullWhiteCapFloorTest obj's underlying member method code with example usage: obj.test_gradient_1d(use_analytic_pricing) without return types