code: def test_factorized_joint_logprob_basic():
      # A simple check for when `factorized_joint_logprob` is the same as `logprob`
      a = pt.random.uniform(0.0, 1.0)
      a.name = "a"
      a_value_var = a.clone()
  
      a_logp = conditional_logp({a: a_value_var})
      a_logp_comb = tuple(a_logp.values())[0]
      a_logp_exp = logp(a, a_value_var)
  
      assert equal_computations([a_logp_comb], [a_logp_exp])
  
      # Let's try a hierarchical model
      sigma = pt.random.invgamma(0.5, 0.5)
      Y = pt.random.normal(0.0, sigma)
  
      sigma_value_var = sigma.clone()
      y_value_var = Y.clone()
  
      total_ll = conditional_logp(
          {Y: y_value_var, sigma: sigma_value_var}
      )
      total_ll_combined = pt.add(*total_ll.values())
  
      # We need to replace the reference to `sigma` in `Y` with its value
      # variable
      ll_Y = logp(Y, y_value_var)
      (ll_Y,) = replace_rvs_by_values(
          [ll_Y],
          rvs_to_values={sigma: sigma_value_var},
      )
      total_ll_exp = logp(sigma, sigma_value_var) + ll_Y
  
      assert equal_computations([total_ll_combined], [total_ll_exp])
  
      # Now, make sure we can compute a joint log-probability for a hierarchical
      # model with some non-`RandomVariable` nodes
      c = pt.random.normal()
      c.name = "c"
      b_l = c * a + 2.0
      b = pt.random.uniform(b_l, b_l + 1.0)
      b.name = "b"
  
      b_value_var = b.clone()
      c_value_var = c.clone()
  
      b_logp = conditional_logp(
          {a: a_value_var, b: b_value_var, c: c_value_var}
      )
      b_logp_combined = pt.sum(
          [pt.sum(factor) for factor in b_logp.values()]
      )
  
      # There shouldn't be any `RandomVariable`s in the resulting graph
      assert_no_rvs(b_logp_combined)
  
      res_ancestors = list(ancestors((b_logp_combined,)))
      assert b_value_var in res_ancestors
      assert c_value_var in res_ancestors
      assert a_value_var in res_ancestors
  
imports: import warnings
  import numpy
  import pytensor
  import pytensor.tensor
  import pytest
  import scipy.stats.distributions
  from pytensor.graph.basic import ancestors, equal_computations
  from pytensor.tensor.random.op import RandomVariable
  from pytensor.tensor.subtensor import AdvancedIncSubtensor, AdvancedIncSubtensor1, IncSubtensor
  import pymc
  from pymc.logprob.basic import conditional_logp, icdf, logcdf, logp, transformed_conditional_logp
  from pymc.logprob.transforms import LogTransform
  from pymc.logprob.utils import replace_rvs_by_values
  from pymc.testing import assert_no_rvs
label_desc: Use image node_id 1 for calling a global function with example usage: test_factorized_joint_logprob_basic() without return types