class_docstr: Tests :class:`~texar.tf.modules.decoders.rnn_decoders.AttentionRNNDecoder`.
      
docstr: Tests :meth:`texar.tf.modules.AttentionRNNDecoder._get_beam_search_cell`
          
docstr_tok: ["Tests",":","meth",":","`","texar.tf.modules.AttentionRNNDecoder._get_beam_search_cell","`"]
code: def test_beam_search_cell(self):
      """Tests :meth:`texar.tf.modules.AttentionRNNDecoder._get_beam_search_cell`"""
      seq_length = (
          np.random.randint(self._max_time, size=[self._batch_size]) + 1
      )
      encoder_values_length = tf.constant(seq_length)
      hparams = {
          "attention": {
              "kwargs": {
                  "num_units": self._attention_dim,
                  "probability_fn": "sparsemax",
              }
          }
      }
      decoder = AttentionRNNDecoder(
          memory=self._encoder_output,
          memory_sequence_length=encoder_values_length,
          vocab_size=self._vocab_size,
          hparams=hparams,
      )
  
      helper_train = get_helper(
          decoder.hparams.helper_train.type,
          inputs=self._inputs,
          sequence_length=[self._max_time] * self._batch_size,
          **decoder.hparams.helper_train.kwargs.todict(),
      )
  
      _, _, _ = decoder(helper=helper_train)
  
      # 4+1 trainable variables: cell-kernel, cell-bias,
      # fc-weight, fc-bias, and
      # memory_layer: For LuongAttention, we only transform the memory layer;
      # thus num_units *must* match the expected query depth.
      self.assertEqual(len(decoder.trainable_variables), 5)
  
      beam_width = 3
      beam_cell = decoder._get_beam_search_cell(beam_width)
      cell_input = tf.random_uniform(
          [self._batch_size * beam_width, self._emb_dim]
      )
      cell_state = beam_cell.zero_state(
          self._batch_size * beam_width, tf.float32
      )
      _ = beam_cell(cell_input, cell_state)
      # Test if beam_cell is sharing variables with decoder cell.
      for tvar in beam_cell.trainable_variables:
          self.assertTrue(tvar in decoder.trainable_variables)
  
imports: import numpy
  import tensorflow
  from texar.tf.modules.decoders.rnn_decoders import BasicRNNDecoderOutput
  from texar.tf.modules.decoders.rnn_decoders import BasicRNNDecoder
  from texar.tf.modules.decoders.rnn_decoders import AttentionRNNDecoderOutput
  from texar.tf.modules.decoders.rnn_decoders import AttentionRNNDecoder
  from texar.tf.modules.decoders.rnn_decoder_helpers import get_helper
  from texar.tf import context
label_desc: Use image node_id 4 for calling the AttentionRNNDecoderTest obj's underlying member method code with example usage: obj.test_beam_search_cell() without return types