class_docstr: This module produces sinusoidal positional embeddings of any length.
class_docstr_tok: ["This","module","produces","sinusoidal","positional","embeddings","of","any","length","."]
docstr: Features are not interleaved. The cos features are in the 2nd half of the vector. [dim // 2:]
docstr_tok: ["Features","are","not","interleaved",".","The","cos","features","are","in","the","2nd","half","of","the","vector",".","[","dim","\/\/","2",":","]"]
code: def _init_weight(out: torch.Tensor) -> torch.Tensor:
      """
      Features are not interleaved. The cos features are in the 2nd half of the vector. [dim // 2:]
      """
      n_pos, dim = out.shape
      position_enc = np.array(
          [
              [
                  pos / np.power(10000, 2 * (j // 2) / dim)
                  for j in range(dim)
              ]
              for pos in range(n_pos)
          ]
      )
      # set early to avoid an error in pytorch-1.8+
      out.requires_grad = False
  
      sentinel = dim // 2 if dim % 2 == 0 else (dim // 2) + 1
      out[:, 0:sentinel] = torch.FloatTensor(
          np.sin(position_enc[:, 0::2])
      )
      out[:, sentinel:] = torch.FloatTensor(
          np.cos(position_enc[:, 1::2])
      )
      out.detach_()
      return out
  
imports: from typing import Tuple
  import numpy
  import torch
  from torch import nn
  from gluonts.core.component import validated
  from gluonts.model import Input, InputSpec
  from gluonts.torch.distributions import StudentTOutput
  from gluonts.torch.scaler import StdScaler, MeanScaler, NOPScaler
  from gluonts.torch.util import unsqueeze_expand, weighted_average
  from gluonts.torch.model.simple_feedforward import make_linear_layer
label_desc: Use image node_id 2 for calling the SinusoidalPositionalEmbedding obj's underlying member method code with example usage: obj._init_weight(out) and returns: out