# Path: seya/utils.py
# def apply_layer(layer, X, train=False):
#     tmp = layer.get_input
#     layer.get_input = lambda _: X
#     Y = layer.get_output(train=train)
#     layer.get_input = tmp
#     return Y


import theano.tensor as T
from collections import OrderedDict
from theano import scan
from keras.layers.core import Layer, Merge
from keras.utils.theano_utils import ndim_tensor, alloc_zeros_matrix
from ..utils import apply_layer

    def _step(self, *args):
        # print('--- {}'.format(args))
        local_outputs = OrderedDict()
        for k, node in self.nodes.items():
            # print('This is node {}'.format(k))
            local_inputs = []
            for inp in node.input_names:
                # print('>>> input {}'.format(inp))
                if inp in self.input_order:
                    idx = self.input_order.index(inp)
                    local_inputs.append(args[idx])
                    # print('iii idx: {}'.format(idx))
                elif inp in local_outputs:
                    # print('??? output {}'.format(inp))
                    local_inputs.append(local_outputs[inp])
                elif inp in node.input_list:  # state input
                    idx = len(self.input_order) + self.state_order.index(inp)
                    # print('!!! state {0}, idx {1}'.format(inp, idx))
                    local_inputs.append(args[idx])
            local_inputs = [x for x in local_inputs if x != []]
            # print(local_inputs)
            if len(local_inputs) > 1:
                if node.merge_mode == 'concat':
                    inputs = T.concatenate(local_inputs, axis=-1)
                elif node.merge_mode == 'sum':
                    inputs = sum(local_inputs)
            else:
                inputs = local_inputs[0]
            # print('After concat {}'.format(inputs))

# Path: seya/utils.py
# def apply_layer(layer, X, train=False):
#     tmp = layer.get_input
#     layer.get_input = lambda _: X
#     Y = layer.get_output(train=train)
#     layer.get_input = tmp
#     return Y


# Path: seya/layers/containers.py
import theano.tensor as T
from collections import OrderedDict
from theano import scan
from keras.layers.core import Layer, Merge
from keras.utils.theano_utils import ndim_tensor, alloc_zeros_matrix
from ..utils import apply_layer


    def _step(self, *args):
        # print('--- {}'.format(args))
        local_outputs = OrderedDict()
        for k, node in self.nodes.items():
            # print('This is node {}'.format(k))
            local_inputs = []
            for inp in node.input_names:
                # print('>>> input {}'.format(inp))
                if inp in self.input_order:
                    idx = self.input_order.index(inp)
                    local_inputs.append(args[idx])
                    # print('iii idx: {}'.format(idx))
                elif inp in local_outputs:
                    # print('??? output {}'.format(inp))
                    local_inputs.append(local_outputs[inp])
                elif inp in node.input_list:  # state input
                    idx = len(self.input_order) + self.state_order.index(inp)
                    # print('!!! state {0}, idx {1}'.format(inp, idx))
                    local_inputs.append(args[idx])
            local_inputs = [x for x in local_inputs if x != []]
            # print(local_inputs)
            if len(local_inputs) > 1:
                if node.merge_mode == 'concat':
                    inputs = T.concatenate(local_inputs, axis=-1)
                elif node.merge_mode == 'sum':
                    inputs = sum(local_inputs)
            else:
                inputs = local_inputs[0]
            # print('After concat {}'.format(inputs))

            local_outputs[k] = apply_layer(node, inputs)