code: def test_local_gpu_subtensor():
      # Test shared forced on CPU.
      t = tensor._shared(np.zeros(20, "float32"))
      f = theano.function([], t[3:4], mode=mode_with_gpu)
      topo = f.maker.fgraph.toposort()
      assert any([type(node.op) is tensor.Subtensor for node in topo])
      assert not any(
          [isinstance(node.op, GpuSubtensor) for node in topo]
      )
      assert _check_stack_trace(f)
  
      # Test graph input.
      t = tensor.fmatrix()
      f = theano.function([t], t[3:4], mode=mode_with_gpu)
      topo = f.maker.fgraph.toposort()
      assert any([type(node.op) is tensor.Subtensor for node in topo])
      assert not any(
          [isinstance(node.op, GpuSubtensor) for node in topo]
      )
      assert _check_stack_trace(f)
  
      # Test multiple use of the input
      # We want the subtensor to be on the GPU to prevent multiple transfer.
      t = tensor.fmatrix()
      f = theano.function([t], [t[3:4], t + 1], mode=mode_with_gpu)
      topo = f.maker.fgraph.toposort()
      assert not any(
          [type(node.op) is tensor.Subtensor for node in topo]
      )
      assert any([isinstance(node.op, GpuSubtensor) for node in topo])
      assert _check_stack_trace(f)
  
      # Test multiple use of the input + input as output
      # We want the subtensor to be on the GPU to prevent multiple transfer.
      t = tensor.fmatrix()
      f = theano.function([t], [t[3:4], t + 1, t], mode=mode_with_gpu)
      topo = f.maker.fgraph.toposort()
      assert not any(
          [type(node.op) is tensor.Subtensor for node in topo]
      )
      assert any([isinstance(node.op, GpuSubtensor) for node in topo])
      assert _check_stack_trace(f)
  
      # Test shared forced on CPU end we do computation on the output of
      # the subtensor.
      t = tensor._shared(np.zeros(20, "float32"))
      f = theano.function([], t[3:4] + 1, mode=mode_with_gpu)
      topo = f.maker.fgraph.toposort()
      assert any([type(node.op) is tensor.Subtensor for node in topo])
      assert not any(
          [isinstance(node.op, GpuSubtensor) for node in topo]
      )
      # Our optimizer isn't smart enough to move to the GPU Elemwise.
      # If it where just a little bit smarter, it could wrongly move it to the GPU.
      # If it where super smart, it would know it should not move it to the GPU.
      assert any(
          [isinstance(node.op, tensor.Elemwise) for node in topo]
      )
      assert _check_stack_trace(f)
  
imports: from __future__ import absolute_import, print_function, division
  from nose.tools import assert_raises
  import numpy
  import theano
  from theano import tensor
  import theano.tensor.slinalg
  from theano.tests.breakpoint import PdbBreakpoint
  from theano.tests import unittest_tools, test_ifelse
  from theano.tensor.tests import test_basic
  from theano.gof.opt import check_stack_trace
  import theano.gpuarray
  from ..None import basic_ops
  from ..type import GpuArrayType, gpuarray_shared_constructor, get_context
  from ..basic_ops import GpuAlloc, GpuAllocEmpty, GpuReshape, GpuFromHost, HostFromGpu, host_from_gpu
  from ..blas import GpuGemm
  from ..elemwise import GpuCAReduceCuda, GpuCAReduceCPY, GpuElemwise, Elemwise, max_inputs_to_GpuElemwise
  from ..dnn import GpuDnnReduction
  from ..subtensor import GpuSubtensor
  from ..linalg import GpuCusolverSolve, cusolver_available, GpuCholesky
  from .config import mode_with_gpu, mode_without_gpu, test_ctx_name, SkipTest
  import unittest
  from theano.tensor.nnet import abstract_conv
  from theano.gpuarray import dnn, blas, opt
label_desc: Use image node_id 15 for calling a global function with example usage: test_local_gpu_subtensor() without return types