code: def test_nested_scalar_mixtures():
      x = pt.random.normal(loc=-50, name="x")
      y = pt.random.normal(loc=50, name="y")
      comps1 = pt.stack([x, y])
      comps1.name = "comps1"
      idxs1 = pt.random.bernoulli(0.5, name="idxs1")
      mix1 = comps1[idxs1]
      mix1.name = "mix1"
  
      w = pt.random.normal(loc=-100, name="w")
      z = pt.random.normal(loc=100, name="z")
      comps2 = pt.stack([w, z])
      comps2.name = "comps2"
      idxs2 = pt.random.bernoulli(0.5, name="idxs2")
      mix2 = comps2[idxs2]
      mix2.name = "mix2"
  
      comps12 = pt.stack([mix1, mix2])
      comps12.name = "comps12"
      idxs12 = pt.random.bernoulli(0.5, name="idxs12")
      mix12 = comps12[idxs12]
      mix12.name = "mix12"
  
      idxs1_vv = idxs1.clone()
      idxs2_vv = idxs2.clone()
      idxs12_vv = idxs12.clone()
      mix12_vv = mix12.clone()
  
      logp = conditional_logp(
          {
              idxs1: idxs1_vv,
              idxs2: idxs2_vv,
              idxs12: idxs12_vv,
              mix12: mix12_vv,
          }
      )
      logp_combined = pt.sum(
          [pt.sum(factor) for factor in logp.values()]
      )
  
      logp_fn = pytensor.function(
          [idxs1_vv, idxs2_vv, idxs12_vv, mix12_vv], logp_combined
      )
  
      expected_mu_logpdf = st.norm.logpdf(0) + np.log(0.5) * 3
      assert np.isclose(logp_fn(0, 0, 0, -50), expected_mu_logpdf)
      assert np.isclose(logp_fn(0, 1, 0, -50), expected_mu_logpdf)
      assert np.isclose(logp_fn(1, 0, 0, 50), expected_mu_logpdf)
      assert np.isclose(logp_fn(1, 1, 0, 50), expected_mu_logpdf)
      assert np.isclose(logp_fn(0, 0, 1, -100), expected_mu_logpdf)
      assert np.isclose(logp_fn(0, 1, 1, 100), expected_mu_logpdf)
      assert np.isclose(logp_fn(1, 0, 1, -100), expected_mu_logpdf)
      assert np.isclose(logp_fn(1, 1, 1, 100), expected_mu_logpdf)
  
      assert np.isclose(
          logp_fn(0, 0, 0, 50), st.norm.logpdf(100) + np.log(0.5) * 3
      )
      assert np.isclose(
          logp_fn(0, 0, 1, 50), st.norm.logpdf(150) + np.log(0.5) * 3
      )
  
file_path: pymc/tests/logprob/test_composite_logprob.py
imports: import numpy
  import pytensor
  import pytensor.tensor
  import pytest
  import scipy.stats
  from pymc import draw, logp
  from pymc.logprob.abstract import MeasurableVariable
  from pymc.logprob.basic import conditional_logp
  from pymc.logprob.rewriting import construct_ir_fgraph
  from pymc.testing import assert_no_rvs
label_desc: Use image node_id 2 for calling a global function with example usage: test_nested_scalar_mixtures() without return types