code: def test_extra_event_dim_overflow(sample_dim, batch_dim, event_dim):
      shape = torch.Size(range(sample_dim + batch_dim + event_dim))
      sample_shape = shape[:sample_dim]
      batch_shape = shape[sample_dim : sample_dim + batch_dim]
      event_shape = shape[sample_dim + batch_dim :]
  
      # Construct a base dist of desired starting shape.
      dist0 = (
          Bernoulli(0.5)
          .expand_by(batch_shape + event_shape)
          .to_event(event_dim)
      )
      assert dist0.batch_shape == batch_shape
      assert dist0.event_shape == event_shape
  
      # Check .to_event(...) for valid values.
      for extra_event_dims in range(1 + sample_dim + batch_dim):
          dist = dist0.expand_by(sample_shape).to_event(
              extra_event_dims
          )
          assert (
              dist.batch_shape
              == shape[: sample_dim + batch_dim - extra_event_dims]
          )
          assert (
              dist.event_shape
              == shape[sample_dim + batch_dim - extra_event_dims :]
          )
  
      # Check .to_event(...) for invalid values.
      for extra_event_dims in range(1 + sample_dim + batch_dim, 20):
          with pytest.raises(ValueError):
              dist0.expand_by(sample_shape).to_event(extra_event_dims)
  
file_path: pyro/tests/distributions/test_reshape.py
imports: import pytest
  import torch
  from pyro.distributions.torch import Bernoulli
  from tests.common import assert_equal
label_desc: Use image node_id 5 for calling a global function with example usage: test_extra_event_dim_overflow(sample_dim, batch_dim, event_dim) without return types