code: def _batch_reset_recurrent_states_when_episodes_end(
      model, batch_done, batch_reset, recurrent_states
  ):
      """Reset recurrent states when episodes end.
  
      Args:
          model (chainer.Link): Model that implements `StatelessRecurrent`.
          batch_done (array-like of bool): True iff episodes are terminal.
          batch_reset (array-like of bool): True iff episodes will be reset.
          recurrent_states (object): Recurrent state.
  
      Returns:
          object: New recurrent states.
      """
      indices_that_ended = [
          i
          for i, (done, reset) in enumerate(
              zip(batch_done, batch_reset)
          )
          if done or reset
      ]
      if indices_that_ended:
          return model.mask_recurrent_state_at(
              recurrent_states, indices_that_ended
          )
      else:
          return recurrent_states
  
imports: import copy
  from logging import getLogger
  import chainer
  from chainer import cuda
  import chainer.functions
  from chainerrl import agent
  from chainerrl.misc.batch_states import batch_states
  from chainerrl.misc.copy_param import synchronize_parameters
  from chainerrl.replay_buffer import batch_experiences
  from chainerrl.replay_buffer import batch_recurrent_experiences
  from chainerrl.replay_buffer import ReplayUpdater
label_desc: Use image node_id 3 for calling a global function with example usage: _batch_reset_recurrent_states_when_episodes_end(model, batch_done, batch_reset, recurrent_states) and returns: model, recurrent_states