diff options
author | Pavan Yalamanchili <pyalamanchili@twitter.com> | 2017-02-17 04:25:33 +0300 |
---|---|---|
committer | Pavan Yalamanchili <pyalamanchili@twitter.com> | 2017-02-17 04:33:03 +0300 |
commit | 3996dbb87ec79d087c37bc6f4fe8f23a3767c88c (patch) | |
tree | d79dced267c31b5250930087ebd0e9fee21be340 /test.lua | |
parent | 618f847d94ad65baef1c1614ed241d6e4bea7151 (diff) |
Convert real to accreal in libTHCUNN
- This reverts commit 0d85922d116879448485ef88ae21e83a9255a0b0.
- Includes fixes for TemporalRowConvolution
Diffstat (limited to 'test.lua')
-rw-r--r-- | test.lua | 111 |
1 files changed, 51 insertions, 60 deletions
@@ -376,17 +376,17 @@ function cunntest.Square_transposed() end function cunntest.SoftShrink_forward() - local r = THC.THC_half2float(THC.THC_float2half(math.random())) + local r = math.random() pointwise_forward(nn.SoftShrink(r), 'SoftShrink', precision_forward) end function cunntest.SoftShrink_backward() - local r = THC.THC_half2float(THC.THC_float2half(math.random())) + local r = math.random() pointwise_backward(nn.SoftShrink(r), 'SoftShrink', precision_backward) end function cunntest.SoftShrink_transposed() - local r = THC.THC_half2float(THC.THC_float2half(math.random())) + local r = math.random() pointwise_transposed(nn.SoftShrink(r), 'SoftShrink', precision_backward) end @@ -2056,8 +2056,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,ki/2-1) - local padj = math.random(0,kj/2-1) + local padi = math.random(0,math.floor(ki/2)-1) + local padj = math.random(0,math.floor(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 @@ -2094,8 +2094,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,ki/2-1) - local padj = math.random(0,kj/2-1) + local padi = math.random(0,math.floor(ki/2)-1) + local padj = math.random(0,math.floor(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 @@ -2129,8 +2129,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,ki/2-1) - local padj = math.random(0,kj/2-1) + local padi = math.random(0,math.floor(ki/2)-1) + local padj = math.random(0,math.floor(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 @@ -2170,8 +2170,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,ki/2-1) - local padj = math.random(0,kj/2-1) + local padi = math.random(0,math.floor(ki/2)-1) + local padj = math.random(0,math.floor(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 @@ -2214,8 +2214,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,ki/2-1) - local padj = math.random(0,kj/2-1) + local padi = math.random(0,math.floor(ki/2)-1) + local padj = math.random(0,math.floor(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 @@ -2257,8 +2257,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,ki/2-1) - local padj = math.random(0,kj/2-1) + local padi = math.random(0,math.floor(ki/2)-1) + local padj = math.random(0,math.floor(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 @@ -2307,8 +2307,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,ki/2-1) - local padj = math.random(0,kj/2-1) + local padi = math.random(0,math.floor(ki/2)-1) + local padj = math.random(0,math.floor(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 @@ -2347,8 +2347,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,ki/2-1) - local padj = math.random(0,kj/2-1) + local padi = math.random(0,math.floor(ki/2)-1) + local padj = math.random(0,math.floor(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 @@ -2383,8 +2383,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,ki/2-1) - local padj = math.random(0,kj/2-1) + local padi = math.random(0,math.floor(ki/2)-1) + local padj = math.random(0,math.floor(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 @@ -2428,8 +2428,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,ki/2-1) - local padj = math.random(0,kj/2-1) + local padi = math.random(0,math.floor(ki/2)-1) + local padj = math.random(0,math.floor(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 @@ -2622,8 +2622,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,ki/2-1) - local padj = math.random(0,kj/2-1) + local padi = math.random(0,math.floor(ki/2)-1) + local padj = math.random(0,math.floor(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 @@ -2661,8 +2661,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,ki/2-1) - local padj = math.random(0,kj/2-1) + local padi = math.random(0,math.floor(ki/2)-1) + local padj = math.random(0,math.floor(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 @@ -2699,8 +2699,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,ki/2-1) - local padj = math.random(0,kj/2-1) + local padi = math.random(0,math.floor(ki/2)-1) + local padj = math.random(0,math.floor(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 @@ -2746,8 +2746,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,ki/2-1) - local padj = math.random(0,kj/2-1) + local padi = math.random(0,math.floor(ki/2)-1) + local padj = math.random(0,math.floor(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 @@ -3412,9 +3412,6 @@ 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() @@ -3446,9 +3443,6 @@ 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), @@ -4280,9 +4274,6 @@ 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() @@ -4684,9 +4675,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,kT/2-1) - local padH = math.random(0,kH/2-1) - local padW = math.random(0,kW/2-1) + 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 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) @@ -4720,9 +4711,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,kT/2-1) - local padH = math.random(0,kH/2-1) - local padW = math.random(0,kW/2-1) + 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 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) @@ -4764,9 +4755,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,kt/2-1) - local padi = math.random(0,ki/2-1) - local padj = math.random(0,kj/2-1) + 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 dilationt = math.random(1,10) local dilationi = math.random(1,10) local dilationj = math.random(1,10) @@ -4808,9 +4799,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,kt/2-1) - local padi = math.random(0,ki/2-1) - local padj = math.random(0,kj/2-1) + 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 dilationt = math.random(1,10) local dilationi = math.random(1,10) local dilationj = math.random(1,10) @@ -4858,9 +4849,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,kt/2-1) - local padi = math.random(0,ki/2-1) - local padj = math.random(0,kj/2-1) + 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 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) @@ -4899,9 +4890,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,kt/2-1) - local padi = math.random(0,ki/2-1) - local padj = math.random(0,kj/2-1) + 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 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) @@ -5226,8 +5217,8 @@ function cunntest.VolumetricFullConvolution_pair_test() local dT = math.random(1,3) local dH = math.random(1,3) local dW = dH - local pT = (kT-1)/2 - local pH = (kH-1)/2 + local pT = math.floor((kT-1)/2) + local pH = math.floor((kH-1)/2) local pW = pH local inChan = math.random(1,32) |