class_docstr: BeamSearchDecoderMixin contains the common methods for
  BeamSearchDecoder.
  
  It is expected to be used a base class for concrete
  BeamSearchDecoder. Since this is a mixin class, it is expected to be
  used together with other class as base.
docstr: Maybe sorts beams within a `TensorArray`.
  
  Args:
    t: A `TensorArray` of size `max_time` that contains `Tensor`s of
      shape `[batch_size, beam_width, s]` or
      `[batch_size * beam_width, s]` where `s` is the depth shape.
    parent_ids: The parent ids of shape
      `[max_time, batch_size, beam_width]`.
    sequence_length: The sequence length of shape
      `[batch_size, beam_width]`.
  
  Returns:
    A `TensorArray` where beams are sorted in each `Tensor` or `t` itself
      if it is not a `TensorArray` or does not meet shape requirements.
docstr_tok: ["Maybe","sorts","beams","within","a","`","TensorArray","`",".","Args",":","t",":","A","`","TensorArray","`","of","size","`","max_time","`","that","contains","`","Tensor","`","s","of","shape","`","[","batch_size",",","beam_width",",","s","]","`","or","`","[","batch_size","*","beam_width",",","s","]","`","where","`","s","`","is","the","depth","shape",".","parent_ids",":","The","parent","ids","of","shape","`","[","max_time",",","batch_size",",","beam_width","]","`",".","sequence_length",":","The","sequence","length","of","shape","`","[","batch_size",",","beam_width","]","`",".","Returns",":","A","`","TensorArray","`","where","beams","are","sorted","in","each","`","Tensor","`","or","`","t","`","itself","if","it","is","not","a","`","TensorArray","`","or","does","not","meet","shape","requirements","."]
code: def _maybe_sort_array_beams(self, t, parent_ids, sequence_length):
      """Maybe sorts beams within a `TensorArray`.
  
      Args:
        t: A `TensorArray` of size `max_time` that contains `Tensor`s of
          shape `[batch_size, beam_width, s]` or
          `[batch_size * beam_width, s]` where `s` is the depth shape.
        parent_ids: The parent ids of shape
          `[max_time, batch_size, beam_width]`.
        sequence_length: The sequence length of shape
          `[batch_size, beam_width]`.
  
      Returns:
        A `TensorArray` where beams are sorted in each `Tensor` or `t` itself
          if it is not a `TensorArray` or does not meet shape requirements.
      """
      if not isinstance(t, tf.TensorArray):
          return t
      if t.element_shape.ndims is None or t.element_shape.ndims < 1:
          tf.get_logger().warn(
              "The TensorArray %s in the cell state is not amenable to "
              "sorting based on the beam search result. For a "
              "TensorArray to be sorted, its elements shape must be "
              "defined and have at least a rank of 1, but saw shape: %s"
              % (t.handle.name, t.element_shape)
          )
          return t
      if not _check_static_batch_beam_maybe(
          t.element_shape,
          tf.get_static_value(self._batch_size),
          self._beam_width,
      ):
          return t
      t = t.stack()
      with tf.control_dependencies(
          [_check_batch_beam(t, self._batch_size, self._beam_width)]
      ):
          return gather_tree_from_array(t, parent_ids, sequence_length)
  
imports: import collections
  import numpy
  import tensorflow
  from tensorflow_addons import options
  from tensorflow_addons.seq2seq import attention_wrapper
  from tensorflow_addons.seq2seq import decoder
  from tensorflow_addons.utils import keras_utils
  from tensorflow_addons.utils.resource_loader import LazySO
  from tensorflow_addons.utils.types import FloatTensorLike, TensorLike, Number
  from typeguard import typechecked
  from typing import Callable, Optional
label_desc: Use image node_id 11 for calling the BeamSearchDecoderMixin obj's underlying member method code with example usage: obj._maybe_sort_array_beams(t, parent_ids, sequence_length) and returns: t, t, t, gather_tree_from_array