docstr: Construct 2D sin-cos positional embeddings.
  
  Args:
      w: width of the image or feature map
      h: height of the image or feature map
      embed_dim: embedding dimension
      temp: temperature coefficient
      device: device to place the positional embeddings
      dtype: data type of the positional embeddings
  
  Returns:
      positional embeddings, shape :math:`(H * W, 1, C)`
docstr_tok: ["Construct","2D","sin-cos","positional","embeddings",".","Args",":","w",":","width","of","the","image","or","feature","map","h",":","height","of","the","image","or","feature","map","embed_dim",":","embedding","dimension","temp",":","temperature","coefficient","device",":","device","to","place","the","positional","embeddings","dtype",":","data","type","of","the","positional","embeddings","Returns",":","positional","embeddings",",","shape",":","math",":","`","(","H","*","W",",","1",",","C",")","`"]
code: def build_2d_sincos_pos_emb(
      w: int,
      h: int,
      embed_dim: int,
      temp: float = 10_000.0,
      device: Optional[torch.device] = None,
      dtype: Optional[torch.dtype] = None,
  ) -> Tensor:
      """Construct 2D sin-cos positional embeddings.
  
      Args:
          w: width of the image or feature map
          h: height of the image or feature map
          embed_dim: embedding dimension
          temp: temperature coefficient
          device: device to place the positional embeddings
          dtype: data type of the positional embeddings
  
      Returns:
          positional embeddings, shape :math:`(H * W, 1, C)`
      """
      xs = torch.arange(w, device=device, dtype=dtype)
      ys = torch.arange(h, device=device, dtype=dtype)
      grid_x, grid_y = torch.meshgrid(xs, ys, indexing="ij")
  
      pos_dim = embed_dim // 4
      omega = (
          torch.arange(pos_dim, device=device, dtype=dtype) / pos_dim
      )
      omega = 1.0 / (temp**omega)
  
      out_x = grid_x.reshape(-1, 1) * omega.view(1, -1)
      out_y = grid_y.reshape(-1, 1) * omega.view(1, -1)
  
      pos_emb = concatenate(
          [out_x.sin(), out_x.cos(), out_y.sin(), out_y.cos()], 1
      )
      return pos_emb.unsqueeze(1)
  
imports: from __future__ import annotations
  from typing import Optional
  import torch
  import torch.nn.functional
  from torch import nn
  from torch.nn.utils.fusion import fuse_conv_bn_weights
  from kornia.contrib.models.common import ConvNormAct
  from kornia.core import Module, Tensor, concatenate, pad
label_desc: Use image node_id 4 for calling the AIFI obj's underlying member method code with example usage: obj.build_2d_sincos_pos_emb(w, h, embed_dim, temp, device, dtype) and returns: pos_emb