docstr: Shows misuse of `dtc._TensorCoercible(distribution)` in `tf.while_loop`.
  
  Since `dtc._TensorCoercible(distribution)` only creates the `Tensor` on an
  as-needed basis, care must be taken that the Tensor is created outside the
  body of a `tf.while_loop`, if the result is going to be used outside of the
  `tf.while_loop`. Although this is the case for any use of `tf.while_loop` we
  write this unit-test as a reminder of the behavior.
code: def _testWhileLoop(self):
      """Shows misuse of `dtc._TensorCoercible(distribution)` in `tf.while_loop`.
  
      Since `dtc._TensorCoercible(distribution)` only creates the `Tensor` on an
      as-needed basis, care must be taken that the Tensor is created outside the
      body of a `tf.while_loop`, if the result is going to be used outside of the
      `tf.while_loop`. Although this is the case for any use of `tf.while_loop` we
      write this unit-test as a reminder of the behavior.
      """
      mean_ = 0.5
      stddev_ = 2.0
      num_iter_ = 4
  
      x = dtc._TensorCoercible(
          normal.Normal(mean_, 0.75), distribution.Distribution.mean
      )
  
      # Note: in graph mode we can make the assertion not raise
      # if we make sure to create the Tensor outside the loop. Ie,
      # tf.convert_to_tensor(x)
  
      def _body(iter_, d):
          y = dtc._TensorCoercible(
              normal.Normal(0, stddev_),
              distribution.Distribution.stddev,
          )
          return [iter_ + 1, d + y + x]
  
      _, mean_plus_numiter_times_stddev = tf.while_loop(
          cond=lambda iter_, *args: iter_ < num_iter_,
          body=_body,
          loop_vars=[0, mean_],
      )
  
      if not tf.executing_eagerly():
          # In graph mode we cannot access the cached value of x outside the
          # tf.while_loop. To make this exception not occur, simply call
          # `tf.convert_to_tensor(x)` prior to the `tf.while_loop`.  Doing so will
          # cause the value of `x` to exist both outside and inside the
          # `tf.while_loop`.
          if tf1.control_flow_v2_enabled():
              error_regex = (
                  r"Tensor.*must be from the same graph as Tensor.*"
              )
          else:
              error_regex = "Cannot use.*in a while loop"
          with self.assertRaisesRegexp(ValueError, error_regex):
              _ = x + tf.constant(3.0)
          return
  
      # Things work in Eager mode because it has regular Python semantics,
      # ie, lexical scope rules.
      self.assertAllEqual(
          [
              mean_ + 3.0,
              mean_ + num_iter_ * (mean_ + stddev_),
          ],
          self.evaluate(
              [
                  x + tf.constant(3.0),
                  mean_plus_numiter_times_stddev,
              ]
          ),
      )
  
imports: import gc
  import operator
  from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import categorical
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.distributions import uniform
  from tensorflow_probability.python.internal import reparameterization
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.layers import distribution_layer
  from tensorflow_probability.python.layers.internal import distribution_tensor_coercible
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 14 for calling the DistributionTensorConversionTest obj's underlying member method code with example usage: obj._testWhileLoop() and returns: list