code: def positional_encoding_2d(
      condition_vector: int, height: int, width: int
  ) -> Tensor:
      """Creates embedding to store relative position of the feature vector using sine and cosine functions.
  
      Args:
          condition_vector (int): Length of the condition vector
          height (int): H of the positions
          width (int): W of the positions
  
      Raises:
          ValueError: Cannot generate encoding with conditional vector length not as multiple of 4
  
      Returns:
          Tensor: condition_vector x HEIGHT x WIDTH position matrix
      """
      if condition_vector % 4 != 0:
          raise ValueError(
              f"Cannot use sin/cos positional encoding with odd dimension (got dim={condition_vector})"
          )
      pos_encoding = torch.zeros(condition_vector, height, width)
      # Each dimension use half of condition_vector
      condition_vector = condition_vector // 2
      div_term = torch.exp(
          torch.arange(0.0, condition_vector, 2)
          * -(math.log(1e4) / condition_vector)
      )
      pos_w = torch.arange(0.0, width).unsqueeze(1)
      pos_h = torch.arange(0.0, height).unsqueeze(1)
      pos_encoding[0:condition_vector:2, :, :] = (
          torch.sin(pos_w * div_term)
          .transpose(0, 1)
          .unsqueeze(1)
          .repeat(1, height, 1)
      )
      pos_encoding[1:condition_vector:2, :, :] = (
          torch.cos(pos_w * div_term)
          .transpose(0, 1)
          .unsqueeze(1)
          .repeat(1, height, 1)
      )
      pos_encoding[condition_vector::2, :, :] = (
          torch.sin(pos_h * div_term)
          .transpose(0, 1)
          .unsqueeze(2)
          .repeat(1, 1, width)
      )
      pos_encoding[condition_vector + 1 :: 2, :, :] = (
          torch.cos(pos_h * div_term)
          .transpose(0, 1)
          .unsqueeze(2)
          .repeat(1, 1, width)
      )
      return pos_encoding
  
file_path: anomalib/src/anomalib/models/cflow/utils.py
imports: from __future__ import annotations
  import logging
  import math
  import numpy
  import torch
  from FrEIA.framework import SequenceINN
  from torch import Tensor, nn
  from anomalib.models.components.flow import AllInOneBlock
label_desc: Use image node_id 2 for calling a global function with example usage: positional_encoding_2d(condition_vector, height, width) and returns: pos_encoding