code: def test_scan(self):
      x = tensor.vector("x")
  
      # we will insert a subgraph involving these variables into the inner
      # graph of scan. since they were not previously in the inner graph,
      # they are like non_sequences to scan(). scan() infers these and
      # imports them into the inner graph properly, and map_variables()
      # should do this as well.
      outer = tensor.scalar("outer")
      shared = theano.shared(
          np.array(1.0, dtype=theano.config.floatX), name="shared"
      )
      constant = tensor.constant(1, name="constant")
  
      # z will equal 1 so multiplying by it doesn't change any values
      z = outer * (shared + constant)
  
      def step(x, a):
          r = a + x
          r.tag.replacement = z * (a - x)
          return r
  
      s, _ = theano.scan(
          step, sequences=x, outputs_info=[np.array(0.0)]
      )
      # ensure z is owned by the outer graph so map_variables() will need to
      # jump through additional hoops to placate FunctionGraph.
      t = z * s
      (s2,) = map_variables(self.replacer, [t])
      t2 = z * s2
  
      f = theano.function([x, outer], [t, t2])
      rval = f(x=np.array([1, 2, 3], dtype=np.float32), outer=0.5)
      assert np.array_equal(rval, [[1, 3, 6], [-1, -3, -6]])
  
file_path: Theano/theano/scan_module/tests/test_scan_utils.py
imports: from __future__ import absolute_import, print_function, division
  import itertools
  import unittest
  import numpy
  import theano
  from theano import tensor
  from theano.scan_module.scan_utils import equal_computations, map_variables
  from theano.tensor.type_other import NoneConst
label_desc: Use image node_id 4 for calling the TestMapVariables obj's underlying member method code with example usage: obj.test_scan() and returns: r