Concatenate.prepare()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
dl 0
loc 2
rs 10
c 2
b 0
f 0
1
import theano.tensor as T
2
from . import NeuralLayer
3
4
5
class Concatenate(NeuralLayer):
6
    """
7
    Concatenate two tensors.
8
    They should have identical dimensions except the last one.
9
    """
10
11
    def __init__(self, axis=-1):
12
        """
13
        :type layer1: NeuralLayer
14
        :type layer2: NeuralLayer
15
        """
16
        super(Concatenate, self).__init__("concate")
17
        self.axis = axis
18
19
    def prepare(self):
20
        self.output_dim = sum(self.input_dims)
21
22
    def compute_tensor(self, *xs):
23
        if self.axis == -1:
24
            axis = xs[0].ndim - 1
25
        else:
26
            axis = self.axis
27
        return T.concatenate(xs, axis=axis)