class_docstr: Sinusoidal positional encoding for non-recurrent neural networks.
  Implementation based on "Attention Is All You Need"
  Args:
     channels (int): embedding size
     dropout (float): dropout parameter
class_docstr_tok: ["Sinusoidal","positional","encoding","for","non-recurrent","neural","networks",".","Implementation","based","on","``","Attention","Is","All","You","Need","''","Args",":","channels","(","int",")",":","embedding","size","dropout","(","float",")",":","dropout","parameter"]
docstr: Shapes:
      x: [B, C, T]
      mask: [B, 1, T]
      first_idx: int
      last_idx: int
docstr_tok: ["Shapes",":","x",":","[","B",",","C",",","T","]","mask",":","[","B",",","1",",","T","]","first_idx",":","int","last_idx",":","int"]
code: def forward(self, x, mask=None, first_idx=None, last_idx=None):
      """
      Shapes:
          x: [B, C, T]
          mask: [B, 1, T]
          first_idx: int
          last_idx: int
      """
  
      x = x * math.sqrt(self.channels)
      if first_idx is None:
          if self.pe.size(2) < x.size(2):
              raise RuntimeError(
                  f"Sequence is {x.size(2)} but PositionalEncoding is"
                  f" limited to {self.pe.size(2)}. See max_len argument."
              )
          if mask is not None:
              pos_enc = self.pe[:, :, : x.size(2)] * mask
          else:
              pos_enc = self.pe[:, :, : x.size(2)]
          x = x + pos_enc
      else:
          x = x + self.pe[:, :, first_idx:last_idx]
      if hasattr(self, "dropout"):
          x = self.dropout(x)
      return x
  
imports: import math
  import torch
  from torch import nn
  from TTS.tts.layers.glow_tts.transformer import RelativePositionTransformer
  from TTS.tts.layers.generic.res_conv_bn import ResidualConv1dBNBlock
label_desc: Use image node_id 2 for calling the PositionalEncoding obj's underlying member method code with example usage: obj.forward(x, mask, first_idx, last_idx) and returns: x