code: def create_sinusoidal_positions(
      num_positions: int, embedding_dim: int, padding_idx: Optional[int]
  ) -> tf.Tensor:
      half_dim = embedding_dim // 2
      emb = math.log(10000) / (half_dim - 1)
      emb = tf.exp(tf.range(half_dim, dtype=tf.float32) * -emb)
      emb = tf.expand_dims(
          tf.range(num_positions, dtype=tf.float32), axis=1
      ) * tf.expand_dims(emb, axis=0)
      emb = tf.reshape(
          tf.concat([tf.sin(emb), tf.cos(emb)], axis=1),
          (num_positions, -1),
      )
      if embedding_dim % 2 == 1:
          # zero pad
          emb = tf.concat([emb, tf.zeros((num_positions, 1))], axis=1)
      if padding_idx is not None:
          _padding_mask = tf.concat(
              [
                  tf.ones((padding_idx, shape_list(emb)[1])),
                  tf.zeros((1, shape_list(emb)[1])),
                  tf.ones(
                      (
                          shape_list(emb)[0] - padding_idx - 1,
                          shape_list(emb)[1],
                      )
                  ),
              ],
              axis=0,
          )
          emb *= _padding_mask
  
      return tf.constant(emb, name="embed_positions")
  
imports: from __future__ import annotations
  import math
  import random
  from typing import Any, Optional, Tuple, Union
  import numpy
  import tensorflow
  from ...activations_tf import get_tf_activation
  from ...file_utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, replace_return_docstrings
  from ...modeling_tf_outputs import TFBaseModelOutputWithPastAndCrossAttentions, TFCausalLMOutputWithCrossAttentions
  from ...modeling_tf_utils import TFCausalLanguageModelingLoss, TFModelInputType, TFPreTrainedModel, TFSharedEmbeddings, get_initializer, keras_serializable, unpack_inputs
  from ...tf_utils import check_embeddings_within_bounds, shape_list, stable_softmax
  from ...utils import logging
  from .configuration_xglm import XGLMConfig
label_desc: Use image node_id 1 for calling a global function with example usage: create_sinusoidal_positions(num_positions, embedding_dim, padding_idx) and returns: tf