code: def _beta_L_plus_alpha_M(
      fgraph, beta, L, alpha, M, recurse_flip=True
  ):
      # print 'BETA L + ALPHA M', beta, L, alpha, M, recurse_flip
      # EXPRESSION: (beta * L) + (alpha * M)
  
      # we've already checked the client counts, now just make the type check.
      # if res_is_a(M, _dot22, 1):
      if M.owner and M.owner.op == _dot22:
          Ml, Mr = M.owner.inputs
          rval = [gemm_no_inplace(L, alpha, Ml, Mr, beta)]
          return rval, M
  
      # it also might be the case that there is a dimshuffle between the +
      # and the dot22. local_dot_to_dot22 in particular will put in such things.
      if (
          M.owner
          and isinstance(M.owner.op, DimShuffle)
          and M.owner.inputs[0].owner
          and isinstance(M.owner.inputs[0].owner.op, Dot22)
      ):
          MM = M.owner.inputs[0]
          if M.owner.op.new_order == (0,):
              # it is making a column MM into a vector
              MMl, MMr = MM.owner.inputs
              g = gemm_no_inplace(
                  L.dimshuffle(0, "x"), alpha, MMl, MMr, beta
              )
              rval = [g.dimshuffle(0)]
              return rval, MM
          if M.owner.op.new_order == (1,):
              # it is making a row MM into a vector
              MMl, MMr = MM.owner.inputs
              g = gemm_no_inplace(
                  L.dimshuffle("x", 0), alpha, MMl, MMr, beta
              )
              rval = [g.dimshuffle(1)]
              return rval, MM
          if len(M.owner.op.new_order) == 0:
              # it is making a row MM into a vector
              MMl, MMr = MM.owner.inputs
              g = gemm_no_inplace(
                  L.dimshuffle("x", "x"), alpha, MMl, MMr, beta
              )
              rval = [g.dimshuffle()]
              return rval, MM
  
      if recurse_flip:
          return _beta_L_plus_alpha_M(
              fgraph, alpha, M, beta, L, recurse_flip=False
          )
      else:
          return False, False
  
imports: import copy
  import logging
  import time
  import numpy
  from pytensor.tensor.rewriting.basic import register_specialize
  import pytensor.scalar
  from pytensor.compile.mode import optdb
  from pytensor.configdefaults import config
  from pytensor.graph.features import ReplacementDidNotRemoveError, ReplaceValidate
  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
  from pytensor.tensor import basic
  from pytensor.tensor.blas import Dot22, _dot22, _dot22scalar, batched_dot, gemm_inplace, gemm_no_inplace, gemv_inplace, gemv_no_inplace, ger, ger_destructive
  from pytensor.tensor.elemwise import DimShuffle, Elemwise
  from pytensor.tensor.exceptions import NotScalarConstantError
  from pytensor.tensor.math import Dot, _matrix_matrix_matmul, add, mul, neg, sub
  from pytensor.tensor.rewriting.elemwise import local_dimshuffle_lift
  from pytensor.tensor.type import DenseTensorType, TensorType, integer_dtypes, values_eq_approx_remove_inf_nan
label_desc: Use image node_id 5 for calling a global function with example usage: _beta_L_plus_alpha_M(fgraph, beta, L, alpha, M, recurse_flip) and returns: rval,  M, _beta_L_plus_alpha_M, False,  False, rval,  MM, rval,  MM, rval,  MM