class_docstr: Conv + Transformer encoder
class_docstr_tok: ["Conv","+","Transformer","encoder"]
docstr: Reorder encoder output according to *new_order*.
  
  Args:
      encoder_out: output from the ``forward()`` method
      new_order (LongTensor): desired order
  
  Returns:
      *encoder_out* rearranged according to *new_order*
docstr_tok: ["Reorder","encoder","output","according","to","*","new_order","*",".","Args",":","encoder_out",":","output","from","the","``","forward","(",")","``","method","new_order","(","LongTensor",")",":","desired","order","Returns",":","*","encoder_out","*","rearranged","according","to","*","new_order","*"]
code: def reorder_encoder_out(
      self, encoder_out: Dict[str, List[Tensor]], new_order
  ):
      """
      Reorder encoder output according to *new_order*.
  
      Args:
          encoder_out: output from the ``forward()`` method
          new_order (LongTensor): desired order
  
      Returns:
          *encoder_out* rearranged according to *new_order*
      """
      new_encoder_out = [
          encoder_out["encoder_out"][0].index_select(1, new_order)
      ]
      if len(encoder_out["encoder_padding_mask"]) == 0:
          new_encoder_padding_mask = []
      else:
          new_encoder_padding_mask = [
              (encoder_out["encoder_padding_mask"][0]).index_select(
                  0, new_order
              )
          ]
      if len(encoder_out["encoder_embedding"]) == 0:
          new_encoder_embedding = []
      else:
          new_encoder_embedding = [
              (encoder_out["encoder_embedding"][0]).index_select(
                  0, new_order
              )
          ]
      encoder_states = encoder_out["encoder_states"]
      if len(encoder_states) > 0:
          for idx, state in enumerate(encoder_states):
              encoder_states[idx] = state.index_select(1, new_order)
  
      return {
          "encoder_out": new_encoder_out,
          "encoder_padding_mask": new_encoder_padding_mask,
          "encoder_embedding": new_encoder_embedding,
          "encoder_states": encoder_states,
          "src_tokens": [],
          "src_lengths": [],
      }
  
imports: import logging
  import math
  from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from torch import Tensor
  from fairseq import checkpoint_utils, utils
  from fairseq.data.data_utils import lengths_to_padding_mask
  from fairseq.models import FairseqEncoder, FairseqEncoderDecoderModel, register_model, register_model_architecture
  from fairseq.models.speech_to_text.modules.convolution import infer_conv_output_dim
  from fairseq.models.transformer import Embedding, TransformerDecoder
  from fairseq.modules import LayerNorm, PositionalEmbedding, TransformerEncoderLayer
label_desc: Use image node_id 4 for calling the ConvTransformerEncoder obj's underlying member method code with example usage: obj.reorder_encoder_out(encoder_out, new_order) and returns: dict