class_docstr: Since `cat` must be categorical.Categorical, we check only components.
class_docstr_tok: ["Since","`","cat","`","must","be","categorical.Categorical",",","we","check","only","components","."]
code: def testStatefulComponentDist(self):
      class StatefulNormal(distribution.Distribution):
          def __init__(self, loc):
              self._loc = tf.convert_to_tensor(loc)
              super(StatefulNormal, self).__init__(
                  dtype=tf.float32,
                  reparameterization_type=reparameterization.FULLY_REPARAMETERIZED,
                  validate_args=False,
                  allow_nan_stats=False,
              )
  
          def _batch_shape(self):
              return self._loc.shape
  
          def _event_shape(self):
              return []
  
          def _sample_n(self, n, seed=None):
              return self._loc + tf.random.normal(
                  tf.concat([[n], tf.shape(self._loc)], axis=0),
                  seed=seed,
              )
  
      mix = mixture.Mixture(
          cat=categorical.Categorical(logits=[0.0, 0]),
          components=[
              half_normal.HalfNormal(scale=2.0),
              StatefulNormal(loc=3.0),
          ],
      )
      with warnings.catch_warnings(record=True) as triggered:
          self.evaluate(mix.sample(seed=test_util.test_seed()))
      self.assertTrue(
          any(
              "Falling back to stateful sampling for `components[1]`"
              in str(warning.message)
              for warning in triggered
          )
      )
  
imports: import contextlib
  import warnings
  import numpy
  from scipy import stats
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import categorical
  from tensorflow_probability.python.distributions import dirichlet
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.distributions import gamma
  from tensorflow_probability.python.distributions import half_normal
  from tensorflow_probability.python.distributions import independent
  from tensorflow_probability.python.distributions import mixture
  from tensorflow_probability.python.distributions import mvn_diag
  from tensorflow_probability.python.distributions import mvn_tril
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.internal import hypothesis_testlib
  from tensorflow_probability.python.internal import reparameterization
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.internal import test_util
label_desc: Use image node_id 1 for calling the SamplerBackwardCompatibilityTest obj's underlying member method code with example usage: obj.testStatefulComponentDist() and returns: self, list, unknown