class_docstr: Since tfd.Sample uses transposes, it requires a custom event bijector.
class_docstr_tok: ["Since","tfd.Sample","uses","transposes",",","it","requires","a","custom","event","bijector","."]
code: def _bcast_and_reduce_logdet(self, underlying_ldj):
      # Ensure ldj is fully broadcast in the sample dims, i.e. ensure ldj has
      # full sample shape in the sample axes, before we reduce.
      batch_ndims = ps.rank_from_shape(
          self.distribution.batch_shape_tensor,
          self.distribution.batch_shape,
      )
      extra_sample_ndims = ps.rank_from_shape(self.sample_shape)
      sample_ndims = (
          ps.rank(underlying_ldj) - extra_sample_ndims - batch_ndims
      )
      bcast_ldj_shape = ps.broadcast_shape(
          ps.shape(underlying_ldj),
          ps.concat(
              [
                  ps.ones([sample_ndims], tf.int32),
                  ps.ones([batch_ndims], tf.int32),
                  ps.reshape(self.sample_shape, shape=[-1]),
              ],
              axis=0,
          ),
      )
      ldj = tf.broadcast_to(underlying_ldj, bcast_ldj_shape)
      return self._sum_fn(ldj, axis=-1 - ps.range(extra_sample_ndims))
  
imports: import functools
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import bijector
  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 dtype_util
  from tensorflow_probability.python.internal import parameter_properties
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import tensor_util
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.math import generic
label_desc: Use image node_id 9 for calling the _NonCompositeTensorDefaultSampleBijector obj's underlying member method code with example usage: obj._bcast_and_reduce_logdet(underlying_ldj) and returns: self