class_docstr: Adder which adds entire episodes as trajectories.
class_docstr_tok: ["Adder","which","adds","entire","episodes","as","trajectories","."]
code: def _write_last(self):
      if (
          self._padding_fn is not None
          and self._writer.episode_steps < self._max_sequence_length
      ):
          history = self._writer.history
          padding_step = dict(
              observation=history["observation"],
              action=history["action"],
              reward=history["reward"],
              discount=history["discount"],
              extras=history.get("extras", ()),
          )
          # Get shapes and dtypes from the last element.
          padding_step = tree.map_structure(
              lambda col: self._padding_fn(
                  col[-1].shape, col[-1].dtype
              ),
              padding_step,
          )
          padding_step["start_of_episode"] = False
          while self._writer.episode_steps < self._max_sequence_length:
              self._writer.append(padding_step)
  
      trajectory = tree.map_structure(
          lambda x: x[:], self._writer.history
      )
  
      # Pack the history into a base.Step structure and get numpy converted
      # variant for priotiy computation.
      trajectory = base.Trajectory(**trajectory)
  
      # Calculate the priority for this episode.
      table_priorities = utils.calculate_priorities(
          self._priority_fns, trajectory
      )
  
      # Create a prioritized item for each table.
      for table_name, priority in table_priorities.items():
          self._writer.create_item(table_name, priority, trajectory)
          self._writer.flush(self._max_in_flight_items)
  
file_path: acme/acme/adders/reverb/episode.py
imports: from typing import Callable, Optional, Iterable, Tuple
  from acme import specs
  from acme import types
  from acme.adders.reverb import base
  from acme.adders.reverb import utils
  import dm_env
  import numpy
  import reverb
  import tensorflow
  import tree
label_desc: Use image node_id 4 for calling the EpisodeAdder obj's underlying member method code with example usage: obj._write_last() without return types