class_docstr: Tests for methods in linear_interpolation module.
docstr: Tests none of the gradients is nan.
docstr_tok: ["Tests","none","of","the","gradients","is","nan","."]
code: def test_valid_gradients(self, optimize_for_tpu):
      """Tests none of the gradients is nan."""
  
      # In this example, `x[0]` and `x[1]` are both less than or equal to
      # `x_data[0]`. `x[-2]` and `x[-1]` are both greater than or equal to
      # `x_data[-1]`. They are set up this way to test none of the tf.where
      # branches of the implementation have any nan. An unselected nan could still
      # propagate through gradient calculation with the end result being nan.
      x = [
          [-10.0, -1.0, 1.0, 3.0, 6.0, 7.0],
          [8.0, 15.0, 18.0, 25.0, 30.0, 35.0],
      ]
      x_data = [[-1.0, 2.0, 6.0], [8.0, 18.0, 30.0]]
  
      def _value_helper_fn(y_data):
          """A helper function that returns sum of squared interplated values."""
  
          interpolated_values = (
              tff.math.interpolation.linear.interpolate(
                  x,
                  x_data,
                  y_data,
                  optimize_for_tpu=optimize_for_tpu,
                  dtype=tf.float64,
              )
          )
          return tf.reduce_sum(tf.math.square(interpolated_values))
  
      y_data = tf.convert_to_tensor(
          [[10.0, -1.0, -5.0], [7.0, 9.0, 20.0]], dtype=tf.float64
      )
      if tf.executing_eagerly():
          with tf.GradientTape(watch_accessed_variables=False) as tape:
              tape.watch(y_data)
              value = _value_helper_fn(y_data=y_data)
              gradients = tape.gradient(value, y_data)
      else:
          value = _value_helper_fn(y_data=y_data)
          gradients = tf.gradients(value, y_data)[0]
  
      gradients = tf.convert_to_tensor(gradients)
  
      self.assertFalse(
          self.evaluate(tf.reduce_any(tf.math.is_nan(gradients)))
      )
  
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 11 for calling the LinearInterpolation obj's underlying member method code with example usage: obj.test_valid_gradients(optimize_for_tpu) and returns: tf