code: def test_ifelse_mixture_shared_component():
      rng = np.random.default_rng(1009)
  
      if_var = pt.scalar("if_var", dtype="bool")
      outer_rv = pt.random.normal(name="outer")
      # comp_shared need not be an output of ifelse at all,
      # but since we allow arbitrary graphs we test it works as expected.
      comp_shared = pt.random.normal(size=(2,), name="comp_shared")
      comp_then = outer_rv + pt.random.normal(
          comp_shared, 1, size=(4, 2), name="comp_then"
      )
      comp_else = outer_rv + pt.random.normal(
          comp_shared, 10, size=(8, 2), name="comp_else"
      )
      shared_rv, mix_rv = ifelse(
          if_var,
          [comp_shared, comp_then],
          [comp_shared, comp_else],
          name="mix",
      )
  
      outer_vv = outer_rv.clone()
      shared_vv = shared_rv.clone()
      mix_vv = mix_rv.clone()
      outer_logp, mix_logp1, mix_logp2 = conditional_logp(
          {outer_rv: outer_vv, shared_rv: shared_vv, mix_rv: mix_vv}
      ).values()
      assert_no_rvs(outer_logp)
      assert_no_rvs(mix_logp1)
      assert_no_rvs(mix_logp2)
  
      fn = function(
          [if_var, outer_vv, shared_vv, mix_vv],
          mix_logp1.sum() + mix_logp2.sum(),
      )
      outer_vv_test = rng.normal()
      shared_vv_test = rng.normal(size=(2,))
      mix_vv_test = rng.normal(size=(4, 2))
      np.testing.assert_almost_equal(
          fn(True, outer_vv_test, shared_vv_test, mix_vv_test),
          (
              sp.norm(0, 1).logpdf(shared_vv_test).sum()
              + sp.norm(outer_vv_test + shared_vv_test, 1)
              .logpdf(mix_vv_test)
              .sum()
          ),
      )
      mix_vv_test = rng.normal(size=(8, 2))
      np.testing.assert_almost_equal(
          fn(False, outer_vv_test, shared_vv_test, mix_vv_test),
          (
              sp.norm(0, 1).logpdf(shared_vv_test).sum()
              + sp.norm(outer_vv_test + shared_vv_test, 10)
              .logpdf(mix_vv_test)
              .sum()
          ),
          decimal=6,
      )
  
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 16 for calling a global function with example usage: test_ifelse_mixture_shared_component() without return types