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

github.com/torch/cutorch.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/torch
diff options
context:
space:
mode:
authorztaylor <ztaylor@twitter.com>2015-05-23 00:47:39 +0300
committerztaylor <ztaylor@twitter.com>2015-05-27 18:21:03 +0300
commit7ae4e6a04bcbcb6d7712115f0b4ddd12d97acd6f (patch)
treeafa563a92d4869c54e6d25a938f5f28d2ef54101 /torch
parentdbe760c5ecca0f577c3dc81ef3383a794c41ba0c (diff)
Adding support for Storage views to cutorch.
Diffstat (limited to 'torch')
-rw-r--r--torch/generic/Storage.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/torch/generic/Storage.c b/torch/generic/Storage.c
index 995e57f..9dc1333 100644
--- a/torch/generic/Storage.c
+++ b/torch/generic/Storage.c
@@ -30,12 +30,29 @@ static int torch_Storage_(new)(lua_State *L)
lua_pop(L, 1);
}
}
+ else if(lua_type(L, 1) == LUA_TUSERDATA)
+ {
+ THStorage *src = luaT_checkudata(L, 1, torch_Storage);
+ real *ptr = src->data;
+ long offset = luaL_optlong(L, 2, 1) - 1;
+ if (offset < 0 || offset >= src->size) {
+ luaL_error(L, "offset out of bounds");
+ }
+ long size = luaL_optlong(L, 3, src->size - offset);
+ if (size < 1 || size > (src->size - offset)) {
+ luaL_error(L, "size out of bounds");
+ }
+ storage = THStorage_(newWithData)(state, ptr + offset, size);
+ storage->flag = TH_STORAGE_REFCOUNTED | TH_STORAGE_VIEW;
+ storage->view = src;
+ THStorage_(retain)(storage->view);
+ }
else if(lua_type(L, 2) == LUA_TNUMBER)
{
long size = luaL_optlong(L, 1, 0);
real *ptr = (real *)luaL_optlong(L, 2, 0);
storage = THStorage_(newWithData)(state, ptr, size);
- storage->flag = 0;
+ storage->flag = TH_STORAGE_REFCOUNTED;
}
else
{
@@ -183,7 +200,7 @@ static int torch_Storage_(write)(lua_State *L)
{
THStorage *storage = luaT_checkudata(L, 1, torch_Storage);
THFile *file = luaT_checkudata(L, 2, "torch.File");
-
+
THFile_writeLongScalar(file, storage->size);
THFile_writeRealRaw(file, storage->data, storage->size);