From 3e0b2dde2151d98a75b5ef4006618eb61d5e5e1a Mon Sep 17 00:00:00 2001 From: nicholas-leonard Date: Sun, 11 May 2014 01:59:06 -0400 Subject: TemporalMaxPooling batch unit tests --- test/test.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test') 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() -- cgit v1.2.3