From f94245b0019c3fd1b6d2bbfc836e08f9e90b64b8 Mon Sep 17 00:00:00 2001 From: Sasank Chilamkurthy Date: Tue, 13 Sep 2016 20:11:48 +0530 Subject: Fixed type issue in affinetransform and warp. See https://github.com/torch/image/issues/187 --- init.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 7f15fd5..619d9b7 100644 --- a/init.lua +++ b/init.lua @@ -952,6 +952,7 @@ local function warp(...) dok.error('Incorrect arguments (clamp_mode is not clamp | pad)!', 'image.warp') end + local field = field:typeAs(torch.Tensor()) -- coerce matrix to default tensor type local dim2 = false if src:nDimension() == 2 then dim2 = true @@ -1065,14 +1066,15 @@ local function affinetransform(...) local grid_y = torch.ger( torch.linspace(-1,1,height), torch.ones(width) ) local grid_x = torch.ger( torch.ones(height), torch.linspace(-1,1,width) ) - local grid_xy = torch.FloatTensor() + local grid_xy = torch.Tensor() grid_xy:resize(2,height,width) grid_xy[1] = grid_y * ((height-1)/2) * -1 grid_xy[2] = grid_x * ((width-1)/2) * -1 local view_xy = grid_xy:reshape(2,height*width) + local matrix = matrix:typeAs(torch.Tensor()) -- coerce matrix to default tensor type local field = torch.mm(matrix, view_xy) - field = (grid_xy - field:reshape( 2, height, width )):double() + field = (grid_xy - field:reshape( 2, height, width )) -- offset field for translation translation = torch.Tensor(translation) -- cgit v1.2.3