code: def checkBatchGradient():
      """check that the batch gradient is correct"""
  
      # lets gradient check this beast
      n, b, d = (5, 3, 4)  # sequence length, batch size, hidden size
      input_size = 10
      WLSTM = LSTM.init(input_size, d)  # input size, hidden size
      X = np.random.randn(n, b, input_size)
      h0 = np.random.randn(b, d)
      c0 = np.random.randn(b, d)
  
      # batch forward backward
      H, Ct, Ht, cache = LSTM.forward(X, WLSTM, c0, h0)
      wrand = np.random.randn(*H.shape)
      # loss = np.sum(H * wrand)  # weighted sum is a nice hash to use I think
      dH = wrand
      dX, dWLSTM, dc0, dh0 = LSTM.backward(dH, cache)
  
      def fwd():
          h, _, _, _ = LSTM.forward(X, WLSTM, c0, h0)
          return np.sum(h * wrand)
  
      # now gradient check all
      delta = 1e-5
      rel_error_thr_warning = 1e-2
      rel_error_thr_error = 1
      tocheck = [X, WLSTM, c0, h0]
      grads_analytic = [dX, dWLSTM, dc0, dh0]
      names = ["X", "WLSTM", "c0", "h0"]
      for j in range(len(tocheck)):
          mat = tocheck[j]
          dmat = grads_analytic[j]
          name = names[j]
          # gradcheck
          for i in range(mat.size):
              old_val = mat.flat[i]
              mat.flat[i] = old_val + delta
              loss0 = fwd()
              mat.flat[i] = old_val - delta
              loss1 = fwd()
              mat.flat[i] = old_val
  
              grad_analytic = dmat.flat[i]
              grad_numerical = (loss0 - loss1) / float(2 * delta)
  
              if grad_numerical == 0 and grad_analytic == 0:
                  rel_error = 0  # both are zero, OK.
                  status = "OK"
              elif (
                  abs(grad_numerical) < 1e-7
                  and abs(grad_analytic) < 1e-7
              ):
                  rel_error = 0  # not enough precision to check this
                  status = "VAL SMALL WARNING"
              else:
                  rel_error = abs(grad_analytic - grad_numerical) / abs(
                      float(grad_numerical + grad_analytic)
                  )
                  status = "OK"
                  if rel_error > rel_error_thr_warning:
                      status = "WARNING"
                  if rel_error > rel_error_thr_error:
                      status = "!!!!! NOTOK"
  
              # print stats
              neon_logger.display(
                  "%s checking param %s index %s (val = %+8f), analytic = %+8f,"
                  + "numerical = %+8f, relative error = %+8f"
                  % (
                      status,
                      name,
                      repr(np.unravel_index(i, mat.shape)),
                      old_val,
                      grad_analytic,
                      grad_numerical,
                      rel_error,
                  )
              )
  
file_path: neon/tests/lstm_ref.py
imports: from builtins import input
  import numpy
  from neon import logger
  from utils import allclose_with_out
label_desc: Use image node_id 2 for calling a global function with example usage: checkBatchGradient() and returns: np