code: def local_careduce_fusion(fgraph, node):
      """Fuse a `CAReduce` applied to an `Elemwise`."""
  
      (car_input,) = node.inputs
      car_scalar_op = node.op.scalar_op
  
      # FIXME: This check is needed because of the faulty logic in the FIXME below!
      # Right now, rewrite only works for `Sum`/`Prod`
      if not isinstance(car_scalar_op, (ps.Add, ps.Mul)):
          return None
  
      elm_node = car_input.owner
  
      if elm_node is None or not isinstance(elm_node.op, Elemwise):
          return False
  
      elm_scalar_op = elm_node.op.scalar_op
  
      elm_inputs = elm_node.inputs
      elm_outputs = elm_node.outputs
  
      if len(elm_inputs) > 1 or len(elm_outputs) > 1:
          # TODO: Implement the multiple inputs case
          return False
  
      if len(fgraph.clients[elm_outputs[0]]) > 1:
          return False
  
      # Don't form the fusion when the target language is Python
      if get_target_language() == ("py",):
          return False
  
      if not elm_scalar_op.supports_c_code(elm_inputs, elm_outputs):
          return None
  
      # FIXME: This fails with Ops like `Max` whose `c_code` always expects two inputs!
      #  Should implement a `CAReduce.supports_c_code`?
      try:
          car_scalar_op.c_code(
              node,
              "test_presence_of_c_code",
              ["x" for x in node.inputs],
              ["z" for z in node.outputs],
              {"fail": "%(fail)s"},
          )
      except (NotImplementedError, MethodNotDefined):
          return False
  
      car_op = node.op
      car_acc_dtype = node.op.acc_dtype
  
      scalar_elm_inputs = [
          ps.get_scalar_type(inp.type.dtype).make_variable()
          for inp in elm_inputs
      ]
  
      elm_output = elm_scalar_op(*scalar_elm_inputs)
  
      # This input represents the previous value in the `CAReduce` binary reduction
      carried_car_input = ps.get_scalar_type(
          car_acc_dtype
      ).make_variable()
  
      scalar_fused_output = car_scalar_op(carried_car_input, elm_output)
      if scalar_fused_output.type.dtype != car_acc_dtype:
          scalar_fused_output = ps.cast(
              scalar_fused_output, car_acc_dtype
          )
  
      fused_scalar_op = ps.Composite(
          inputs=[carried_car_input] + scalar_elm_inputs,
          outputs=[scalar_fused_output],
      )
  
      # The fused `Op` needs to look and behave like a `BinaryScalarOp`
      # TODO: Generate a new `type` and make this relationship official?
      fused_scalar_op.identity = car_scalar_op.identity
      fused_scalar_op.nin = 2
      fused_scalar_op.nout = 1
  
      new_car_op = CAReduce(
          scalar_op=fused_scalar_op,
          axis=car_op.axis,
          acc_dtype=car_acc_dtype,
          dtype=car_op.dtype,
          upcast_discrete_output=car_op.upcast_discrete_output,
      )
  
      return [new_car_op(*elm_inputs)]
  
imports: import sys
  from collections import defaultdict, deque
  from collections.abc import Generator
  from functools import cache
  from typing import TypeVar
  from warnings import warn
  import pytensor
  import pytensor.scalar.basic
  from pytensor import clone_replace, compile
  from pytensor.compile.mode import get_target_language
  from pytensor.configdefaults import config
  from pytensor.graph import FunctionGraph
  from pytensor.graph.basic import Apply, Constant, Variable, ancestors, io_toposort
  from pytensor.graph.features import ReplaceValidate
  from pytensor.graph.fg import ApplyOrOutput
  from pytensor.graph.rewriting.basic import EquilibriumGraphRewriter, GraphRewriter, copy_stack_trace, in2out, node_rewriter
  from pytensor.graph.rewriting.db import SequenceDB
  from pytensor.graph.utils import InconsistencyError, MethodNotDefined
  from pytensor.scalar.loop import ScalarLoop
  from pytensor.scalar.math import Grad2F1Loop, _grad_2f1_loop
  from pytensor.tensor.basic import MakeVector, alloc, cast, get_underlying_scalar_constant_value
  from pytensor.tensor.elemwise import CAReduce, DimShuffle, Elemwise
  from pytensor.tensor.exceptions import NotScalarConstantError
  from pytensor.tensor.math import exp
  from pytensor.tensor.rewriting.basic import alloc_like, register_canonicalize, register_specialize
  from pytensor.tensor.shape import shape_padleft
  from pytensor.tensor.variable import TensorConstant, get_unique_constant_value
label_desc: Use image node_id 9 for calling a global function with example usage: local_careduce_fusion(fgraph, node) and returns: list, None, False, False, False, False, None, False