code: def _test_grad_accuracy(self, dtype, grid_spec, error_spec):
      grid = _make_grid(dtype, grid_spec)
      _, actual_grad = self.evaluate(
          value_and_gradient(
              special_math.log_ndtr
              if self._use_log
              else special_math.ndtr,
              grid,
          )
      )
  
      # Check for NaN separately in order to get informative failures.
      self.assert_all_false(np.isnan(actual_grad))
      if self._use_log:
          g = np.reshape(actual_grad, [-1])
          half = np.ceil(len(g) / 2)
          self.assert_all_true(g[: int(half)] > 0.0)
          self.assert_all_true(g[int(half) :] >= 0.0)
      else:
          # The ndtr gradient will only be non-zero in the range [-14, 14] for
          # float32 and [-38, 38] for float64.
          self.assert_all_true(actual_grad >= 0.0)
      # isfinite checks for NaN and Inf.
      self.assert_all_true(np.isfinite(actual_grad))
  
      # Versus scipy.
      if not (sp_special and sp_stats):
          return
  
      expected_grad = sp_stats.norm.pdf(grid)
      if self._use_log:
          expected_grad /= sp_special.ndtr(grid)
          expected_grad[np.isnan(expected_grad)] = 0.0
      # Scipy prematurely goes to zero at some places that we don't.  So don't
      # include these in the comparison.
      self.assertAllClose(
          expected_grad.astype(np.float64)[expected_grad < 0],
          actual_grad.astype(np.float64)[expected_grad < 0],
          rtol=error_spec.rtol,
          atol=error_spec.atol,
      )
  
imports: import collections
  import numpy
  from scipy import special
  from scipy import stats
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import special_math
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math.gradient import value_and_gradient
label_desc: Use image node_id 4 for calling the NdtrGradientTest obj's underlying member method code with example usage: obj._test_grad_accuracy(dtype, grid_spec, error_spec) without return types