diff options
author | txh18 <cloudygooseg@gmail.com> | 2015-11-17 13:20:43 +0800 |
---|---|---|
committer | txh18 <cloudygooseg@gmail.com> | 2015-11-17 13:20:43 +0800 |
commit | 317ff51cae8dcfaff26855c42ce99656b4d293b5 (patch) | |
tree | 67f779bcffa9bace5e080329ae427796e785302d /nerv/examples/lmptb/rnn/tnn.lua | |
parent | bd563c1ebcd676059e0384532ab192d98b3eabf2 (diff) |
added small opt: use mmatrix in lm_trainer and reader
Diffstat (limited to 'nerv/examples/lmptb/rnn/tnn.lua')
-rw-r--r-- | nerv/examples/lmptb/rnn/tnn.lua | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/nerv/examples/lmptb/rnn/tnn.lua b/nerv/examples/lmptb/rnn/tnn.lua index d10ab82..c2e397c 100644 --- a/nerv/examples/lmptb/rnn/tnn.lua +++ b/nerv/examples/lmptb/rnn/tnn.lua @@ -291,11 +291,21 @@ function TNN:getfeed_from_reader(reader) return got_new, feeds_now end -function TNN:move_right_to_nextmb() --move output history activations of 1..chunk_size to 1-chunk_size..0 - for t = 1, self.chunk_size, 1 do +function TNN:move_right_to_nextmb(list_t) --move output history activations of 1..chunk_size to 1-chunk_size..0 + if list_t == nil then + list_t = {} + for i = 1, self.chunk_size do + list_t[i] = i - self.chunk_size + end + end + for i = 1, #list_t do + t = list_t[i] + if t < 1 - self.chunk_size or t > 0 then + nerv.error("MB move range error") + end for id, ref in pairs(self.layers) do for p = 1, #ref.dim_out do - ref.outputs_m[t - self.chunk_size][p]:copy_fromd(ref.outputs_m[t][p]) + ref.outputs_m[t][p]:copy_fromd(ref.outputs_m[t + self.chunk_size][p]) end end end |