code: def _updated_cashflow(
      num_times,
      exercise_index,
      exercise_value,
      expected_continuation,
      cashflow,
  ):
      """Revises the cashflow tensor where options will be exercised earlier."""
      # Shape [num_samples, batch_size]
      do_exercise_bool = exercise_value > expected_continuation
      # Shape [num_samples, batch_size]
      scaled_do_exercise = tf.where(do_exercise_bool, exercise_value, 0)
      # This picks out the samples where we now wish to exercise.
      # Shape [num_samples, batch_size, 1]
      new_samp_masked = tf.expand_dims(scaled_do_exercise, axis=2)
      # This is an array with nonzero entries showing newly exercised payoffs.
      # Has shape [num_samples, batch_size, 1]
      cashflow_update = tf.where(
          tf.expand_dims(do_exercise_bool, axis=-1),
          tf.constant(0, dtype=cashflow.dtype),
          cashflow,
      )
      new_mask = tf.range(0, num_times) >= exercise_index
      # Shape [num_samples, batch_size, num_times]
      return tf.where(new_mask, cashflow_update, new_samp_masked)
  
file_path: tf-quant-finance/tf_quant_finance/experimental/lsm_algorithm/lsm_v2.py
imports: import collections
  import tensorflow.compat.v2
label_desc: Use image node_id 6 for calling a global function with example usage: _updated_cashflow(num_times, exercise_index, exercise_value, expected_continuation, cashflow) and returns: tf