code: def lagged_sequence_values(
      indices: List[int],
      prior_sequence: torch.Tensor,
      sequence: torch.Tensor,
      dim: int,
  ) -> torch.Tensor:
      """
      Constructs an array of lagged values from a given sequence.
  
      Parameters
      ----------
      indices
          Indices of the lagged observations. For example, ``[0]`` indicates
          that, at any time ``t``, the will have only the observation from
          time ``t`` itself; instead, ``[0, 24]`` indicates that the output
          will have observations from times ``t`` and ``t-24``.
      prior_sequence
          Tensor containing the input sequence prior to the time range for
          which the output is required.
      sequence
          Tensor containing the input sequence in the time range where the
          output is required.
      dim
          Time dimension.
  
      Returns
      -------
      Tensor
          A tensor of shape (*sequence.shape, len(indices)).
      """
      assert max(indices) <= prior_sequence.shape[dim], (
          f"lags cannot go further than prior sequence length, found lag"
          f" {max(indices)} while prior sequence is only"
          f" {prior_sequence.shape[dim]}-long"
      )
  
      full_sequence = torch.cat((prior_sequence, sequence), dim=dim)
  
      lags_values = []
      for lag_index in indices:
          begin_index = -lag_index - sequence.shape[dim]
          end_index = -lag_index if lag_index > 0 else None
          lags_values.append(
              slice_along_dim(
                  full_sequence,
                  dim=dim,
                  slice_=slice(begin_index, end_index),
              )
          )
  
      return torch.stack(lags_values, dim=-1)
  
file_path: gluonts/src/gluonts/torch/util.py
imports: from typing import List, Optional, Type, Union
  import inspect
  import torch
label_desc: Use image node_id 5 for calling a global function with example usage: lagged_sequence_values(indices, prior_sequence, sequence, dim) and returns: torch