code: def test_dist_to_funsor_categorical(batch_shape, cardinality):
      logits = torch.randn(batch_shape + (cardinality,))
      logits -= logits.logsumexp(dim=-1, keepdim=True)
      d = dist.Categorical(logits=logits)
      f = dist_to_funsor(d)
      assert isinstance(f, Tensor)
      expected = tensor_to_funsor(logits, ("value",))
      assert_close(f, expected)
  
imports: from collections import OrderedDict
  import pyro.distributions
  import pytest
  import torch
  from pyro.distributions.torch_distribution import MaskedDistribution
  from funsor.domains import Bint, Reals
  from funsor.pyro.convert import dist_to_funsor, funsor_to_cat_and_mvn, funsor_to_mvn, funsor_to_tensor, matrix_and_mvn_to_funsor, mvn_to_funsor, tensor_to_funsor
  from funsor.tensor import Tensor
  from funsor.terms import Funsor
  from funsor.testing import assert_close, random_mvn
label_desc: Use image node_id 7 for calling a global function with example usage: test_dist_to_funsor_categorical(batch_shape, cardinality) without return types