code: def test_lookuptable_rand_error(
      backend_default, basic_linargs, deltas_buffer
  ):
      nin, nout, batch_size, vocab_size = basic_linargs
      NervanaObject.be.bsz = batch_size
  
      dtypeu = np.float32
  
      init_glorot = GlorotUniform()
      layer = LookupTable(
          vocab_size=vocab_size, embedding_dim=nout, init=init_glorot
      )
  
      inp = np.random.random_integers(
          0, vocab_size - 1, size=nin * batch_size
      )
      layer.configure(nin)
      layer.allocate()
  
      layer.prev_layer = True  # Hack to force delta buffer allocation
      layer.allocate_deltas(deltas_buffer)
      deltas_buffer.allocate_buffers()
      layer.set_deltas(deltas_buffer)
  
      inputs = layer.be.array(inp.reshape((nin, batch_size)))
      out = layer.fprop(inputs).get()
      W = layer.W.get()
      for i in range(nin * batch_size):
          assert np.all(W[inp[i]].T == out[:, i])
  
      err = dtypeu(np.random.random((nout, nin * batch_size)))
      layer.bprop(layer.be.array(err)).get()
  
      dw = layer.dW.get()
      unqidx, count = np.unique(inp, return_counts=True)
      dw_exp = np.zeros((1, nout))
      for wrd_id, cnt in zip(unqidx, count):
          dw_exp[:] = 0
          cnt_exp = 0
          for i, w_id in enumerate(inp):
              if w_id == wrd_id:
                  dw_exp[:] = dw_exp[:] + err[:, i]
                  cnt_exp += 1
          assert allclose_with_out(
              dw[wrd_id, :], dw_exp, atol=0, rtol=1e-4
          )
          assert allclose_with_out(
              dw_exp, dw[wrd_id, :], atol=0, rtol=1e-4
          )
          assert cnt == cnt_exp
  
      return
  
file_path: neon/tests/test_lookuptable.py
imports: from builtins import zip
  import itertools
  import numpy
  from neon.backends import gen_backend
  from neon import NervanaObject
  from neon import logger
  from neon.initializers.initializer import GlorotUniform
  from neon.layers.layer import LookupTable
  from utils import allclose_with_out
label_desc: Use image node_id 4 for calling a global function with example usage: test_lookuptable_rand_error(backend_default, basic_linargs, deltas_buffer) without return types