class_docstr: Test for tfp.math.trapz.
class_docstr_tok: ["Test","for","tfp.math.trapz","."]
code: def test_convergence_nonuniform_x(self):
      # Each 10x decrease in dx gives a 100x increase in integral accuracy.
      # This demonstrates that trapz() has quadratic converence.
      def trapz_sin_fn(x_min, x_max, n, expected, rtol):
          pi = tf.constant(np.pi, dtype=tf.float32)
          s = np.linspace(0, 1, n) ** 1.5
          x = tf.convert_to_tensor(
              x_min + s * (x_max - x_min), tf.float32
          )
          y = tf.sin(pi * x)
          np.testing.assert_allclose(
              self.evaluate(integration.trapz(y, x)),
              expected,
              rtol=rtol,
          )
  
      with self.subTest("sin(2pi x) over [0, 1]"):
          # integral[sin(pi*x)] for x over [0, 1] is equal to 2 / pi.
          trapz_sin_fn(0, 1, 20, 2 / np.pi, rtol=3.2e-3)
          trapz_sin_fn(0, 1, 200, 2 / np.pi, rtol=2.9e-5)
          trapz_sin_fn(0, 1, 2000, 2 / np.pi, rtol=4.2e-7)
  
      with self.subTest("sin(2pi x) over [1, 2]"):
          # integral[sin(pi*x)] for x over [1, 2] is equal to -2 / pi.
          trapz_sin_fn(1, 2, 20, -2 / np.pi, rtol=3.2e-3)
          trapz_sin_fn(1, 2, 200, -2 / np.pi, rtol=2.9e-5)
          trapz_sin_fn(1, 2, 2000, -2 / np.pi, rtol=4.2e-7)
  
imports: import hypothesis
  from hypothesis import strategies
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import hypothesis_testlib
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math import integration
label_desc: Use image node_id 13 for calling the TrapzTest obj's underlying member method code with example usage: obj.test_convergence_nonuniform_x() without return types