code: def test_non_contiguous_input_states_handled(self):
      # Check that the encoder is robust to non-contiguous input states.
  
      # A transposition will make the tensors non-contiguous, start them off at the wrong shape
      # and transpose them into the right shape.
      encoder_base = _EncoderBase(stateful=False)
      initial_states = (
          torch.randn(5, 6, 7).permute(1, 0, 2),
          torch.randn(5, 6, 7).permute(1, 0, 2),
      )
      assert (
          not initial_states[0].is_contiguous()
          and not initial_states[1].is_contiguous()
      )
      assert initial_states[0].size() == torch.Size([6, 5, 7])
      assert initial_states[1].size() == torch.Size([6, 5, 7])
  
      # We'll pass them through an LSTM encoder and a vanilla RNN encoder to make sure it works
      # whether the initial states are a tuple of tensors or just a single tensor.
      encoder_base.sort_and_run_forward(
          self.lstm, self.tensor, self.mask, initial_states
      )
      encoder_base.sort_and_run_forward(
          self.rnn, self.tensor, self.mask, initial_states[0]
      )
  
file_path: magnitude/pymagnitude/third_party/allennlp/tests/modules/encoder_base_test.py
imports: from __future__ import absolute_import
  import numpy
  import torch
  from torch.nn import LSTM, RNN
  from allennlp.modules.encoder_base import _EncoderBase
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.nn.util import sort_batch_by_length, get_lengths_from_binary_sequence_mask
label_desc: Use image node_id 5 for calling the TestEncoderBase obj's underlying member method code with example usage: obj.test_non_contiguous_input_states_handled() without return types