diff options
author | Sam Gross <colesbury@gmail.com> | 2015-07-16 00:09:22 +0300 |
---|---|---|
committer | Sam Gross <colesbury@gmail.com> | 2015-07-16 00:09:22 +0300 |
commit | bf269f0f9bc49dd68cf37a0504e2eb70688a7a85 (patch) | |
tree | 9745d578afcc1975d59689a68fb3e161ab2e218b /init.lua | |
parent | 3c911e7923811c11f82c179299112da338344a62 (diff) |
Use torch.typename in isTensor and isStorage
This supports tensor types that are implemented using cdata.
These cdata objects do not have a unique metatable. Their
names are available through torch.typename.
Diffstat (limited to 'init.lua')
-rw-r--r-- | init.lua | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -127,11 +127,19 @@ function torch.totable(obj) end function torch.isTensor(obj) - return type(obj) == 'userdata' and torch.isTypeOf(obj, 'torch.*Tensor') + local typename = torch.typename(obj) + if typename and typename:find('torch.*Tensor') then + return true + end + return false end function torch.isStorage(obj) - return type(obj) == 'userdata' and torch.isTypeOf(obj, 'torch.*Storage') + local typename = torch.typename(obj) + if typename and typename:find('torch.*Storage') then + return true + end + return false end -- alias for convenience torch.Tensor.isTensor = torch.isTensor |