Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/torch7.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2015-07-16 00:09:22 +0300
committerSam Gross <colesbury@gmail.com>2015-07-16 00:09:22 +0300
commitbf269f0f9bc49dd68cf37a0504e2eb70688a7a85 (patch)
tree9745d578afcc1975d59689a68fb3e161ab2e218b /init.lua
parent3c911e7923811c11f82c179299112da338344a62 (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.lua12
1 files changed, 10 insertions, 2 deletions
diff --git a/init.lua b/init.lua
index 76e08d0..ae2ccf5 100644
--- a/init.lua
+++ b/init.lua
@@ -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