code: def crop_or_pad_sequence(seq, length, allow_crop=True):
      """Crops or pads a sequence of scalars."""
      paddings = [[0, length - tf.shape(seq)[0]]] + [(0, 0)] * (
          len(seq.shape) - 1
      )
      if allow_crop:
          paddings = tf.maximum(paddings, 0)
      if seq.dtype == tf.string:
          padded = tf.pad(seq, paddings, constant_values="")
      elif seq.dtype == tf.bool:
          padded = tf.pad(seq, paddings, constant_values=False)
      else:
          padded = tf.pad(seq, paddings, constant_values=-1)
      if allow_crop:
          padded = padded[:length]
          padded.set_shape([length] + seq.shape[1:])
      return padded
  
file_path: scenic/scenic/projects/owl_vit/preprocessing/transforms.py
imports: from typing import Any, Optional, Sequence, Tuple, Union
  import tensorflow
label_desc: Use image node_id 8 for calling a global function with example usage: crop_or_pad_sequence(seq, length, allow_crop) and returns: padded