class_docstr: Tests reward related functions.
      
docstr: Tests :func:`texar.tf.losses.rewards.discount_reward`
          
code: def test_discount_reward(self):
      """Tests :func:`texar.tf.losses.rewards.discount_reward`"""
      # 1D
      reward = np.ones([2], dtype=np.float64)
      sequence_length = [3, 5]
  
      discounted_reward = discount_reward(
          reward, sequence_length, discount=1.0
      )
      discounted_reward_n = discount_reward(
          reward, sequence_length, discount=0.1, normalize=True
      )
  
      discounted_reward_ = discount_reward(
          tf.constant(reward, dtype=tf.float64),
          sequence_length,
          discount=1.0,
      )
      discounted_reward_n_ = discount_reward(
          tf.constant(reward, dtype=tf.float64),
          sequence_length,
          discount=0.1,
          normalize=True,
      )
  
      with self.test_session() as sess:
          sess.run(tf.global_variables_initializer())
  
          r, r_n = sess.run([discounted_reward_, discounted_reward_n_])
  
          np.testing.assert_array_almost_equal(
              discounted_reward, r, decimal=6
          )
          np.testing.assert_array_almost_equal(
              discounted_reward_n, r_n, decimal=6
          )
  
      # 2D
      reward = np.ones([2, 10], dtype=np.float64)
      sequence_length = [5, 10]
  
      discounted_reward = discount_reward(
          reward, sequence_length, discount=1.0
      )
      discounted_reward_n = discount_reward(
          reward, sequence_length, discount=0.1, normalize=True
      )
  
      discounted_reward_ = discount_reward(
          tf.constant(reward, dtype=tf.float64),
          sequence_length,
          discount=1.0,
          tensor_rank=2,
      )
      discounted_reward_n_ = discount_reward(
          tf.constant(reward, dtype=tf.float64),
          sequence_length,
          discount=0.1,
          tensor_rank=2,
          normalize=True,
      )
  
      with self.test_session() as sess:
          sess.run(tf.global_variables_initializer())
  
          r, r_n = sess.run([discounted_reward_, discounted_reward_n_])
  
          np.testing.assert_array_almost_equal(
              discounted_reward, r, decimal=6
          )
          np.testing.assert_array_almost_equal(
              discounted_reward_n, r_n, decimal=6
          )
  
file_path: texar/tests/losses/rewards_test.py
imports: import numpy
  import tensorflow
  from texar.tf.losses.rewards import _discount_reward_tensor_2d, _discount_reward_tensor_1d, _discount_reward_py_1d, _discount_reward_py_2d, discount_reward
label_desc: Use image node_id 1 for calling the RewardTest obj's underlying member method code with example usage: obj.test_discount_reward() without return types