diff options
author | Soumith Chintala <soumith@gmail.com> | 2014-05-12 19:18:57 +0400 |
---|---|---|
committer | Soumith Chintala <soumith@gmail.com> | 2014-05-12 19:18:57 +0400 |
commit | 8e0d8500f43eb88e9dafa789e1ac5d9e6c29e02b (patch) | |
tree | e21e21b5f97b49f6fb8fc057488923770a2106c7 /test | |
parent | 2353158c6db7b61f711ad3d93de0384390cc9040 (diff) | |
parent | d389ba76e9676ee2d00ed87dd1934640f9266c63 (diff) |
Merge branch 'master' of github.com:torch/nn
Diffstat (limited to 'test')
-rw-r--r-- | test/test.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/test.lua b/test/test.lua index 0e85578..7eb2d44 100644 --- a/test/test.lua +++ b/test/test.lua @@ -1438,12 +1438,36 @@ function nntest.TemporalMaxPooling() local module = nn.TemporalMaxPooling(ki, si) local input = torch.Tensor(ini, from):zero() + -- 1D + local err = jac.testJacobian(module, input) + mytester:assertlt(err, precision, 'error on state ') + + local ferr, berr = jac.testIO(module, input) + mytester:asserteq(0, ferr, torch.typename(module) .. ' - i/o forward err ') + mytester:asserteq(0, berr, torch.typename(module) .. ' - i/o backward err ') + + -- 2D + local nBatchFrame = 2 + local input = torch.Tensor(nBatchFrame, ini, from):zero() local err = jac.testJacobian(module, input) mytester:assertlt(err, precision, 'error on state ') local ferr, berr = jac.testIO(module, input) mytester:asserteq(0, ferr, torch.typename(module) .. ' - i/o forward err ') mytester:asserteq(0, berr, torch.typename(module) .. ' - i/o backward err ') + + -- 2D matches 1D + local output = module:forward(input):clone() + local outputGrad = torch.randn(output:size()) + local inputGrad = module:backward(input, outputGrad):clone() + + local input1D = input:select(1, 1) + local output1D = module:forward(input1D) + local outputGrad1D = outputGrad:select(1, 1) + local inputGrad1D = module:backward(input1D, outputGrad1D) + + mytester:assertTensorEq(output:select(1,1), output1D, 0.000001, 'error on 2D vs 1D forward)') + mytester:assertTensorEq(inputGrad:select(1,1), inputGrad1D, 0.000001, 'error on 2D vs 1D backward)') end function nntest.VolumetricConvolution() |