code: def _map_variables_inner(
      replacer, inner_inputs, outer_inputs, inner_outputs, containing_op
  ):
      # the replacements returned by the replacer may involve variables
      # that are already owned by the outer fgraph (`fg` in the caller)
      # and so cannot be added to the inner fgraph (`fg` in the
      # recursive call).  wrap the replacer to catch these before they
      # are added.
  
      # additionally, some of these may be fgraph inputs or shared
      # variables, which we cannot directly use inside the inner graph.
      # we need to create inner inputs to access them through.
  
      outer_to_inner = dict(zip(outer_inputs, inner_inputs))
      extra_inner_inputs = []
      extra_outer_inputs = []
  
      from theano.scan_module import scan_utils
      from itertools import chain
      from theano import gof
  
      def inner_replacer(graph):
          new_graph = replacer(graph)
  
          other_inputs = []
          constants = []
          for input_ in gof.graph.inputs([new_graph]):
              if isinstance(input_, gof.Variable):
                  if isinstance(input_, gof.Constant):
                      constants.append(input_)
                  else:
                      other_inputs.append(input_)
  
          # foreign inputs are fgraph inputs and shared variables that we need
          # to access through inner inputs
          foreign_inputs = list(
              set(other_inputs) - set(outer_to_inner.values())
          )
  
          # skip further processing if there is nothing to do
          if not constants and not foreign_inputs:
              return new_graph
  
          replacements = []
  
          # constants just need to be replaced by copies that the inner
          # `fg` can take ownership of
          for input_ in constants:
              new_input = input_.clone()
              new_input.name = "%s_copied" % new_input.name
              replacements.append((input_, new_input))
  
          for outer_input in foreign_inputs:
              if getattr(outer_input, "update", False):
                  # when theano.scan() constructs a scan node, it detects
                  # shared variables with updates and returns these updates
                  # to the user.  we need to do the same thing for every new
                  # use of such a variable that is introduced.  it's hard to
                  # do that at this point.
                  # shared variables with updates inside the inner graph of
                  # OpFromGraph are not supported at all, so we don't support
                  # introducing those either.
                  raise NotImplementedError(
                      "Replacement introduces shared variable %s "
                      "which has an update associated with it into "
                      "the inner graph of %s. This is not currently "
                      "supported." % (outer_input, containing_op)
                  )
              # if this foreign input is not already available
              # as an inner input, connect it through a new
              # inner input
              if outer_input not in outer_to_inner.keys():
                  inner_input = scan_utils.safe_new(
                      outer_input, tag="_copy"
                  )
                  outer_to_inner[outer_input] = inner_input
                  extra_inner_inputs.append(inner_input)
                  extra_outer_inputs.append(outer_input)
                  # the inner FunctionGraph wants to know its inputs
                  # beforehand, but we don't always know.  so add them
                  # as we discover them.
                  graph.owner.fgraph.add_input(inner_input)
  
          replacements.extend(outer_to_inner.items())
  
          (new_graph,) = theano.clone(
              [new_graph], share_inputs=True, replace=replacements
          )
          return new_graph
  
      new_inner_outputs = map_variables(inner_replacer, inner_outputs)
      new_inner_inputs = list(chain(inner_inputs, extra_inner_inputs))
      new_outer_inputs = list(chain(outer_inputs, extra_outer_inputs))
  
      return new_inner_inputs, new_outer_inputs, new_inner_outputs
  
imports: from __future__ import absolute_import, print_function, division
  import copy
  import logging
  import warnings
  from collections import OrderedDict
  import numpy
  import theano
  from theano.compat import izip
  from six import string_types, iteritems
  from six.moves import xrange
  from theano.compile.pfunc import rebuild_collect_shared
  from theano import gof, compat
  from theano import tensor, scalar
  from theano.tensor.basic import get_scalar_constant_value
label_desc: Use image node_id 6 for calling a global function with example usage: _map_variables_inner(replacer, inner_inputs, outer_inputs, inner_outputs, containing_op) and returns: new_inner_inputs,  new_outer_inputs,  new_inner_outputs, new_graph, new_graph