aboutsummaryrefslogtreecommitdiff
path: root/nerv/layer/elem_mul.lua
blob: f03649bdedf32db68b588e9cb37c178dede17113 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
local ElemMulLayer = nerv.class('nerv.ElemMulLayer', 'nerv.Layer')

function ElemMulLayer:__init(id, global_conf, layer_conf)
    nerv.Layer.__init(self, id, global_conf, layer_conf)
    -- element-wise multiplication of input[1] and input[2]
    self:check_dim_len(2, 1)
end

function ElemMulLayer:bind_params()
    -- do nothing
end

function ElemMulLayer:init(batch_size)
    if self.dim_in[1] ~= self.dim_in[2] or
        self.dim_in[1] ~= self.dim_out[1] then
        nerv.error("mismatching dimensions of input and output")
    end
end

function ElemMulLayer:batch_resize(batch_size)
    -- do nothing
end

function ElemMulLayer:propagate(input, output)
    output[1]:mul_elem(input[1], input[2])
end

function ElemMulLayer:back_propagate(bp_err, next_bp_err, input, output)
    next_bp_err[1]:mul_elem(bp_err[1], input[2])
    next_bp_err[2]:mul_elem(bp_err[1], input[1])
end

function ElemMulLayer:update(bp_err, input, output)
    -- do nothing
end

function ElemMulLayer:get_params()
    return nerv.ParamRepo({}, self.loc_type)
end