diff options
author | Simon N <CodeRect@users.noreply.github.com> | 2016-05-16 05:09:47 +0300 |
---|---|---|
committer | Simon N <CodeRect@users.noreply.github.com> | 2016-05-16 05:09:47 +0300 |
commit | 4c56c19571b06aead938da67b80b281e9d467068 (patch) | |
tree | df664813588be61b531ebad5253caa0f77fd138e /Narrow.lua | |
parent | 9f64ffa3e20c73ada3ab8c1564eb821e719f0155 (diff) |
added support for negative lenghts to Narrow
Diffstat (limited to 'Narrow.lua')
-rw-r--r-- | Narrow.lua | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -11,15 +11,23 @@ function Narrow:__init(dimension,offset,length) end function Narrow:updateOutput(input) - local output=input:narrow(self.dimension,self.index,self.length) + local length = self.length + if length < 0 then + length = input:size(self.dimension) - self.index + self.length + 2 + end + local output=input:narrow(self.dimension,self.index,length) self.output = self.output:typeAs(output) self.output:resizeAs(output):copy(output) return self.output end function Narrow:updateGradInput(input, gradOutput) + local length = self.length + if length < 0 then + length = input:size(self.dimension) - self.index + self.length + 2 + end self.gradInput = self.gradInput:typeAs(input) self.gradInput:resizeAs(input):zero() - self.gradInput:narrow(self.dimension,self.index,self.length):copy(gradOutput) + self.gradInput:narrow(self.dimension,self.index,length):copy(gradOutput) return self.gradInput end |