class_docstr: Positional encoding using random spatial frequencies.
docstr: Generate positional encoding for a grid of the specified size.
docstr_tok: ["Generate","positional","encoding","for","a","grid","of","the","specified","size","."]
code: def forward(self, size: tuple[int, int]) -> Tensor:
      """Generate positional encoding for a grid of the specified size."""
      h, w = size
      _dev = self.positional_encoding_gaussian_matrix.device
      device = _dev if isinstance(_dev, torch.device) else None
      grid = torch.ones((h, w), device=device, dtype=torch.float32)
      y_embed = grid.cumsum(dim=0) - 0.5
      x_embed = grid.cumsum(dim=1) - 0.5
      y_embed = y_embed / h
      x_embed = x_embed / w
  
      pe = self._pe_encoding(stack([x_embed, y_embed], dim=-1))
      return pe.permute(2, 0, 1)
  
imports: from __future__ import annotations
  from math import pi
  from typing import Optional
  import torch
  from torch import nn
  from kornia.contrib.models.common import LayerNorm2d
  from kornia.core import Device, Module, Tensor, concatenate, cos, sin, stack, zeros
label_desc: Use image node_id 3 for calling the PositionEmbeddingRandom obj's underlying member method code with example usage: obj.forward(size) and returns: pe