code: def concatenate_recurrent_states(split_recurrent_states):
      """Concatenate recurrent states into a batch.
  
      This function can be used to make a batched recurrent state from separate
      recurrent states obtained via the `get_recurrent_state_at` function.
  
      Args:
          split_recurrent_states (Sequence): Recurrent states to concatenate.
  
      Returns:
          object: Batched recurrent_state.
      """
      if all(s is None for s in split_recurrent_states):
          return None
      else:
          non_none_s = next(
              s for s in split_recurrent_states if s is not None
          )
          if isinstance(non_none_s, torch.Tensor):
              new_ss = [
                  s if s is not None else torch.zeros_like(non_none_s)
                  for s in split_recurrent_states
              ]
              return torch.stack(new_ss, dim=1)
          elif isinstance(non_none_s, np.ndarray):
              new_ss = [
                  s if s is not None else np.zeros_like(non_none_s)
                  for s in split_recurrent_states
              ]
              return np.stack(new_ss, axis=1)
          elif isinstance(non_none_s, tuple):
              return tuple(
                  concatenate_recurrent_states(
                      [
                          s[i] if s is not None else None
                          for s in split_recurrent_states
                      ]
                  )
                  for i in range(len(non_none_s))
              )
          else:
              raise ValueError(
                  "Invalid recurrent state: {}".format(non_none_s)
              )
  
file_path: pfrl/pfrl/utils/recurrent.py
imports: import itertools
  import numpy
  import torch
  from torch import nn
label_desc: Use image node_id 4 for calling a global function with example usage: concatenate_recurrent_states(split_recurrent_states) and returns: None, torch, np, tuple