我正在寻找像 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
关于lua - Torch,如何检查变量是否是CUDA?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39225413/