code: def gen_backend_tensors(
      backends, tensor_dims, flags=None, dtype=np.float32
  ):
      """
      Generates random number for all backends.
  
      Arguments:
          backends (list): List of backends, one of (np, NervanaGPU, NervanaCPU, NervanaMKL)
          tensor_dims (list): List of dimensions of the tensors, for example
                              [(1, 2), (3, 4), (5, 6)]
          dtype (data-type): One of (np.float16, np.float32), must be the same
                             as backend.dtype if backend is one of the nervana
                             backends
          flags (list or str): If list is provided, specifies the flag for each
                               tensor. If str is provided, will be applied to all
                               tensors. Flags is one of the following:
                               ('zeros', 'pos_ones', 'neg_ones', 'pos_rand',
                                'neg_rand', 'rand', None)
  
      Returns:
          List of lists of tensors, corresponding to the backends.
          For example:
          [[np.ndarray, np.ndarray, np.ndarray],
           [GPUTensor, GPUTensor, GPUTensor],
           [CPUTensor, CPUTensor, CPUTensor],
           [MKLTensor, MKLTensor, MKLTensor]]
      """
  
      tensor_num = len(tensor_dims)
      if flags is not None:
          assert len(flags) == tensor_num
  
      # init
      backend_tensors = [[] for i in range(tensor_num)]
  
      # generate
      idx = 0
      for tensor_dim, flag in zip(tensor_dims, flags):
          assert flag in (
              "zeros",
              "pos_ones",
              "neg_ones",
              "pos_rand",
              "neg_rand",
              "rand",
              None,
          )
  
          # numpy standard value
          if flag == "zeros":
              tensor = np.zeros(tensor_dim)
          elif flag == "pos_ones":
              tensor = np.ones(tensor_dim)
          elif flag == "neg_ones":
              tensor = -np.ones(tensor_dim)
          elif flag == "pos_rand":
              tensor = np.random.rand(*tensor_dim)
          elif flag == "neg_rand":
              tensor = -np.random.rand(*tensor_dim)
          elif flag == "rand" or flag is None:
              tensor = -np.random.randn(*tensor_dim)
          else:
              raise NotImplementedError
          tensor = tensor.astype(dtype)
  
          # copy to different backends
          for backend, tensors in zip(backends, backend_tensors):
              if backend == np:
                  tensors.append(tensor)
              else:
                  assert backend.default_dtype == dtype
                  tensors.append(
                      backend.array(tensor, name="x%s" % idx)
                  )
          idx += 1
  
      return backend_tensors
  
file_path: neon/tests/utils.py
imports: from builtins import zip
  import numpy
  import numpy.random
  from neon import logger
  from neon.backends.backend import Tensor
label_desc: Use image node_id 7 for calling a global function with example usage: gen_backend_tensors(backends, tensor_dims, flags, dtype) and returns: backend_tensors