# 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 theano import scan
from keras.layers.recurrent import Recurrent
from keras import activations, initializations, regularizers, constraints
from keras.utils.theano_utils import shared_zeros
from ..utils import apply_layer
            self.W_regularizer.set_param(self.W)
            self.regularizers.append(self.W_regularizer)

        self.b_regularizer = regularizers.get(b_regularizer)
        if self.b_regularizer:
            self.b_regularizer.set_param(self.b)
            self.regularizers.append(self.b_regularizer)

        self.activity_regularizer = regularizers.get(activity_regularizer)
        if self.activity_regularizer:
            self.activity_regularizer.set_layer(self)
            self.regularizers.append(self.activity_regularizer)

        self.W_constraint = constraints.get(W_constraint)
        self.b_constraint = constraints.get(b_constraint)
        self.constraints = [self.W_constraint, self.b_constraint]

        if weights is not None:
            self.set_weights(weights)

        if name is not None:
            self.set_name(name)

    def set_name(self, name):
        self.W.name = '%s_W' % name
        self.C.name = '%s_C' % name

    def _step(self, Wx_t, s_tm1, u_tm1, C, b, *args):
        uWx = (u_tm1[:, :, None] * Wx_t).sum(axis=1)  # shape: batch/output_dim
        s_t = self.activation(uWx + T.dot(s_tm1, C) + b)

# 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/tensor.py
import theano.tensor as T
from theano import scan
from keras.layers.recurrent import Recurrent
from keras import activations, initializations, regularizers, constraints
from keras.utils.theano_utils import shared_zeros
from ..utils import apply_layer

            self.W_regularizer.set_param(self.W)
            self.regularizers.append(self.W_regularizer)

        self.b_regularizer = regularizers.get(b_regularizer)
        if self.b_regularizer:
            self.b_regularizer.set_param(self.b)
            self.regularizers.append(self.b_regularizer)

        self.activity_regularizer = regularizers.get(activity_regularizer)
        if self.activity_regularizer:
            self.activity_regularizer.set_layer(self)
            self.regularizers.append(self.activity_regularizer)

        self.W_constraint = constraints.get(W_constraint)
        self.b_constraint = constraints.get(b_constraint)
        self.constraints = [self.W_constraint, self.b_constraint]

        if weights is not None:
            self.set_weights(weights)

        if name is not None:
            self.set_name(name)

    def set_name(self, name):
        self.W.name = '%s_W' % name
        self.C.name = '%s_C' % name

    def _step(self, Wx_t, s_tm1, u_tm1, C, b, *args):
        uWx = (u_tm1[:, :, None] * Wx_t).sum(axis=1)  # shape: batch/output_dim
        s_t = self.activation(uWx + T.dot(s_tm1, C) + b)

        u_t = apply_layer(self.hid2output, s_t)