code: def test_sampling(self):
      d = masked.Masked(
          normal.Normal(tf.zeros([20]), 1),
          tf.sequence_mask(15, 20),
          safe_sample_fn=distribution.Distribution.mode,
      )
      self.assertAllEqual(
          tf.zeros([5]),  # distribution mode
          d.sample(seed=test_util.test_seed())[15:],
      )
  
      # Gamma doesn't have mode for concentration<1.
      # Let's verify we don't trigger an assert.
      d = masked.Masked(
          gamma.Gamma(0.9, tf.ones([20]), allow_nan_stats=False),
          tf.sequence_mask(13, 20),
          safe_sample_fn=distribution.Distribution.mean,
      )
      self.assertAllEqual(
          d.distribution.mean()[15:],
          d.sample(seed=test_util.test_seed())[15:],
      )
  
      d = masked.Masked(
          gamma.Gamma(0.9, tf.ones([20]), allow_nan_stats=False),
          tf.sequence_mask(13, 20),
      )
      self.evaluate(d.sample(seed=test_util.test_seed()))
  
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.distributions import gamma
  from tensorflow_probability.python.distributions import independent
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.distributions import log_prob_ratio
  from tensorflow_probability.python.distributions import lognormal
  from tensorflow_probability.python.distributions import masked
  from tensorflow_probability.python.distributions import mvn_diag
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.distributions import relaxed_onehot_categorical
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math import gradient
label_desc: Use image node_id 2 for calling the MaskedTest obj's underlying member method code with example usage: obj.test_sampling() without return types