'Run this multi-layer cell on inputs, starting from state.'

def __call__(self, inputs, state, scope=None):

    if (not self._residual_connections):
        return super(ExtendedMultiRNNCell, self).__call__(inputs, state, (scope or u'extended_multi_rnn_cell'))
    with tf.variable_scope((scope or u'extended_multi_rnn_cell')):
        if ((self._cells[0].output_size != inputs.get_shape().as_list()[1]) and (self._residual_combiner in [u'add', u'mean'])):
            inputs = tf.contrib.layers.fully_connected(inputs=inputs, num_outputs=self._cells[0].output_size, activation_fn=None, scope=u'input_transform')
        cur_inp = inputs
        prev_inputs = [cur_inp]
        new_states = []
        for (i, cell) in enumerate(self._cells):
            with tf.variable_scope((u'cell_%d' % i)):
                if (not nest.is_sequence(state)):
                    raise ValueError((u'Expected    state    to    be    a    tuple    of    length    %d,    but    received:    %s' % (len(self.state_size), state)))
                cur_state = state[i]
                (next_input, new_state) = cell(cur_inp, cur_state)
                input_to_combine = prev_inputs[(-1):]
                if self._residual_dense:
                    input_to_combine = prev_inputs
                if (self._residual_combiner == u'add'):
                    next_input = (next_input + sum(input_to_combine))
                if (self._residual_combiner == u'mean'):
                    combined_mean = tf.reduce_mean(tf.stack(input_to_combine), 0)
                    next_input = (next_input + combined_mean)
                elif (self._residual_combiner == u'concat'):
                    next_input = tf.concat(([next_input] + input_to_combine), 1)
                cur_inp = next_input
                prev_inputs.append(cur_inp)
                new_states.append(new_state)
    new_states = (tuple(new_states) if self._state_is_tuple else array_ops.concat(new_states, 1))
    return (cur_inp, new_states)
