def METHOD_NAME(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))