code: def logprob_ScanRV(op, values, *inputs, name=None, **kwargs):
      new_node = op.make_node(*inputs)
      scan_args = ScanArgs.from_node(new_node)
      rv_outer_outs = get_random_outer_outputs(scan_args)
  
      var_indices, rv_vars, io_vars = zip(*rv_outer_outs)
      value_map = {_rv: _val for _rv, _val in zip(rv_vars, values)}
  
      def create_inner_out_logp(
          value_map: Dict[TensorVariable, TensorVariable]
      ) -> TensorVariable:
          """Create a log-likelihood inner-output for a `Scan`."""
          logp_parts = conditional_logp(value_map, warn_rvs=False)
          return logp_parts.values()
  
      logp_scan_args = convert_outer_out_to_in(
          scan_args,
          rv_vars,
          value_map,
          inner_out_fn=create_inner_out_logp,
      )
  
      # Remove the shared variables corresponding to replaced terms.
  
      # TODO FIXME: This is a really dirty approach, because it effectively
      # assumes that all sampling is being removed, and, thus, all shared updates
      # relating to `RandomType`s.  Instead, we should be more precise and only
      # remove the `RandomType`s associated with `values`.
      logp_scan_args.outer_in_shared = [
          i
          for i in logp_scan_args.outer_in_shared
          if not isinstance(i.type, RandomType)
      ]
      logp_scan_args.inner_in_shared = [
          i
          for i in logp_scan_args.inner_in_shared
          if not isinstance(i.type, RandomType)
      ]
      logp_scan_args.inner_out_shared = [
          i
          for i in logp_scan_args.inner_out_shared
          if not isinstance(i.type, RandomType)
      ]
      # XXX TODO: Remove this properly
      # logp_scan_args.outer_out_shared = []
  
      logp_scan_out, updates = construct_scan(
          logp_scan_args, mode=op.mode
      )
  
      # Automatically pick up updates so that we don't have to pass them around
      for key, value in updates.items():
          key.default_update = value
  
      # Return only the logp outputs, not any potentially carried states
      logp_outputs = logp_scan_out[-len(values) :]
  
      if len(logp_outputs) == 1:
          return logp_outputs[0]
      return logp_outputs
  
imports: from copy import copy
  from typing import Callable, Dict, Iterable, List, Optional, Tuple, cast
  import numpy
  import pytensor
  import pytensor.tensor
  from pytensor.graph.basic import Variable
  from pytensor.graph.op import compute_test_value
  from pytensor.graph.rewriting.basic import node_rewriter
  from pytensor.graph.rewriting.db import RewriteDatabaseQuery
  from pytensor.scan.op import Scan
  from pytensor.scan.rewriting import scan_eqopt1, scan_eqopt2
  from pytensor.scan.utils import ScanArgs
  from pytensor.tensor.random.type import RandomType
  from pytensor.tensor.subtensor import Subtensor, indices_from_subtensor
  from pytensor.tensor.variable import TensorVariable
  from pytensor.updates import OrderedUpdates
  from pymc.logprob.abstract import MeasurableVariable, _logprob
  from pymc.logprob.basic import conditional_logp
  from pymc.logprob.rewriting import PreserveRVMappings, construct_ir_fgraph, inc_subtensor_ops, logprob_rewrites_db, measurable_ir_rewrites_db
  from pymc.logprob.utils import replace_rvs_by_values
label_desc: Use image node_id 4 for calling a global function with example usage: logprob_ScanRV(op, values) and returns: logp_outputs, logp_parts, logp_outputs