diff options
author | Ronan Collobert <ronan@collobert.com> | 2014-04-07 18:25:43 +0400 |
---|---|---|
committer | Ronan Collobert <ronan@collobert.com> | 2014-04-07 18:25:43 +0400 |
commit | 2c53e62dca687868a5ad025a475f960e0e931431 (patch) | |
tree | 1c8c83e074f21e9c26a09627cc2848a4b70e65e1 /torch | |
parent | 3218a3e06c2684bfdf4e9cf4e53fe7d1782cb7bd (diff) |
upgrading torch/generic files to the last version
Diffstat (limited to 'torch')
-rw-r--r-- | torch/generic/Storage.c | 3 | ||||
-rw-r--r-- | torch/generic/Tensor.c | 26 |
2 files changed, 20 insertions, 9 deletions
diff --git a/torch/generic/Storage.c b/torch/generic/Storage.c index dc0678e..66ff742 100644 --- a/torch/generic/Storage.c +++ b/torch/generic/Storage.c @@ -9,7 +9,8 @@ static int torch_Storage_(new)(lua_State *L) { const char *fileName = luaL_checkstring(L, 1); int isShared = luaT_optboolean(L, 2, 0); - storage = THStorage_(newWithMapping)(fileName, isShared); + long size = luaL_optlong(L, 3, 0); + storage = THStorage_(newWithMapping)(fileName, size, isShared); } else if(lua_type(L, 1) == LUA_TTABLE) { diff --git a/torch/generic/Tensor.c b/torch/generic/Tensor.c index a2b2d57..dd1961b 100644 --- a/torch/generic/Tensor.c +++ b/torch/generic/Tensor.c @@ -555,7 +555,9 @@ static int torch_Tensor_(__newindex__)(lua_State *L) { void *src; long index = luaL_checklong(L,2)-1; + luaL_argcheck(L, tensor->nDimension > 0, 1, "empty tensor"); if (index < 0) index = tensor->size[0] + index + 1; + if (lua_isnumber(L,3)) { real value = (real)luaL_checknumber(L,3); if (tensor->nDimension == 1) { @@ -633,12 +635,13 @@ static int torch_Tensor_(__newindex__)(lua_State *L) } else if(lua_istable(L, 2)) { - int dim; + int dim; int cdim = 0; int ndims; int done = 0; - tensor = THTensor_(newWithTensor)(tensor); ndims = tensor->nDimension; + luaL_argcheck(L, lua_objlen(L, 2) <= ndims, 2, "too many indices provided"); + tensor = THTensor_(newWithTensor)(tensor); for(dim = 0; dim < ndims; dim++) { lua_rawgeti(L, 2, dim+1); @@ -745,9 +748,9 @@ static int torch_Tensor_(__index__)(lua_State *L) if(lua_isnumber(L, 2)) { long index = luaL_checklong(L,2)-1; - if (index < 0) index = tensor->size[0] + index + 1; luaL_argcheck(L, tensor->nDimension > 0, 1, "empty tensor"); + if (index < 0) index = tensor->size[0] + index + 1; luaL_argcheck(L, index >= 0 && index < tensor->size[0], 2, "out of range"); if(tensor->nDimension == 1) @@ -787,9 +790,11 @@ static int torch_Tensor_(__index__)(lua_State *L) int cdim = 0; int ndims; int done = 0; - tensor = THTensor_(newWithTensor)(tensor); + ndims = tensor->nDimension; - + luaL_argcheck(L, lua_objlen(L, 2) <= ndims, 2, "too many indices provided"); + tensor = THTensor_(newWithTensor)(tensor); + for(dim = 0; dim < ndims; dim++) { lua_rawgeti(L, 2, dim+1); @@ -925,7 +930,6 @@ static void torch_Tensor_(c_readSizeStride)(lua_State *L, int index, int allowSt static void torch_Tensor_(c_readTensorStorageSizeStride)(lua_State *L, int index, int allowNone, int allowTensor, int allowStorage, int allowStride, THStorage **storage_, long *storageOffset_, THLongStorage **size_, THLongStorage **stride_) { - static char errMsg[64]; THTensor *src = NULL; THStorage *storage = NULL; @@ -975,8 +979,14 @@ static void torch_Tensor_(c_readTensorStorageSizeStride)(lua_State *L, int index *storage_ = NULL; *storageOffset_ = 0; - sprintf(errMsg, "expecting number%s%s", (allowTensor ? " or Tensor" : ""), (allowStorage ? " or Storage" : "")); - luaL_argcheck(L, 0, index, errMsg); + if(allowTensor && allowStorage) + luaL_argcheck(L, 0, index, "expecting number or Tensor or Storage"); + else if(allowTensor) + luaL_argcheck(L, 0, index, "expecting number or Tensor"); + else if(allowStorage) + luaL_argcheck(L, 0, index, "expecting number or Storage"); + else + luaL_argcheck(L, 0, index, "expecting number"); } static int torch_Tensor_(apply)(lua_State *L) |