code: def test_idempotent(batch_dim, event_dim):
      shape = torch.Size((1, 2, 3, 4))[: batch_dim + event_dim]
      batch_shape = shape[:batch_dim]
      event_shape = shape[batch_dim:]
  
      # Construct a base dist of desired starting shape.
      dist0 = Bernoulli(0.5).expand_by(shape).to_event(event_dim)
      assert dist0.batch_shape == batch_shape
      assert dist0.event_shape == event_shape
  
      # Check that an .expand_by() an empty shape is a no-op.
      dist = dist0.expand_by([])
      assert dist.batch_shape == dist0.batch_shape
      assert dist.event_shape == dist0.event_shape
  
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 2 for calling a global function with example usage: test_idempotent(batch_dim, event_dim) without return types