code: def test_positional_embeddings():
      num_embed = 32
      max_seq_len = 10
      scale_up_input = False
      scale_down_positions = False
      data_len = 5
      data = pt.zeros(2, data_len, num_embed)
  
      # fixed embeddings
      expected_fixed_embedding = (
          sockeye.layers.get_positional_embeddings(data_len, num_embed)
      )
      b = sockeye.layers.PositionalEmbeddings(
          weight_type="fixed",
          num_embed=num_embed,
          max_seq_len=max_seq_len,
          scale_up_input=scale_up_input,
          scale_down_positions=scale_down_positions,
      )
      # no steps
      out = b(data, None)
      pt.testing.assert_close(out[0], expected_fixed_embedding)
      pt.testing.assert_close(out[1], expected_fixed_embedding)
  
      # steps
      steps = pt.tensor([2, 3, 1, 1, 1]).unsqueeze(0)
      out = b(data, steps)
      pt.testing.assert_close(out[0, 0], expected_fixed_embedding[2])
      pt.testing.assert_close(out[1, 0], expected_fixed_embedding[2])
      pt.testing.assert_close(out[0, 1], expected_fixed_embedding[3])
      pt.testing.assert_close(out[1, 1], expected_fixed_embedding[3])
      pt.testing.assert_close(out[0, 2], expected_fixed_embedding[1])
      pt.testing.assert_close(out[1, 2], expected_fixed_embedding[1])
  
      # learned embeddings
      b = sockeye.layers.PositionalEmbeddings(
          weight_type="learned",
          num_embed=num_embed,
          max_seq_len=max_seq_len,
          scale_up_input=scale_up_input,
          scale_down_positions=scale_down_positions,
      )
      pt.nn.init.constant_(b.weight, val=1.0)
      expected_learned_embeddings = pt.ones(data_len, num_embed)
      out = b(data, None)
      pt.testing.assert_close(out[0], expected_learned_embeddings)
  
file_path: sockeye/test/unit/test_layers.py
imports: from math import pow, sqrt
  import numpy
  import pytest
  import torch
  import sockeye.constants
  import sockeye.layers
  import sockeye.transformer
  from sockeye.knn import KNNConfig, FaissIndexBuilder
label_desc: Use image node_id 3 for calling a global function with example usage: test_positional_embeddings() without return types