class_docstr: The positional encoding scheme from the `"Attention Is All You Need"
  <https://arxiv.org/pdf/1706.03762.pdf>`_ paper.
  
  .. math::
  
      PE(x)_{2 \cdot i} &= \sin(x / 10000^{2 \cdot i / d})
  
      PE(x)_{2 \cdot i + 1} &= \cos(x / 10000^{2 \cdot i / d})
  
  where :math:`x` is the position and :math:`i` is the dimension.
  
  Args:
      out_channels (int): Size :math:`d` of each output sample.
      base_freq (float, optional): The base frequency of sinusoidal
          functions. (default: :obj:`1e-4`)
      granularity (float, optional): The granularity of the positions. If
          set to smaller value, the encoder will capture more fine-grained
          changes in positions. (default: :obj:`1.0`)
class_docstr_tok: ["The","positional","encoding","scheme","from","the","`","``","Attention","Is","All","You","Need","''","<","https",":","\/\/arxiv.org\/pdf\/1706.03762.pdf",">","`","_","paper",".","..","math",":",":","PE","(","x",")","_","{","2","\\cdot","i","}","&","=","\\sin","(","x","\/","10000^","{","2","\\cdot","i","\/","d","}",")","PE","(","x",")","_","{","2","\\cdot","i","+","1","}","&","=","\\cos","(","x","\/","10000^","{","2","\\cdot","i","\/","d","}",")","where",":","math",":","`","x","`","is","the","position","and",":","math",":","`","i","`","is","the","dimension",".","Args",":","out_channels","(","int",")",":","Size",":","math",":","`","d","`","of","each","output","sample",".","base_freq","(","float",",","optional",")",":","The","base","frequency","of","sinusoidal","functions",".","(","default",":",":","obj",":","`","1e-4","`",")","granularity","(","float",",","optional",")",":","The","granularity","of","the","positions",".","If","set","to","smaller","value",",","the","encoder","will","capture","more","fine-grained","changes","in","positions",".","(","default",":",":","obj",":","`","1.0","`",")"]
code: def forward(self, x: Tensor) -> Tensor:
      """"""  # noqa: D419
      x = x / self.granularity if self.granularity != 1.0 else x
      out = x.view(-1, 1) * self.frequency.view(1, -1)
      return torch.cat([torch.sin(out), torch.cos(out)], dim=-1)
  
file_path: pytorch_geometric/torch_geometric/nn/encoding.py
imports: import math
  import torch
  from torch import Tensor
label_desc: Use image node_id 3 for calling the PositionalEncoding obj's underlying member method code with example usage: obj.forward(x) and returns: torch