code: def _discount_reward_tensor_1d(
      reward, sequence_length, discount=1.0, dtype=None
  ):
      if sequence_length is None:
          raise ValueError(
              "sequence_length must not be `None` for 1D reward."
          )
  
      batch_size = tf.shape(reward)[0]
      max_seq_length = tf.reduce_max(sequence_length)
      dtype = dtype or reward.dtype
  
      if discount == 1.0:
          dmat = tf.ones(
              tf.concat([[batch_size], [max_seq_length]], 0),
              dtype=dtype,
          )
      else:
          mask = tf.sequence_mask(sequence_length, dtype=dtype)
          mask = tf.concat(
              [mask[:, 1:], tf.zeros_like(mask[:, -1:])], axis=1
          )
          # Make each row = [discount, ..., discount, 1, ..., 1]
          dmat = mask * discount + (1 - mask)
          dmat = tf.cumprod(dmat, axis=1, reverse=True)
  
      disc_reward = dmat * tf.expand_dims(reward, -1)
      disc_reward = mask_sequences(
          disc_reward, sequence_length, dtype=dtype, tensor_rank=2
      )
  
      return disc_reward
  
imports: import numpy
  import tensorflow
  from texar.tf.utils.shapes import mask_sequences
label_desc: Use image node_id 3 for calling a global function with example usage: _discount_reward_tensor_1d(reward, sequence_length, discount, dtype) and returns: disc_reward