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
diff options
context:
space:
mode:
authorRonan Collobert <ronan@collobert.com>2012-08-13 16:31:32 +0400
committerRonan Collobert <ronan@collobert.com>2012-08-13 16:31:32 +0400
commitdb2d8ae4769d20261c1d592097ad2edc6dc68508 (patch)
treef09937356f808e0d49dc856f216a4e3d12e2cd6f /Storage.c
parent0a74ee341fbc03cfa126bbecf26a7cab6fb1a8ba (diff)
cuda package now complies with the new luaT API
Diffstat (limited to 'Storage.c')
-rw-r--r--Storage.c63
1 files changed, 22 insertions, 41 deletions
diff --git a/Storage.c b/Storage.c
index dfc3516..933352c 100644
--- a/Storage.c
+++ b/Storage.c
@@ -2,16 +2,6 @@
#include "THFile.h"
#include "luaT.h"
-static const void *torch_File_id = NULL;
-static const void *torch_ByteStorage_id = NULL;
-static const void *torch_CharStorage_id = NULL;
-static const void *torch_ShortStorage_id = NULL;
-static const void *torch_IntStorage_id = NULL;
-static const void *torch_LongStorage_id = NULL;
-static const void *torch_FloatStorage_id = NULL;
-static const void *torch_DoubleStorage_id = NULL;
-static const void *torch_CudaStorage_id = NULL;
-
/* everything is as the generic Storage.c, except few things (see below) */
#define real float
@@ -19,7 +9,7 @@ static const void *torch_CudaStorage_id = NULL;
#define TH_GENERIC_FILE "generic/Storage.c"
#define torch_Storage_(NAME) TH_CONCAT_4(torch_,Real,Storage_,NAME)
-#define torch_Storage_id TH_CONCAT_3(torch_,Real,Storage_id)
+
#define THFile_readRealRaw(file, data, size) \
{ \
float *fdata = THAlloc(sizeof(float)*size); \
@@ -36,7 +26,7 @@ static const void *torch_CudaStorage_id = NULL;
THFree(fdata); \
}
-#define STRING_torchStorage TH_CONCAT_STRING_3(torch.,Real,Storage)
+#define torch_Storage TH_CONCAT_STRING_3(torch.,Real,Storage)
#include "generic/Storage.c"
@@ -49,25 +39,25 @@ static const void *torch_CudaStorage_id = NULL;
#define CUDA_IMPLEMENT_STORAGE_COPY(TYPEC) \
static int cutorch_##TYPEC##Storage_copy(lua_State *L) \
{ \
- TH##TYPEC##Storage *storage = luaT_checkudata(L, 1, torch_##TYPEC##Storage_id); \
+ TH##TYPEC##Storage *storage = luaT_checkudata(L, 1, "torch." #TYPEC "Storage"); \
void *src; \
- if( (src = luaT_toudata(L, 2, torch_##TYPEC##Storage_id)) ) \
+ if( (src = luaT_toudata(L, 2, "torch." #TYPEC "Storage")) ) \
TH##TYPEC##Storage_copy(storage, src); \
- else if( (src = luaT_toudata(L, 2, torch_ByteStorage_id)) ) \
+ else if( (src = luaT_toudata(L, 2, "torch.ByteStorage")) ) \
TH##TYPEC##Storage_copyByte(storage, src); \
- else if( (src = luaT_toudata(L, 2, torch_CharStorage_id)) ) \
+ else if( (src = luaT_toudata(L, 2, "torch.CharStorage")) ) \
TH##TYPEC##Storage_copyChar(storage, src); \
- else if( (src = luaT_toudata(L, 2, torch_ShortStorage_id)) ) \
+ else if( (src = luaT_toudata(L, 2, "torch.ShortStorage")) ) \
TH##TYPEC##Storage_copyShort(storage, src); \
- else if( (src = luaT_toudata(L, 2, torch_IntStorage_id)) ) \
+ else if( (src = luaT_toudata(L, 2, "torch.IntStorage")) ) \
TH##TYPEC##Storage_copyInt(storage, src); \
- else if( (src = luaT_toudata(L, 2, torch_LongStorage_id)) ) \
+ else if( (src = luaT_toudata(L, 2, "torch.LongStorage")) ) \
TH##TYPEC##Storage_copyLong(storage, src); \
- else if( (src = luaT_toudata(L, 2, torch_FloatStorage_id)) ) \
+ else if( (src = luaT_toudata(L, 2, "torch.FloatStorage")) ) \
TH##TYPEC##Storage_copyFloat(storage, src); \
- else if( (src = luaT_toudata(L, 2, torch_DoubleStorage_id)) ) \
+ else if( (src = luaT_toudata(L, 2, "torch.DoubleStorage")) ) \
TH##TYPEC##Storage_copyDouble(storage, src); \
- else if( (src = luaT_toudata(L, 2, torch_CudaStorage_id)) ) \
+ else if( (src = luaT_toudata(L, 2, "torch.CudaStorage")) ) \
TH##TYPEC##Storage_copyCuda(storage, src); \
else \
luaL_typerror(L, 2, "torch.*Storage"); \
@@ -87,15 +77,6 @@ CUDA_IMPLEMENT_STORAGE_COPY(Cuda)
void cutorch_CudaStorage_init(lua_State* L)
{
- /* the ids */
- torch_ByteStorage_id = luaT_checktypename2id(L, "torch.ByteStorage");
- torch_CharStorage_id = luaT_checktypename2id(L, "torch.CharStorage");
- torch_ShortStorage_id = luaT_checktypename2id(L, "torch.ShortStorage");
- torch_IntStorage_id = luaT_checktypename2id(L, "torch.IntStorage");
- torch_LongStorage_id = luaT_checktypename2id(L, "torch.LongStorage");
- torch_FloatStorage_id = luaT_checktypename2id(L, "torch.FloatStorage");
- torch_DoubleStorage_id = luaT_checktypename2id(L, "torch.DoubleStorage");
-
/* the standard stuff */
torch_CudaStorage_init(L);
@@ -103,15 +84,15 @@ void cutorch_CudaStorage_init(lua_State* L)
{
int i;
- const void* ids[8] = {torch_ByteStorage_id,
- torch_CharStorage_id,
- torch_ShortStorage_id,
- torch_IntStorage_id,
- torch_LongStorage_id,
- torch_FloatStorage_id,
- torch_DoubleStorage_id,
- torch_CudaStorage_id};
-
+ const void* tnames[8] = {"torch.ByteStorage",
+ "torch.CharStorage",
+ "torch.ShortStorage",
+ "torch.IntStorage",
+ "torch.LongStorage",
+ "torch.FloatStorage",
+ "torch.DoubleStorage",
+ "torch.CudaStorage"};
+
static int (*funcs[8])(lua_State*) = {cutorch_ByteStorage_copy,
cutorch_CharStorage_copy,
cutorch_ShortStorage_copy,
@@ -123,7 +104,7 @@ void cutorch_CudaStorage_init(lua_State* L)
for(i = 0; i < 8; i++)
{
- luaT_pushmetaclass(L, ids[i]);
+ luaT_pushmetatable(L, tnames[i]);
lua_pushcfunction(L, funcs[i]);
lua_setfield(L, -2, "copy");
lua_pop(L, 1);