code: def test_positional_encoding(self):
      model = PositionalEncoding(self.feature_dim, self.seq_len)
      output = model(self.fake_input)
      delta = output - self.fake_input
  
      pe = torch.zeros(
          self.seq_len, self.feature_dim, dtype=torch.float
      )
      position = torch.arange(
          0, self.seq_len, dtype=torch.float
      ).unsqueeze(1)
      div_term = torch.exp(
          torch.arange(0, self.feature_dim, 2).float()
          * (-math.log(10000.0) / self.feature_dim)
      )
      pe[:, 0::2] = torch.sin(position * div_term)
      pe[:, 1::2] = torch.cos(position * div_term)
  
      for n in range(0, self.batch_size):
          self.assertTrue(torch.allclose(delta[n], pe, atol=1e-6))
  
file_path: pytorchvideo/tests/test_layers_positional_encoding.py
imports: import itertools
  import math
  import unittest
  import torch
  from pytorchvideo.layers import PositionalEncoding, SpatioTemporalClsPositionalEncoding
label_desc: Use image node_id 2 for calling the TestPositionalEncoding obj's underlying member method code with example usage: obj.test_positional_encoding() without return types