code: def test_bucket_positional_embedding(
      units, num_buckets, bidirectional, max_distance
  ):
      embed = BucketPositionalEmbedding(
          units=units,
          bidirectional=bidirectional,
          num_buckets=num_buckets,
          max_distance=max_distance,
      )
      embed.initialize()
      relative_positions1 = mx.np.random.randint(
          -10000, 10000, (128, 25), dtype=np.int32
      )
      relative_positions2 = mx.np.random.randint(
          -10, 10, (128, 25), dtype=np.int32
      )
      relative_positions = mx.np.concatenate(
          [relative_positions1, relative_positions2], axis=-1
      )
      buckets = relative_position_bucket(
          relative_positions,
          bidirectional=bidirectional,
          num_buckets=num_buckets,
          max_distance=max_distance,
      )
      out = embed(relative_positions)
      for i in range(num_buckets):
          cnt = (buckets == i).sum().asnumpy()
          if cnt > 1:
              assert_allclose(
                  mx.np.linalg.norm(
                      out[buckets == i].std(axis=0)
                  ).asnumpy(),
                  0,
                  1e-5,
                  1e-5,
              )
      if bidirectional:
          assert mx.np.all(
              buckets[relative_positions > 0] >= num_buckets // 2
          ).asnumpy()
      out_of_bound_cnt = buckets[
          relative_positions > max_distance
      ].sum()
      if out_of_bound_cnt.asnumpy() > 0:
          assert (
              buckets[relative_positions > max_distance].std().asnumpy()
              == 0
          )
  
file_path: gluon-nlp/tests/test_layers.py
imports: import pytest
  import numpy
  from numpy.testing import assert_allclose
  import mxnet
  from gluonnlp.layers import PositionalEmbedding, SinusoidalPositionalEmbedding, LearnedPositionalEmbedding, BucketPositionalEmbedding, AdaptiveEmbedding, ProjectedAdaptiveLogSoftmaxWithLoss, get_activation, get_norm_layer
  from gluonnlp.op import relative_position_bucket
label_desc: Use image node_id 6 for calling a global function with example usage: test_bucket_positional_embedding(units, num_buckets, bidirectional, max_distance) without return types