code: def test_compute_new_states_with_no_action_constraints(self):
      # pylint: disable=protected-access
      # This test is basically identical to the previous one, but without specifying
      # `allowed_actions`.  This makes sure we get the right behavior at test time.
      log_probs = torch.FloatTensor(
          [
              [0.1, 0.9, -0.1, 0.2],
              [0.3, 1.1, 0.1, 0.8],
              [0.1, 0.25, 0.3, 0.4],
          ]
      )
      considered_actions = [[0, 1, 2, 3], [0, -1, 3, -1], [0, 2, 4, -1]]
      max_actions = 1
      step_action_embeddings = torch.FloatTensor(
          [
              [[1, 1], [9, 9], [2, 2], [3, 3]],
              [[4, 4], [9, 9], [3, 3], [9, 9]],
              [[1, 1], [2, 2], [5, 5], [9, 9]],
          ]
      )
      new_hidden_state = torch.FloatTensor(
          [[i + 1, i + 1] for i in range(len(considered_actions))]
      )
      new_memory_cell = torch.FloatTensor(
          [[i + 1, i + 1] for i in range(len(considered_actions))]
      )
      new_attended_question = torch.FloatTensor(
          [[i + 1, i + 1] for i in range(len(considered_actions))]
      )
      new_attention_weights = torch.FloatTensor(
          [[i + 1, i + 1] for i in range(len(considered_actions))]
      )
      new_states = WikiTablesDecoderStep._compute_new_states(
          self.state,
          log_probs,
          new_hidden_state,
          new_memory_cell,
          step_action_embeddings,
          new_attended_question,
          new_attention_weights,
          considered_actions,
          allowed_actions=None,
          max_actions=max_actions,
      )
  
      assert len(new_states) == 2
      new_state = new_states[0]
      # For batch instance 0, we should have selected action 1 from group index 0.
      assert new_state.batch_indices == [0]
      assert_almost_equal(
          new_state.score[0].detach().cpu().numpy().tolist(), [0.9]
      )
      # These two have values taken from what's defined in setUp() - the prior action history
      # ([1]) and the nonterminals corresponding to the action we picked ('j').
      assert new_state.action_history == [[1, 1]]
      assert new_state.grammar_state[0]._nonterminal_stack == ["g"]
      # All of these values come from the objects instantiated directly above.
      assert_almost_equal(
          new_state.rnn_state[0].hidden_state.cpu().numpy().tolist(),
          [1, 1],
      )
      assert_almost_equal(
          new_state.rnn_state[0].memory_cell.cpu().numpy().tolist(),
          [1, 1],
      )
      assert_almost_equal(
          new_state.rnn_state[0]
          .previous_action_embedding.cpu()
          .numpy()
          .tolist(),
          [9, 9],
      )
      assert_almost_equal(
          new_state.rnn_state[0].attended_input.cpu().numpy().tolist(),
          [1, 1],
      )
      # And these should just be copied from the prior state.
      assert_almost_equal(
          new_state.rnn_state[0].encoder_outputs.cpu().numpy(),
          self.encoder_outputs.cpu().numpy(),
      )
      assert_almost_equal(
          new_state.rnn_state[0]
          .encoder_output_mask.detach()
          .cpu()
          .numpy(),
          self.encoder_output_mask.detach().cpu().numpy(),
      )
      assert_almost_equal(
          new_state.action_embeddings.cpu().numpy(),
          self.action_embeddings.cpu().numpy(),
      )
      assert new_state.action_indices == self.action_indices
      assert new_state.possible_actions == self.possible_actions
  
      new_state = new_states[1]
      # For batch instance 0, we should have selected action 0 from group index 1.
      assert new_state.batch_indices == [1]
      assert_almost_equal(
          new_state.score[0].detach().cpu().numpy().tolist(), [0.3]
      )
      # These have values taken from what's defined in setUp() - the prior action history
      # ([3, 4]) and the nonterminals corresponding to the action we picked ('q').
      assert new_state.action_history == [[3, 4, 0]]
      assert new_state.grammar_state[0]._nonterminal_stack == ["q"]
      # All of these values come from the objects instantiated directly above.
      assert_almost_equal(
          new_state.rnn_state[0].hidden_state.cpu().numpy().tolist(),
          [2, 2],
      )
      assert_almost_equal(
          new_state.rnn_state[0].memory_cell.cpu().numpy().tolist(),
          [2, 2],
      )
      assert_almost_equal(
          new_state.rnn_state[0]
          .previous_action_embedding.cpu()
          .numpy()
          .tolist(),
          [4, 4],
      )
      assert_almost_equal(
          new_state.rnn_state[0].attended_input.cpu().numpy().tolist(),
          [2, 2],
      )
      # And these should just be copied from the prior state.
      assert_almost_equal(
          new_state.rnn_state[0].encoder_outputs.cpu().numpy(),
          self.encoder_outputs.cpu().numpy(),
      )
      assert_almost_equal(
          new_state.rnn_state[0]
          .encoder_output_mask.detach()
          .cpu()
          .numpy(),
          self.encoder_output_mask.detach().cpu().numpy(),
      )
      assert_almost_equal(
          new_state.action_embeddings.cpu().numpy(),
          self.action_embeddings.cpu().numpy(),
      )
      assert new_state.action_indices == self.action_indices
      assert new_state.possible_actions == self.possible_actions
  
file_path: magnitude/pymagnitude/third_party/allennlp/tests/models/semantic_parsing/wikitables/wikitables_decoder_step_test.py
imports: from __future__ import absolute_import
  from numpy.testing import assert_almost_equal
  import torch
  from allennlp.common import Params
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.models.semantic_parsing.wikitables.wikitables_decoder_state import WikiTablesDecoderState
  from allennlp.models.semantic_parsing.wikitables.wikitables_decoder_step import WikiTablesDecoderStep
  from allennlp.modules import SimilarityFunction
  from allennlp.nn.decoding import GrammarState, RnnState
  from allennlp.semparse.type_declarations.type_declaration import is_nonterminal
label_desc: Use image node_id 7 for calling the WikiTablesDecoderStepTest obj's underlying member method code with example usage: obj.test_compute_new_states_with_no_action_constraints() without return types