code: def test_categorical_sample(sample_shape, batch_shape, cardinality):
      logits = torch.randn(batch_shape + (cardinality,))
      logits -= logits.logsumexp(dim=-1, keepdim=True)
      actual = Categorical(logits=logits)
      expected = dist.Categorical(logits=logits)
      assert actual.batch_shape == expected.batch_shape
      assert actual.event_shape == expected.event_shape
  
      actual_sample = actual.sample(sample_shape)
      expected_sample = expected.sample(sample_shape)
      assert actual_sample.dtype == expected_sample.dtype
      assert actual_sample.shape == expected_sample.shape
      expected.log_prob(actual_sample)
  
file_path: funsor/test/pyro/test_distribution.py
imports: import pyro.distributions
  import pytest
  import torch
  from funsor.pyro.convert import tensor_to_funsor
  from funsor.pyro.distribution import FunsorDistribution
  from funsor.testing import assert_close
label_desc: Use image node_id 2 for calling a global function with example usage: test_categorical_sample(sample_shape, batch_shape, cardinality) without return types