我首先看到了 luatorch[cpuType]
中的用法,例如 fb.resnest.torch 的文件dataloader.lua:
batch = torch[cpuType](sz, nCrops, table.unpack(imageSize))
我没有找到任何语法解释。怎么理解?
PS:cpuType
是在文件中定义的self.cpuType
,我猜是 .
更新:根据我的测试,torch['FloatTensor']
相当于torch.FloatTensor
.
我首先看到了 luatorch[cpuType]
中的用法,例如 fb.resnest.torch 的文件dataloader.lua:
batch = torch[cpuType](sz, nCrops, table.unpack(imageSize))
我没有找到任何语法解释。怎么理解?
PS:cpuType
是在文件中定义的self.cpuType
,我猜是 .
更新:根据我的测试,torch['FloatTensor']
相当于torch.FloatTensor
.
我认为这torch[cpuType]
与torch.cpuType
.
代码(https://github.com/facebook/fb.resnet.torch/blob/master/dataloader.lua#L51-L57)似乎说cpuType
可以采用几个不同的值,即DoubleTensor
,FloatTensor
或HalfTensor
. 因此,该符号创建了torch.DoubleTensor
ortorch.FloatTensor
或torch.HalfTensor
。它是一种更紧凑的符号,例如
if cpuType == 'torch.DoubleTensor' then
batch = torch.DoubleTensor(sz, nCrops, table.unpack(imageSize))
elseif cpuType == 'torch.FloatTensor' then
batch = torch.FloatTensor(sz, nCrops, table.unpack(imageSize))
elseif cpuType == 'torch.HalfTensor' then
batch = torch.HalfTensor(sz, nCrops, table.unpack(imageSize))
From my knowledge in pytorch, which is pretty much very similar to Lua Torch (I tried lua torch too), I would say it specifies where you want this tensor to be stored. Note that torch cannot perform an operation stored two different processing unit. There are methods to move data between cpu (netŧ.cpu()) and gpu [net.cuda()].