code: def _GetMatrixBandPartGradTest(dtype_, batch_shape_, shape_):
      @test_util.run_v1_only("b/120545219")
      def Test(self):
          shape = batch_shape_ + shape_
          x = constant_op.constant(np.random.rand(*shape), dtype=dtype_)
          with self.session(use_gpu=False):
              for lower in -1, 0, 1, shape_[-2] - 1:
                  for upper in -1, 0, 1, shape_[-1] - 1:
                      y = array_ops.matrix_band_part(x, lower, upper)
                      error = gradient_checker.compute_gradient_error(
                          x,
                          x.get_shape().as_list(),
                          y,
                          y.get_shape().as_list(),
                      )
                      self.assertLess(error, 1e-4)
  
      return Test
  
imports: import numpy
  from tensorflow.python.client import session
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import control_flow_ops
  from tensorflow.python.ops import gradient_checker
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import benchmark
  from tensorflow.python.platform import test
label_desc: Use image node_id 3 for calling a global function with example usage: _GetMatrixBandPartGradTest(dtype_, batch_shape_, shape_) and returns: Test