Skip to content

Commit

Permalink
Remove spurious mallocs from nn.Linear
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlerer committed Sep 28, 2015
1 parent f660dbd commit fc023d6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Linear.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ function Linear:updateOutput(input)
if self.output:nElement() ~= nElement then
self.output:zero()
end
if not self.addBuffer or self.addBuffer:nElement() ~= nframe then
self.addBuffer = input.new(nframe):fill(1)
self.addBuffer = self.addBuffer or input.new()
if self.addBuffer:nElement() ~= nframe then
self.addBuffer:resize(nframe):fill(1)
end
self.output:addmm(0, self.output, 1, input, self.weight:t())
self.output:addr(1, self.addBuffer, self.bias)
Expand Down

0 comments on commit fc023d6

Please sign in to comment.