Torch,如何检查变量是否为 CUDA?
Torch, how to check a variable is CUDA or not?
我正在寻找类似 type() 的函数来识别哪个变量是 CudaTensor 或 Normal。
require('cutorch')
x = torch.Tensor(3,3)
x = x:cuda()
if type(x) == 'CudaTensor' then -- What function should be used?
print('x is CUDA tensor')
else
print('x is normal tensor')
end
使用:type()
张量的方法:
cutorch = require('cutorch')
x = torch.Tensor(3,3)
x = x:cuda()
if x:type() == 'torch.CudaTensor' then
print('x is CUDA tensor')
else
print('x is normal tensor')
end
我正在寻找类似 type() 的函数来识别哪个变量是 CudaTensor 或 Normal。
require('cutorch')
x = torch.Tensor(3,3)
x = x:cuda()
if type(x) == 'CudaTensor' then -- What function should be used?
print('x is CUDA tensor')
else
print('x is normal tensor')
end
使用:type()
张量的方法:
cutorch = require('cutorch')
x = torch.Tensor(3,3)
x = x:cuda()
if x:type() == 'torch.CudaTensor' then
print('x is CUDA tensor')
else
print('x is normal tensor')
end