diff options
Diffstat (limited to 'Narrow.lua')
-rw-r--r-- | Narrow.lua | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -16,7 +16,12 @@ function Narrow:updateOutput(input) if length < 0 then length = input:size(dim) - self.index + self.length + 2 end - local output=input:narrow(dim,self.index,length) + local index = self.index + if self.index < 0 then + index = 1 + length = input:size(dim) - length + end + local output=input:narrow(dim, index, length) self.output = self.output:typeAs(output) self.output:resizeAs(output):copy(output) return self.output @@ -28,8 +33,13 @@ function Narrow:updateGradInput(input, gradOutput) if length < 0 then length = input:size(dim) - self.index + self.length + 2 end + local index = self.index + if self.index < 0 then + index = 1 + length = input:size(dim) - length + end self.gradInput = self.gradInput:typeAs(input) self.gradInput:resizeAs(input):zero() - self.gradInput:narrow(dim,self.index,length):copy(gradOutput) + self.gradInput:narrow(dim,index,length):copy(gradOutput) return self.gradInput end |