lua---mattorch icon indicating copy to clipboard operation
lua---mattorch copied to clipboard

Problem when running with torch.setdefaulttensortype('torch.FloatTensor')

Open Amit12690 opened this issue 9 years ago • 1 comments

Hi , I found a bug when running mattorch.save from my env which has default tensor type set to FloatTensor. The error which I get is as follows inspite of passing a double tensor as input

/usr/local/torch/install/share/lua/5.1/mattorch/init.lua:77: bad argument #1 to 'resizeAs' (torch.FloatTensor expected, got torch.DoubleTensor)
stack traceback:
        [C]: at 0x7fcf5529a9c0
        [C]: in function 'resizeAs'
        /usr/local/torch/install/share/lua/5.1/mattorch/init.lua:77: in function 'save'

This is happening due to the presence of torch.Tensor():resizeAs(vars):copy(vars) in line 77 of init.lua torch.Tensor() creates a tensor of default tensor type set . Hence the mismatch occurs even though I pass double tensor as input.

One fix which worked for me is to make it independent of default tensor type set by adding torch.setdefaulttensortype('torch.DoubleTensor') in the beginning of init.lua or the code where we call it from. Hope this is helpful.

Amit12690 avatar Jun 21 '16 10:06 Amit12690

This really helps! Thanks!!!!

ShichenLiu avatar May 22 '19 17:05 ShichenLiu