This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
3,831 additions
and
424 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
------------------------------------------------------------------------ | ||
--[[ Constant ]]-- | ||
-- author : Nicolas Leonard | ||
-- Outputs a constant value given an input. | ||
------------------------------------------------------------------------ | ||
local Constant, parent = torch.class("fbnn.Constant", "nn.Module") | ||
|
||
function Constant:__init(value) | ||
self.value = value | ||
if torch.type(self.value) == 'number' then | ||
self.value = torch.Tensor{self.value} | ||
end | ||
assert(torch.isTensor(self.value), "Expecting number or tensor at arg 1") | ||
parent.__init(self) | ||
end | ||
|
||
function Constant:updateOutput(input) | ||
-- "input:size(1)"" makes the assumption that you're in batch mode | ||
local vsize = self.value:size():totable() | ||
self.output:resize(input:size(1), table.unpack(vsize)) | ||
local value = self.value:view(1, table.unpack(vsize)) | ||
self.output:copy(value:expand(self.output:size())) | ||
return self.output | ||
end | ||
|
||
function Constant:updateGradInput(input, gradOutput) | ||
self.gradInput:resizeAs(input):zero() | ||
return self.gradInput | ||
end |
Oops, something went wrong.