code: def test_hetero_mixture_binomial(p_val, size, supported):
      X_rv = pt.random.normal(0, 1, size=size, name="X")
      Y_rv = pt.random.gamma(0.5, scale=2.0, size=size, name="Y")
  
      if np.ndim(p_val) == 0:
          p_at = pt.scalar("p")
          p_at.tag.test_value = p_val
          I_rv = pt.random.bernoulli(p_at, size=size, name="I")
          p_val_1 = p_val
      else:
          p_at = pt.vector("p")
          p_at.tag.test_value = np.array(
              p_val, dtype=pytensor.config.floatX
          )
          I_rv = pt.random.categorical(p_at, size=size, name="I")
          p_val_1 = p_val[1]
  
      i_vv = I_rv.clone()
      i_vv.name = "i"
  
      M_rv = pt.stack([X_rv, Y_rv])[I_rv]
      M_rv.name = "M"
  
      m_vv = M_rv.clone()
      m_vv.name = "m"
  
      if supported:
          M_logp = conditional_logp({M_rv: m_vv, I_rv: i_vv})
          M_logp_combined = pt.add(*M_logp.values())
      else:
          with pytest.raises(
              RuntimeError, match="could not be derived: {m}"
          ):
              conditional_logp({M_rv: m_vv, I_rv: i_vv})
          return
  
      M_logp_fn = pytensor.function([p_at, m_vv, i_vv], M_logp_combined)
  
      assert_no_rvs(M_logp_fn.maker.fgraph.outputs[0])
  
      decimals = 6 if pytensor.config.floatX == "float64" else 4
  
      test_val_rng = np.random.RandomState(3238)
  
      bern_sp = sp.bernoulli(p_val_1)
      norm_sp = sp.norm(loc=0, scale=1)
      gamma_sp = sp.gamma(0.5, scale=2.0)
  
      for i in range(10):
          i_val = bern_sp.rvs(size=size, random_state=test_val_rng)
          x_val = norm_sp.rvs(size=size, random_state=test_val_rng)
          y_val = gamma_sp.rvs(size=size, random_state=test_val_rng)
  
          component_logps = np.stack(
              [norm_sp.logpdf(x_val), gamma_sp.logpdf(y_val)]
          )[i_val]
          exp_obs_logps = component_logps + bern_sp.logpmf(i_val)
  
          m_val = np.stack([x_val, y_val])[i_val]
          logp_vals = M_logp_fn(p_val, m_val, i_val)
  
          np.testing.assert_almost_equal(
              logp_vals, exp_obs_logps, decimal=decimals
          )
  
imports: import numpy
  import pytensor
  import pytensor.tensor
  import pytest
  import scipy.stats.distributions
  from pytensor import function
  from pytensor.graph.basic import Variable
  from pytensor.ifelse import ifelse
  from pytensor.tensor.random.basic import CategoricalRV
  from pytensor.tensor.shape import shape_tuple
  from pytensor.tensor.subtensor import AdvancedSubtensor, AdvancedSubtensor1, Subtensor, as_index_constant
  from pymc.logprob.abstract import MeasurableVariable
  from pymc.logprob.basic import conditional_logp, logp
  from pymc.logprob.mixture import MeasurableSwitchMixture, expand_indices
  from pymc.logprob.rewriting import construct_ir_fgraph
  from pymc.logprob.utils import dirac_delta
  from pymc.testing import assert_no_rvs
  from tests.logprob.utils import scipy_logprob
label_desc: Use image node_id 3 for calling a global function with example usage: test_hetero_mixture_binomial(p_val, size, supported) without return types