From 7286784cbd0af841501bfadb98a4a2cee28199b6 Mon Sep 17 00:00:00 2001 From: Jonathan Tompson Date: Sun, 20 Oct 2013 11:51:07 -0400 Subject: fixed a bug in Pairwise distance when the output Lp norm is zero (which results in a divide by zero issue). Rewrote PairwiseDistance following Clement's suggestion to only have one codepath. Fixed a small bug in extra/test/test.lua where the input to the non-batch fprop test was zero. --- test/test.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/test.lua b/test/test.lua index 5a1d469..0d54e3d 100644 --- a/test/test.lua +++ b/test/test.lua @@ -1536,7 +1536,7 @@ function nntest.PairwiseDistance() -- I assume both SplitTable and Sequential do not have bugs, otherwise this -- test will break. for p = 1,4 do -- test a few Lp norms - -- TEST CASE 1: non-batch inputs + -- TEST CASE 1: non-batch input, same code path but includes a resize local ini = math.random(10,20) local input = torch.Tensor(2, ini):zero() local module = nn.Sequential() @@ -1550,7 +1550,8 @@ function nntest.PairwiseDistance() mytester:asserteq(ferr, 0, torch.typename(module)..' - i/o forward err ') mytester:asserteq(berr, 0, torch.typename(module)..' - i/o backward err ') - -- Also check that the forward prop result is correct + -- Also check that the forward prop result is correct. + input = torch.rand(2, ini) err = torch.dist(input:select(1,1), input:select(1,2), p) - module:forward(input)[1] mytester:assertlt(err,precision, ' error on non-batch fprop ') @@ -1567,7 +1568,7 @@ function nntest.PairwiseDistance() err = jac.testJacobian(module,input) mytester:assertlt(err,precision, ' error on state ') - -- Also check that the forward prop result is correct + -- Also check that the forward prop result is correct. -- manually calculate each distance separately local inputa = torch.rand(inj,ini) local inputb = torch.rand(inj,ini) -- cgit v1.2.3