code: def sparse_grad(var):
      """This function return a new variable whose gradient will be
      stored in a sparse format instead of dense.
  
      Currently only variable created by AdvancedSubtensor1 is supported.
      i.e. a_tensor_var[an_int_vector].
  
      .. versionadded:: 0.6rc4
      """
      assert isinstance(var.owner.op, tensor.AdvancedSubtensor1)
      ret = var.owner.op.__class__(sparse_grad=True)(*var.owner.inputs)
      return ret
  
imports: from __future__ import absolute_import, print_function, division
  import logging
  import os
  import sys
  import warnings
  from theano.version import version
  from six import PY3
  from theano.configdefaults import config
  from theano.configparser import change_flags
  from theano.gof import CLinker, OpWiseCLinker, DualLinker, Linker, LocalLinker, PerformLinker, Container, InconsistencyError, FunctionGraph, Apply, Variable, Constant, Op, OpenMPOp, opt, toolbox, Type, Generic, generic, object2, utils
  from theano.compile import SymbolicInput, In, SymbolicOutput, Out, Mode, predefined_modes, predefined_linkers, predefined_optimizers, FunctionMaker, function, function_dump, OpFromGraph, ProfileStats, Param, shared, as_op
  from theano.misc.safe_asarray import _asarray
  from theano.printing import pprint, pp
  from theano.scan_module import scan, map, reduce, foldl, foldr, clone, scan_checkpoints
  from theano.updates import OrderedUpdates
  from theano.gradient import Rop, Lop, grad, subgraph_grad
  import theano.tests
  import numpy
label_desc: Use image node_id 5 for calling a global function with example usage: sparse_grad(var) and returns: ret