lua - Torch,如何检查变量是否是CUDA?

标签 lua torch

我正在寻找像 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/

相关文章:

lua - Tarantool:index.indexName:pairs 调用中的限制/偏移

lua - math.sin/cos/tan 是否使用查找表?

python - torch /Lua 等同于 MATLAB 或 Numpy 的功能 'Unique'

python - 计算大量数据而不会耗尽内存

node.js - 使用 LUA 触发 Redis HMSET

lua - 可以在不丢失 torch (lua) 中的引用的情况下连接张量吗?

lua - 在 torch 中组合张量的最惯用的方法是什么?

tensorflow - Torch 或 Tensorflow 中的通用循环神经网络

nginx - Redis 长轮询 Pub/Sub 频繁消息阻塞

android - 如何构建 torch-android