code: def sliding_window(t, window, smear=False):
      """Create a sliding window over a tensor.
  
      Args:
          t (np.ndarray): A tensor to create sliding window from,
              with shape :math:`(N, D)`, where N is the length of a trajectory,
              D is the dimension of each step in trajectory.
          window (int): Window size, mush be less than N.
          smear (bool): If true, copy the last window so that N windows are
              generated.
  
      Returns:
          np.ndarray: All windows generate over t, with shape :math:`(M, W, D)`,
              where W is the window size. If smear if False, M is :math:`N-W+1`,
              otherwise M is N.
  
      Raises:
          NotImplementedError: If step_size is not 1.
          ValueError: If window size is larger than the input tensor.
  
      """
      if window > t.shape[0]:
          raise ValueError("`window` must be <= `t.shape[0]`")
  
      if window == t.shape[0]:
          return np.stack([t] * window)
  
      # The stride trick works only on the last dimension of an ndarray, so we
      # operate on the transpose, which reverses the dimensions of t.
      t_T = t.T
  
      shape = t_T.shape[:-1] + (t_T.shape[-1] - window, window)
      strides = t_T.strides + (t_T.strides[-1],)
      t_T_win = np.lib.stride_tricks.as_strided(
          t_T, shape=shape, strides=strides
      )
  
      # t_T_win has shape (d_k, d_k-1, ..., (n - window_size), window_size)
      # To arrive at the final shape, we first transpose the result to arrive at
      # (window_size, (n - window_size), d_1, ..., d_k), then swap the firs two
      # axes
      t_win = np.swapaxes(t_T_win.T, 0, 1)
  
      # Optionally smear the last element to preserve the first dimension
      if smear:
          t_win = pad_tensor(t_win, t.shape[0], mode="last")
  
      return t_win
  
file_path: garage/src/garage/np/_functions.py
imports: import warnings
  import numpy
  import scipy.signal
label_desc: Use image node_id 3 for calling a global function with example usage: sliding_window(t, window, smear) and returns: t_win, np