code: def test_independent(
      base_dist, sample_shape, batch_shape, reinterpreted_batch_ndims
  ):
      if batch_shape:
          base_dist = base_dist.expand_by(batch_shape)
      if reinterpreted_batch_ndims > len(base_dist.batch_shape):
          with pytest.raises(ValueError):
              d = dist.Independent(base_dist, reinterpreted_batch_ndims)
      else:
          d = dist.Independent(base_dist, reinterpreted_batch_ndims)
          assert (
              d.batch_shape
              == batch_shape[
                  : len(batch_shape) - reinterpreted_batch_ndims
              ]
          )
          assert (
              d.event_shape
              == batch_shape[
                  len(batch_shape) - reinterpreted_batch_ndims :
              ]
              + base_dist.event_shape
          )
  
          assert d.sample().shape == batch_shape + base_dist.event_shape
          assert d.mean.shape == batch_shape + base_dist.event_shape
          assert d.variance.shape == batch_shape + base_dist.event_shape
          x = d.sample(sample_shape)
          assert x.shape == sample_shape + d.batch_shape + d.event_shape
  
          log_prob = d.log_prob(x)
          assert (
              log_prob.shape
              == sample_shape
              + batch_shape[
                  : len(batch_shape) - reinterpreted_batch_ndims
              ]
          )
          assert not torch_isnan(log_prob)
          log_prob_0 = base_dist.log_prob(x)
          assert_equal(
              log_prob,
              _sum_rightmost(log_prob_0, reinterpreted_batch_ndims),
          )
  
file_path: pyro/tests/distributions/test_independent.py
imports: import pytest
  import torch
  from torch.distributions.utils import _sum_rightmost
  import pyro.distributions
  from pyro.util import torch_isnan
  from tests.common import assert_equal
label_desc: Use image node_id 1 for calling a global function with example usage: test_independent(base_dist, sample_shape, batch_shape, reinterpreted_batch_ndims) without return types