code: def testDomainErrorExceptions(self):
      class MyDistException(normal.Normal):
          pass
  
      # Register KL to a lambda that spits out the name parameter
      @kullback_leibler.RegisterKL(MyDistException, MyDistException)
      # pylint: disable=unused-argument,unused-variable
      def _kl(a, b, name=None):
          return tf.identity([float("nan")])
  
      # pylint: disable=unused-argument,unused-variable
  
      a = MyDistException(loc=0.0, scale=1.0, allow_nan_stats=False)
      with self.assertRaisesOpError(
          "KL calculation between .* and .* returned NaN values"
      ):
          kl = kullback_leibler.kl_divergence(
              a, a, allow_nan_stats=False
          )
          self.evaluate(kl)
      with self.assertRaisesOpError(
          "KL calculation between .* and .* returned NaN values"
      ):
          self.evaluate(a.kl_divergence(a))
      a = MyDistException(loc=0.0, scale=1.0, allow_nan_stats=True)
      kl_ok = kullback_leibler.kl_divergence(a, a)
      self.assertAllEqual([float("nan")], self.evaluate(kl_ok))
      self_kl_ok = a.kl_divergence(a)
      self.assertAllEqual([float("nan")], self.evaluate(self_kl_ok))
      cross_ok = a.cross_entropy(a)
      self.assertAllEqual([float("nan")], self.evaluate(cross_ok))
  
file_path: probability/tensorflow_probability/python/distributions/kullback_leibler_test.py
imports: import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.internal import reparameterization
  from tensorflow_probability.python.internal import test_util
label_desc: Use image node_id 2 for calling the KLTest obj's underlying member method code with example usage: obj.testDomainErrorExceptions() and returns: tf