Skip to content

Commit

Permalink
Added more informative pretty-printing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan J Hunt committed Jan 8, 2015
1 parent 27acf63 commit 608ac7c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Linear.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,9 @@ end

-- we do not need to accumulate parameters when sharing
Linear.sharedAccUpdateGradParameters = Linear.accUpdateGradParameters


function Linear:__tostring__()
return torch.type(self) ..
string.format('(%d -> %d)', self.weight:size(2), self.weight:size(1))
end
6 changes: 6 additions & 0 deletions Reshape.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@ function Reshape:updateGradInput(input, gradOutput)
self.gradInput:viewAs(gradOutput, input)
return self.gradInput
end


function Reshape:__tostring__()
return torch.type(self) .. '(' ..
table.concat(self.size:totable(), 'x') .. ')'
end
7 changes: 7 additions & 0 deletions SpatialZeroPadding.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,10 @@ function SpatialZeroPadding:updateGradInput(input, gradOutput)
end
return self.gradInput
end


function SpatialZeroPadding:__tostring__()
return torch.type(self) ..
string.format('(l=%d,r=%d,t=%d,b=%d)', self.pad_l, self.pad_r,
self.pad_t, self.pad_b)
end
16 changes: 16 additions & 0 deletions test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ local function equal(t1, t2, msg)
end


--[[ Generate tests to exercise the tostring component of modules. ]]
local tostringTestModules = {
nnLinear = nn.Linear(1, 2),
nnReshape = nn.Reshape(10),
nnSpatialZeroPadding = nn.SpatialZeroPadding(1, 1, 1, 1)}
for test_name, component in pairs(tostringTestModules) do
nntest['tostring' .. test_name] =
function ()
mytester:assert(tostring(component):find(torch.type(component) .. '(',
1, true),
'nn components should have a descriptive tostring' ..
' beginning with the classname')
end
end


function nntest.Add()
local inj_vals = {math.random(3,5), 1} -- Also test the inj = 1 spatial case
local ini = math.random(3,5)
Expand Down

0 comments on commit 608ac7c

Please sign in to comment.