diff options
author | Soumith Chintala <soumith@gmail.com> | 2014-05-11 21:22:34 +0400 |
---|---|---|
committer | Soumith Chintala <soumith@gmail.com> | 2014-05-11 21:22:34 +0400 |
commit | d389ba76e9676ee2d00ed87dd1934640f9266c63 (patch) | |
tree | 42de8ef60f7a9e909978a04b001c5b55b04d3f54 /test | |
parent | 3f10105da13bd9c081f177ad5b41779493ca564f (diff) | |
parent | 7b6e0fc65559cf0c329f913417f0b723823fc6e7 (diff) |
Merge pull request #9 from nicholas-leonard/master
Batch TemporalMaxPooling
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 29f76da..a0d7566 100644 --- a/test/test.lua +++ b/test/test.lua @@ -1413,12 +1413,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() |