class_docstr: This is a sinusoidal position encoding that generalized to 2-dimensional images.
docstr: Creates a position encoding from scratch.
  
  For 1/8 feature map (which is standard): If the input image size is H, W (both divisible by 8), the max_shape
  should be (H//8, W//8).
docstr_tok: ["Creates","a","position","encoding","from","scratch",".","For","1\/8","feature","map","(","which","is","standard",")",":","If","the","input","image","size","is","H",",","W","(","both","divisible","by","8",")",",","the","max_shape","should","be","(","H\/\/8",",","W\/\/8",")","."]
code: def _create_position_encoding(
      self, max_shape: Tuple[int, int]
  ) -> Tensor:
      """Creates a position encoding from scratch.
  
      For 1/8 feature map (which is standard): If the input image size is H, W (both divisible by 8), the max_shape
      should be (H//8, W//8).
      """
      pe = zeros((self.d_model, *max_shape))
      y_position = torch.ones(max_shape).cumsum(0).float().unsqueeze(0)
      x_position = torch.ones(max_shape).cumsum(1).float().unsqueeze(0)
      if self.temp_bug_fix:
          div_term = torch.exp(
              torch.arange(0, self.d_model // 2, 2).float()
              * (-math.log(10000.0) / (self.d_model // 2))
          )
      else:  # a buggy implementation (for backward compatibility only)
          div_term = torch.exp(
              torch.arange(0, self.d_model // 2, 2).float()
              * (-math.log(10000.0) / self.d_model // 2)
          )
      div_term = div_term[:, None, None]  # [C//4, 1, 1]
      pe[0::4, :, :] = sin(x_position * div_term)
      pe[1::4, :, :] = cos(x_position * div_term)
      pe[2::4, :, :] = sin(y_position * div_term)
      pe[3::4, :, :] = cos(y_position * div_term)
      return pe.unsqueeze(0)
  
file_path: kornia/kornia/feature/loftr/utils/position_encoding.py
imports: import math
  from typing import Tuple
  import torch
  from kornia.core import Module, Tensor, cos, sin, zeros
label_desc: Use image node_id 2 for calling the PositionEncodingSine obj's underlying member method code with example usage: obj._create_position_encoding(max_shape) and returns: pe