diff options
Diffstat (limited to 'test.lua')
-rw-r--r-- | test.lua | 111 |
1 files changed, 60 insertions, 51 deletions
@@ -365,17 +365,17 @@ function cunntest.Square_transposed() end function cunntest.SoftShrink_forward() - local r = math.random() + local r = THC.THC_half2float(THC.THC_float2half(math.random())) pointwise_forward(nn.SoftShrink(r), 'SoftShrink', precision_forward) end function cunntest.SoftShrink_backward() - local r = math.random() + local r = THC.THC_half2float(THC.THC_float2half(math.random())) pointwise_backward(nn.SoftShrink(r), 'SoftShrink', precision_backward) end function cunntest.SoftShrink_transposed() - local r = math.random() + local r = THC.THC_half2float(THC.THC_float2half(math.random())) pointwise_transposed(nn.SoftShrink(r), 'SoftShrink', precision_backward) end @@ -2045,8 +2045,8 @@ function cunntest.SpatialMaxPooling_forward() local sj = math.random(1,4) local outi = math.random(32,256) local outj = math.random(32,256) - local padi = math.random(0,math.floor(ki/2)-1) - local padj = math.random(0,math.floor(kj/2)-1) + local padi = math.random(0,ki/2-1) + local padj = math.random(0,kj/2-1) local ini = (outi-1)*si+ki - padi*2 local inj = (outj-1)*sj+kj - padj*2 local ceil_mode = math.random(0,1) == 1 @@ -2083,8 +2083,8 @@ function cunntest.SpatialMaxPooling_forward_batch() local sj = math.random(2,4) local outi = math.random(32,256) local outj = math.random(32,256) - local padi = math.random(0,math.floor(ki/2)-1) - local padj = math.random(0,math.floor(kj/2)-1) + local padi = math.random(0,ki/2-1) + local padj = math.random(0,kj/2-1) local ini = (outi-1)*si+ki - padi*2 local inj = (outj-1)*sj+kj - padj*2 local ceil_mode = math.random(0,1) == 1 @@ -2118,8 +2118,8 @@ function cunntest.SpatialMaxUnpooling_forward_batch() local sj = kj local outi = math.random(32,256) local outj = math.random(32,256) - local padi = math.random(0,math.floor(ki/2)-1) - local padj = math.random(0,math.floor(kj/2)-1) + local padi = math.random(0,ki/2-1) + local padj = math.random(0,kj/2-1) local ceil_mode = math.random(0,1) == 1 local fun = ceil_mode and torch.ceil or torch.floor local ini = fun((outi + padi*2 - ki)/si) +1 @@ -2159,8 +2159,8 @@ function cunntest.SpatialMaxPooling_backward() local sj = math.random(1,4) local outi = math.random(32,64) local outj = math.random(32,64) - local padi = math.random(0,math.floor(ki/2)-1) - local padj = math.random(0,math.floor(kj/2)-1) + local padi = math.random(0,ki/2-1) + local padj = math.random(0,kj/2-1) local ini = (outi-1)*si+ki - padi*2 local inj = (outj-1)*sj+kj - padj*2 local ceil_mode = true--math.random(0,1) == 1 @@ -2203,8 +2203,8 @@ function cunntest.SpatialMaxPooling_backward_batch() local sj = math.random(2,4) local outi = math.random(32,64) local outj = math.random(32,64) - local padi = math.random(0,math.floor(ki/2)-1) - local padj = math.random(0,math.floor(kj/2)-1) + local padi = math.random(0,ki/2-1) + local padj = math.random(0,kj/2-1) local ini = (outi-1)*si+ki - padi*2 local inj = (outj-1)*sj+kj - padj*2 local ceil_mode = math.random(0,1) == 1 @@ -2246,8 +2246,8 @@ function cunntest.SpatialMaxUnpooling_backward_batch() local sj = kj local outi = math.random(32,256) local outj = math.random(32,256) - local padi = math.random(0,math.floor(ki/2)-1) - local padj = math.random(0,math.floor(kj/2)-1) + local padi = math.random(0,ki/2-1) + local padj = math.random(0,kj/2-1) local ceil_mode = math.random(0,1) == 1 local fun = ceil_mode and torch.ceil or torch.floor local ini = fun((outi + padi*2 - ki)/si) +1 @@ -2296,8 +2296,8 @@ function cunntest.SpatialDilatedMaxPooling_forward() local sj = math.random(1,4) local outi = math.random(32,256) local outj = math.random(32,256) - local padi = math.random(0,math.floor(ki/2)-1) - local padj = math.random(0,math.floor(kj/2)-1) + local padi = math.random(0,ki/2-1) + local padj = math.random(0,kj/2-1) local dilationi = math.random(1,10) local dilationj = math.random(1,10) local ini = (outi-1)*si+(dilationi*(ki-1)+1)-2*padi @@ -2336,8 +2336,8 @@ function cunntest.SpatialDilatedMaxPooling_forward_batch() local sj = math.random(2,4) local outi = math.random(32,256) local outj = math.random(32,256) - local padi = math.random(0,math.floor(ki/2)-1) - local padj = math.random(0,math.floor(kj/2)-1) + local padi = math.random(0,ki/2-1) + local padj = math.random(0,kj/2-1) local dilationi = math.random(1,10) local dilationj = math.random(1,10) local ini = (outi-1)*si+(dilationi*(ki-1)+1)-2*padi @@ -2372,8 +2372,8 @@ function cunntest.SpatialDilatedMaxPooling_backward() local sj = math.random(1,4) local outi = math.random(32,64) local outj = math.random(32,64) - local padi = math.random(0,math.floor(ki/2)-1) - local padj = math.random(0,math.floor(kj/2)-1) + local padi = math.random(0,ki/2-1) + local padj = math.random(0,kj/2-1) local dilationi = math.random(1,10) local dilationj = math.random(1,10) local ini = (outi-1)*si+(dilationi*(ki-1)+1)-2*padi @@ -2417,8 +2417,8 @@ function cunntest.SpatialDilatedMaxPooling_backward_batch() local sj = math.random(2,4) local outi = math.random(32,64) local outj = math.random(32,64) - local padi = math.random(0,math.floor(ki/2)-1) - local padj = math.random(0,math.floor(kj/2)-1) + local padi = math.random(0,ki/2-1) + local padj = math.random(0,kj/2-1) local dilationi = math.random(1,10) local dilationj = math.random(1,10) local ini = (outi-1)*si+(dilationi*(ki-1)+1)-2*padi @@ -2611,8 +2611,8 @@ function cunntest.SpatialAveragePooling_forward() local sj = math.random(1,kj) local outi = math.random(32,256) local outj = math.random(32,256) - local padi = math.random(0,math.floor(ki/2)-1) - local padj = math.random(0,math.floor(kj/2)-1) + local padi = math.random(0,ki/2-1) + local padj = math.random(0,kj/2-1) local ini = (outi-1)*si+ki - padi*2 local inj = (outj-1)*sj+kj - padj*2 local ceil_mode = math.random(0,1) == 1 @@ -2650,8 +2650,8 @@ function cunntest.SpatialAveragePooling_forward_batch() local sj = math.random(1,kj) local outi = math.random(32,256) local outj = math.random(32,256) - local padi = math.random(0,math.floor(ki/2)-1) - local padj = math.random(0,math.floor(kj/2)-1) + local padi = math.random(0,ki/2-1) + local padj = math.random(0,kj/2-1) local ini = (outi-1)*si+ki - padi*2 local inj = (outj-1)*sj+kj - padj*2 local ceil_mode = math.random(0,1) == 1 @@ -2688,8 +2688,8 @@ function cunntest.SpatialAveragePooling_backward() local sj = math.random(1,kj) local outi = math.random(32,64) local outj = math.random(32,64) - local padi = math.random(0,math.floor(ki/2)-1) - local padj = math.random(0,math.floor(kj/2)-1) + local padi = math.random(0,ki/2-1) + local padj = math.random(0,kj/2-1) local ini = (outi-1)*si+ki - padi*2 local inj = (outj-1)*sj+kj - padj*2 local ceil_mode = math.random(0,1) == 1 @@ -2735,8 +2735,8 @@ function cunntest.SpatialAveragePooling_backward_batch() local sj = math.random(1,kj) local outi = math.random(32,64) local outj = math.random(32,64) - local padi = math.random(0,math.floor(ki/2)-1) - local padj = math.random(0,math.floor(kj/2)-1) + local padi = math.random(0,ki/2-1) + local padj = math.random(0,kj/2-1) local ini = (outi-1)*si+ki - padi*2 local inj = (outj-1)*sj+kj - padj*2 local ceil_mode = math.random(0,1) == 1 @@ -3401,6 +3401,9 @@ function cunntest.mse() local cout = cmod:forward(cinput,ctarget) local cgin = cmod:backward(cinput,ctarget) + if (typename == 'torch.CudaHalfTensor') then + fout = THC.THC_half2float(THC.THC_float2half(fout)) + end mytester:assertlt(math.abs(fout-cout), precision_forward_type(0.02, typename), string.format('error on output with %s', typename)) local gerr = cgin:double() - fgin:double() @@ -3432,6 +3435,9 @@ function cunntest.SmoothL1() local cout = cmod:forward(cinput,ctarget) local cgin = cmod:backward(cinput,ctarget) + if (typename == 'torch.CudaHalfTensor') then + fout = THC.THC_half2float(THC.THC_float2half(fout)) + end mytester:assertlt(math.abs(fout-cout), 0.01, string.format('error on output with %s', typename)) local gerr = cgin:double() - fgin:double() mytester:assertlt(gerr:abs():max(), precision_forward_type(precision_forward, typename), @@ -3994,6 +4000,9 @@ function cunntest.l1cost() local cout = cmod:forward(cinput) local cgin = cmod:backward(cinput) + if (typename == 'torch.CudaHalfTensor') then + fout = THC.THC_half2float(THC.THC_float2half(fout)) + end mytester:assertlt(math.abs(fout-cout), precision_forward_type(precision_forward, typename), string.format('error on output with %s', typename)) local gerr = cgin:double() - fgin:double() @@ -4395,9 +4404,9 @@ function cunntest.VolumetricMaxPooling_forward() local iT = math.random(kT*2, 60) local iH = math.random(kH*2, 60) local iW = math.random(kW*2, 60) - local padT = math.random(0,math.floor(kT/2)-1) - local padH = math.random(0,math.floor(kH/2)-1) - local padW = math.random(0,math.floor(kW/2)-1) + local padT = math.random(0,kT/2-1) + local padH = math.random(0,kH/2-1) + local padW = math.random(0,kW/2-1) local iF = math.random(1, 16) -- features local oT = math.floor((iT - kT + 2*padT) / dT + 1) local oH = math.floor((iH - kH + 2*padH) / dH + 1) @@ -4431,9 +4440,9 @@ function cunntest.VolumetricMaxPooling_backward() local iT = math.random(kT*2, 60) local iH = math.random(kH*2, 60) local iW = math.random(kW*2, 60) - local padT = math.random(0,math.floor(kT/2)-1) - local padH = math.random(0,math.floor(kH/2)-1) - local padW = math.random(0,math.floor(kW/2)-1) + local padT = math.random(0,kT/2-1) + local padH = math.random(0,kH/2-1) + local padW = math.random(0,kW/2-1) local iF = math.random(1, 16) -- features local oT = math.floor((iT - kT + 2*padT) / dT + 1) local oH = math.floor((iH - kH + 2*padH) / dH + 1) @@ -4475,9 +4484,9 @@ function cunntest.VolumetricDilatedMaxPooling_forward_batch() local outt = math.random(1,10) local outi = math.random(1,33) local outj = math.random(1,33) - local padt = math.random(0,math.floor(kt/2)-1) - local padi = math.random(0,math.floor(ki/2)-1) - local padj = math.random(0,math.floor(kj/2)-1) + local padt = math.random(0,kt/2-1) + local padi = math.random(0,ki/2-1) + local padj = math.random(0,kj/2-1) local dilationt = math.random(1,10) local dilationi = math.random(1,10) local dilationj = math.random(1,10) @@ -4519,9 +4528,9 @@ function cunntest.VolumetricDilatedMaxPooling_backward_batch() local outt = math.random(8,16) local outi = math.random(8,16) local outj = math.random(8,16) - local padt = math.random(0,math.floor(kt/2)-1) - local padi = math.random(0,math.floor(ki/2)-1) - local padj = math.random(0,math.floor(kj/2)-1) + local padt = math.random(0,kt/2-1) + local padi = math.random(0,ki/2-1) + local padj = math.random(0,kj/2-1) local dilationt = math.random(1,10) local dilationi = math.random(1,10) local dilationj = math.random(1,10) @@ -4569,9 +4578,9 @@ function cunntest.VolumetricMaxUnpooling_forward_batch() local outt = math.random(32,128) local outi = math.random(32,128) local outj = math.random(32,128) - local padt = math.random(0,math.floor(kt/2)-1) - local padi = math.random(0,math.floor(ki/2)-1) - local padj = math.random(0,math.floor(kj/2)-1) + local padt = math.random(0,kt/2-1) + local padi = math.random(0,ki/2-1) + local padj = math.random(0,kj/2-1) local it = math.max(((outt + padt*2 - kt)/st) +1, kt) local ii = math.max(((outi + padi*2 - ki)/si) +1, ki) local ij = math.max(((outj + padj*2 - kj)/sj) +1, kj) @@ -4610,9 +4619,9 @@ function cunntest.VolumetricMaxUnpooling_backward_batch() local outt = math.random(32,128) local outi = math.random(32,128) local outj = math.random(32,128) - local padt = math.random(0,math.floor(kt/2)-1) - local padi = math.random(0,math.floor(ki/2)-1) - local padj = math.random(0,math.floor(kj/2)-1) + local padt = math.random(0,kt/2-1) + local padi = math.random(0,ki/2-1) + local padj = math.random(0,kj/2-1) local it = math.max(((outt + padt*2 - kt)/st) +1, kt) local ii = math.max(((outi + padi*2 - ki)/si) +1, ki) local ij = math.max(((outj + padj*2 - kj)/sj) +1, kj) @@ -4937,8 +4946,8 @@ function cunntest.VolumetricFullConvolution_pair_test() local dT = math.random(1,3) local dH = math.random(1,3) local dW = dH - local pT = math.floor((kT-1)/2) - local pH = math.floor((kH-1)/2) + local pT = (kT-1)/2 + local pH = (kH-1)/2 local pW = pH local inChan = math.random(1,32) |