class_docstr: RotaryRelativePositionBias module definition.
  
  Args:
      size: Module embedding size.
      max_positions: Maximum number of relative positions.
class_docstr_tok: ["RotaryRelativePositionBias","module","definition",".","Args",":","size",":","Module","embedding","size",".","max_positions",":","Maximum","number","of","relative","positions","."]
docstr: Compute rotary positional embeddings.
  
  Args:
      x: Input sequence. (L, size)
  
  Returns:
      x: Rotary positional embeddings.  (L, size)
docstr_tok: ["Compute","rotary","positional","embeddings",".","Args",":","x",":","Input","sequence",".","(","L",",","size",")","Returns",":","x",":","Rotary","positional","embeddings",".","(","L",",","size",")"]
code: def rotary(self, x: torch.Tensor) -> torch.Tensor:
      """Compute rotary positional embeddings.
  
      Args:
          x: Input sequence. (L, size)
  
      Returns:
          x: Rotary positional embeddings.  (L, size)
  
      """
      length, dim = x.size()
  
      x1, x2 = torch.chunk(x, 2, dim=-1)
  
      if self.sine is None or length > self.sine.size(0):
          (
              self.sine,
              self.cosine,
          ) = RotaryRelativePositionBias.get_sinusoid_embeddings(
              length, dim
          )
  
          self.max_positions = length
  
      self.sine = self.sine.to(self._pe)
      self.cosine = self.cosine.to(self._pe)
  
      sin = self.sine[:length]
      cos = self.cosine[:length]
  
      x = torch.cat([x1 * cos - x2 * sin, x2 * cos + x1 * sin], dim=1)
  
      return x
  
file_path: espnet/espnet2/asr_transducer/decoder/modules/mega/positional_bias.py
imports: import math
  from typing import Tuple
  import torch
label_desc: Use image node_id 4 for calling the RotaryRelativePositionBias obj's underlying member method code with example usage: obj.rotary(x) and returns: x