code: def _masked_log_prob_ratio(p, x, q, y, name=None):
      """Computes log p(x) - log q(y) for Masked p, q."""
      with tf.name_scope(name or "masked_log_prob_ratio"):
          p_valid = tf.convert_to_tensor(p.validity_mask)
          safe_x = tf.where(
              _add_event_dims_to_mask(p_valid, dist=p),
              x,
              tf.stop_gradient(p.safe_sample_fn(p.distribution)),
          )
          q_valid = tf.convert_to_tensor(q.validity_mask)
          safe_y = tf.where(
              _add_event_dims_to_mask(q_valid, dist=q),
              y,
              tf.stop_gradient(q.safe_sample_fn(q.distribution)),
          )
          underlying = log_prob_ratio.log_prob_ratio(
              p.distribution, safe_x, q.distribution, safe_y
          )
          asserts = []
          # As with KL, we return the underlying log_prob_ratio where both are valid,
          # `0.` where neither is valid, and `nan` otherwise (or an assertion if
          # either distribution does not `allow_nan_stats`).
          if not (p.allow_nan_stats and p.allow_nan_stats):
              asserts.append(
                  assert_util.assert_equal(
                      p_valid,
                      q_valid,
                      message="Masked log_prob_ratio only valid for matching mask values",
                  )
              )
          with tf.control_dependencies(asserts):
              both_valid = p_valid & q_valid
              neither_valid = (~p_valid) & (~q_valid)
              return tf.where(
                  both_valid,
                  underlying,
                  tf.where(
                      neither_valid,
                      tf.zeros([], dtype=underlying.dtype),
                      float("nan"),
                  ),
              )
  
imports: import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import bijector
  from tensorflow_probability.python.distributions import batch_broadcast
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.distributions import log_prob_ratio
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import auto_composite_tensor
  from tensorflow_probability.python.internal import parameter_properties
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import tensor_util
label_desc: Use image node_id 5 for calling a global function with example usage: _masked_log_prob_ratio(p, x, q, y, name) and returns: tf