code: def _updated_cashflow(
      num_times,
      exercise_index,
      exercise_value,
      expected_continuation,
      cashflow,
  ):
      """Revises the cashflow tensor where options will be exercised earlier."""
      do_exercise_bool = exercise_value > expected_continuation
      do_exercise = tf.cast(do_exercise_bool, exercise_value.dtype)
      # Shape [num_samples, payoff_dim]
      scaled_do_exercise = tf.where(
          do_exercise_bool,
          exercise_value,
          tf.zeros_like(exercise_value),
      )
      # This picks out the samples where we now wish to exercise.
      # Shape [num_samples, payoff_dim, 1]
      new_samp_masked = tf.expand_dims(scaled_do_exercise, 2)
      # This should be one on the current time step and zero otherwise.
      # This is an array with nonzero entries showing newly exercised payoffs.
      pad_shape = scaled_do_exercise.shape.as_list()
      zeros_before = tf.zeros(
          pad_shape + [exercise_index - 1],
          dtype=scaled_do_exercise.dtype,
      )
      zeros_after = tf.zeros(
          pad_shape + [num_times - exercise_index],
          dtype=scaled_do_exercise.dtype,
      )
      new_cash = tf.concat(
          [zeros_before, new_samp_masked, zeros_after], -1
      )
  
      # Has shape [num_samples, payoff_dim, 1]
      old_samp_masker = tf.expand_dims(1 - do_exercise, 2)
      # Broadcast to shape [num_samples, payoff_dim, num_times - exercise_index]
      old_samp_masker_after = tf.broadcast_to(
          old_samp_masker, pad_shape + [num_times - exercise_index]
      )
      # Has shape `[num_samples, payoff_dim, exercise_index]`
      zeros_before = tf.zeros(
          pad_shape + [exercise_index], dtype=scaled_do_exercise.dtype
      )
      # Shape [num_samples, payoff_dim, num_times]
      old_mask = tf.concat([zeros_before, old_samp_masker_after], -1)
      # Shape [num_samples, payoff_dim, num_times]
      old_cash = old_mask * cashflow
      return new_cash + old_cash
  
file_path: tf-quant-finance/tf_quant_finance/experimental/lsm_algorithm/lsm.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: unknown