def _luong_local_compute_attention(attention_mechanism, cell_output, attention_state, attention_layer):
    'Computes the attention and alignments for the Luong style local attention mechanism.'
    (alignments, next_attention_state) = attention_mechanism(cell_output, state=attention_state)
    expanded_alignments = tf.expand_dims(alignments, 1)
    context_windows = []
    padded_alignment_windows = []
    window_start = attention_mechanism.window_start
    window_stop = attention_mechanism.window_stop
    pre_padding = attention_mechanism.window_pre_padding
    post_padding = attention_mechanism.window_post_padding
    full_pre_padding = attention_mechanism.full_seq_pre_padding
    full_post_padding = attention_mechanism.full_seq_post_padding
    for i in range(0, attention_mechanism.const_batch_size):
        value_window = attention_mechanism.values[i, window_start[i][0]:window_stop[i][0], :]
        value_window_paddings = [[pre_padding[i][0], post_padding[i][0]], [0, 0]]
        value_window = tf.pad(value_window, value_window_paddings, 'CONSTANT')
        value_window.set_shape((attention_mechanism.window_size, attention_mechanism._num_units))
        context_window = tf.matmul(expanded_alignments[i], value_window)
        context_windows.append(context_window)
        if (attention_mechanism.force_gaussian is True):
            point_dist = (tf.cast(tf.range(start=window_start[i][0], limit=window_stop[i][0], delta=1), dtype=tf.float32) - attention_mechanism.p[i][0])
            gaussian_weights = tf.exp((((- (point_dist ** 2)) / 2) * ((attention_mechanism.d / 2) ** 2)))
            __alignments = (alignments[i] * gaussian_weights)
        else:
            __alignments = alignments[i]
        alignment_seq_paddings = [[full_pre_padding[i][0], full_post_padding[i][0]]]
        __alignments = tf.pad(__alignments, alignment_seq_paddings, 'CONSTANT')
        padded_alignment_windows.append(__alignments)
    context = tf.stack(context_windows)
    context = tf.squeeze(context, [1])
    padded_alignment = tf.stack(padded_alignment_windows)
    if (attention_layer is not None):
        attention = attention_layer(tf.concat([cell_output, context], 1))
    else:
        attention = context
    return (attention, padded_alignment, padded_alignment)
Computes the attention and alignments for the Luong style local attention mechanism.
def _luong_local_compute_attention(attention_mechanism, cell_output, attention_state, attention_layer):
    
    (alignments, next_attention_state) = attention_mechanism(cell_output, state=attention_state)
    expanded_alignments = tf.expand_dims(alignments, 1)
    context_windows = []
    padded_alignment_windows = []
    window_start = attention_mechanism.window_start
    window_stop = attention_mechanism.window_stop
    pre_padding = attention_mechanism.window_pre_padding
    post_padding = attention_mechanism.window_post_padding
    full_pre_padding = attention_mechanism.full_seq_pre_padding
    full_post_padding = attention_mechanism.full_seq_post_padding
    for i in range(0, attention_mechanism.const_batch_size):
        value_window = attention_mechanism.values[i, window_start[i][0]:window_stop[i][0], :]
        value_window_paddings = [[pre_padding[i][0], post_padding[i][0]], [0, 0]]
        value_window = tf.pad(value_window, value_window_paddings, 'CONSTANT')
        value_window.set_shape((attention_mechanism.window_size, attention_mechanism._num_units))
        context_window = tf.matmul(expanded_alignments[i], value_window)
        context_windows.append(context_window)
        if (attention_mechanism.force_gaussian is True):
            point_dist = (tf.cast(tf.range(start=window_start[i][0], limit=window_stop[i][0], delta=1), dtype=tf.float32) - attention_mechanism.p[i][0])
            gaussian_weights = tf.exp((((- (point_dist ** 2)) / 2) * ((attention_mechanism.d / 2) ** 2)))
            __alignments = (alignments[i] * gaussian_weights)
        else:
            __alignments = alignments[i]
        alignment_seq_paddings = [[full_pre_padding[i][0], full_post_padding[i][0]]]
        __alignments = tf.pad(__alignments, alignment_seq_paddings, 'CONSTANT')
        padded_alignment_windows.append(__alignments)
    context = tf.stack(context_windows)
    context = tf.squeeze(context, [1])
    padded_alignment = tf.stack(padded_alignment_windows)
    if (attention_layer is not None):
        attention = attention_layer(tf.concat([cell_output, context], 1))
    else:
        attention = context
    return (attention, padded_alignment, padded_alignment)