class_docstr: RelPositionMultiHeadedAttention definition.
  
  Args:
      num_heads: Number of attention heads.
      embed_size: Embedding size.
      dropout_rate: Dropout rate.
docstr: Compute relative positional encoding.
  
  Args:
      x: Input sequence. (B, H, T_1, 2 * T_1 - 1)
      left_context: Number of previous frames to use for current chunk
                    attention computation.
  
  Returns:
      x: Output sequence. (B, H, T_1, T_2)
code: def rel_shift(
      self, x: torch.Tensor, left_context: int = 0
  ) -> torch.Tensor:
      """Compute relative positional encoding.
  
      Args:
          x: Input sequence. (B, H, T_1, 2 * T_1 - 1)
          left_context: Number of previous frames to use for current chunk
                        attention computation.
  
      Returns:
          x: Output sequence. (B, H, T_1, T_2)
  
      """
      batch_size, n_heads, time1, n = x.shape
      time2 = time1 + left_context
  
      batch_stride, n_heads_stride, time1_stride, n_stride = x.stride()
  
      return x.as_strided(
          (batch_size, n_heads, time1, time2),
          (
              batch_stride,
              n_heads_stride,
              time1_stride - n_stride,
              n_stride,
          ),
          storage_offset=(n_stride * (time1 - 1)),
      )
  
file_path: espnet/espnet2/asr_transducer/encoder/modules/attention.py
imports: import math
  from typing import Optional, Tuple
  import torch
label_desc: Use image node_id 2 for calling the RelPositionMultiHeadedAttention obj's underlying member method code with example usage: obj.rel_shift(x, left_context) and returns: x