code: def test_log_prob(batch_shape, event_shape, dtype):
      samples = []
      for i in range(5):
          samples.append(torch.ones(event_shape, dtype=dtype) * i)
      samples = torch.stack(samples).expand(
          batch_shape + [5] + event_shape
      )
      weights = torch.tensor(1.0).expand(batch_shape + [5])
      empirical_dist = Empirical(samples, weights)
      sample_to_score = torch.tensor(1, dtype=dtype).expand(
          batch_shape + event_shape
      )
      log_prob = empirical_dist.log_prob(sample_to_score)
      assert_equal(
          log_prob,
          (weights.new_ones(batch_shape + [1]) * 0.2).sum(-1).log(),
      )
  
      # Value outside support returns -Inf
      sample_to_score = (
          torch.tensor(1, dtype=dtype).expand(batch_shape + event_shape)
          * 6
      )
      log_prob = empirical_dist.log_prob(sample_to_score)
      assert log_prob.shape == torch.Size(batch_shape)
      assert torch.isinf(log_prob).all()
  
      # Vectorized ``log_prob`` raises ValueError
      with pytest.raises(ValueError):
          sample_to_score = torch.ones(
              [3] + batch_shape + event_shape, dtype=dtype
          )
          empirical_dist.log_prob(sample_to_score)
  
file_path: pyro/tests/distributions/test_empirical.py
imports: import pytest
  import torch
  from pyro.distributions.empirical import Empirical
  from tests.common import assert_close, assert_equal
label_desc: Use image node_id 4 for calling a global function with example usage: test_log_prob(batch_shape, event_shape, dtype) without return types