Permalink
Browse files

torch now complies with the new luaT API

  • Loading branch information...
1 parent 59f7533 commit 05a6d882c434de34963dad2bfa56797cf82b97a7 @andresy andresy committed Aug 13, 2012
Showing with 256 additions and 321 deletions.
  1. +8 −10 DiskFile.c
  2. +15 −35 File.c
  3. +9 −15 MemoryFile.c
  4. +5 −8 PipeFile.c
  5. +1 −11 Storage.c
  6. +2 −22 Tensor.c
  7. +17 −27 TensorMath.lua
  8. +1 −1 TensorOperator.c
  9. +15 −16 Timer.c
  10. +25 −27 generic/Storage.c
  11. +88 −92 generic/Tensor.c
  12. +14 −18 generic/TensorOperator.c
  13. +0 −3 init.c
  14. +0 −1 init.lua
  15. +55 −33 utils.c
  16. +1 −2 utils.h
View
@@ -1,21 +1,19 @@
#include "general.h"
-static const void* torch_DiskFile_id = NULL;
-
static int torch_DiskFile_new(lua_State *L)
{
const char *name = luaL_checkstring(L, 1);
const char *mode = luaL_optstring(L, 2, "r");
int isQuiet = luaT_optboolean(L, 3, 0);
THFile *self = THDiskFile_new(name, mode, isQuiet);
- luaT_pushudata(L, self, torch_DiskFile_id);
+ luaT_pushudata(L, self, "torch.DiskFile");
return 1;
}
static int torch_DiskFile_free(lua_State *L)
{
- THFile *self = luaT_checkudata(L, 1, torch_DiskFile_id);
+ THFile *self = luaT_checkudata(L, 1, "torch.DiskFile");
THFile_free(self);
return 0;
}
@@ -34,31 +32,31 @@ static int torch_DiskFile_isBigEndianCPU(lua_State *L)
static int torch_DiskFile_nativeEndianEncoding(lua_State *L)
{
- THFile *self = luaT_checkudata(L, 1, torch_DiskFile_id);
+ THFile *self = luaT_checkudata(L, 1, "torch.DiskFile");
THDiskFile_nativeEndianEncoding(self);
lua_settop(L, 1);
return 1;
}
static int torch_DiskFile_littleEndianEncoding(lua_State *L)
{
- THFile *self = luaT_checkudata(L, 1, torch_DiskFile_id);
+ THFile *self = luaT_checkudata(L, 1, "torch.DiskFile");
THDiskFile_littleEndianEncoding(self);
lua_settop(L, 1);
return 1;
}
static int torch_DiskFile_bigEndianEncoding(lua_State *L)
{
- THFile *self = luaT_checkudata(L, 1, torch_DiskFile_id);
+ THFile *self = luaT_checkudata(L, 1, "torch.DiskFile");
THDiskFile_bigEndianEncoding(self);
lua_settop(L, 1);
return 1;
}
static int torch_DiskFile___tostring__(lua_State *L)
{
- THFile *self = luaT_checkudata(L, 1, torch_DiskFile_id);
+ THFile *self = luaT_checkudata(L, 1, "torch.DiskFile");
lua_pushfstring(L, "torch.DiskFile on <%s> [status: %s -- mode %c%c]",
THDiskFile_name(self),
(THFile_isOpened(self) ? "open" : "closed"),
@@ -79,8 +77,8 @@ static const struct luaL_Reg torch_DiskFile__ [] = {
void torch_DiskFile_init(lua_State *L)
{
- torch_DiskFile_id = luaT_newmetatable(L, "torch.DiskFile", "torch.File",
- torch_DiskFile_new, torch_DiskFile_free, NULL);
+ luaT_newmetatable(L, "torch.DiskFile", "torch.File",
+ torch_DiskFile_new, torch_DiskFile_free, NULL);
luaL_register(L, NULL, torch_DiskFile__);
lua_pop(L, 1);
View
@@ -1,19 +1,10 @@
#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;
-
#define IMPLEMENT_TORCH_FILE_FLAG(NAME) \
static int torch_File_##NAME(lua_State *L) \
{ \
- THFile *self = luaT_checkudata(L, 1, torch_File_id); \
+ THFile *self = luaT_checkudata(L, 1, "torch.File"); \
lua_pushboolean(L, THFile_##NAME(self)); \
return 1; \
}
@@ -28,7 +19,7 @@ IMPLEMENT_TORCH_FILE_FLAG(hasError)
#define IMPLEMENT_TORCH_FILE_FUNC(NAME) \
static int torch_File_##NAME(lua_State *L) \
{ \
- THFile *self = luaT_checkudata(L, 1, torch_File_id); \
+ THFile *self = luaT_checkudata(L, 1, "torch.File"); \
THFile_##NAME(self); \
lua_settop(L, 1); \
return 1; \
@@ -46,7 +37,7 @@ IMPLEMENT_TORCH_FILE_FUNC(synchronize)
static int torch_File_seek(lua_State *L)
{
- THFile *self = luaT_checkudata(L, 1, torch_File_id);
+ THFile *self = luaT_checkudata(L, 1, "torch.File");
long position = luaL_checklong(L, 2)-1;
THFile_seek(self, position);
lua_settop(L, 1);
@@ -57,7 +48,7 @@ IMPLEMENT_TORCH_FILE_FUNC(seekEnd)
static int torch_File_position(lua_State *L)
{
- THFile *self = luaT_checkudata(L, 1, torch_File_id);
+ THFile *self = luaT_checkudata(L, 1, "torch.File");
lua_pushnumber(L, THFile_position(self)+1);
return 1;
}
@@ -67,7 +58,7 @@ IMPLEMENT_TORCH_FILE_FUNC(close)
#define IMPLEMENT_TORCH_FILE_RW(TYPEC, TYPE) \
static int torch_File_read##TYPEC(lua_State *L) \
{ \
- THFile *self = luaT_checkudata(L, 1, torch_File_id); \
+ THFile *self = luaT_checkudata(L, 1, "torch.File"); \
int narg = lua_gettop(L); \
\
if(narg == 1) \
@@ -83,15 +74,15 @@ IMPLEMENT_TORCH_FILE_FUNC(close)
long nread; \
\
TH##TYPEC##Storage *storage = TH##TYPEC##Storage_newWithSize(size); \
- luaT_pushudata(L, storage, torch_##TYPEC##Storage_id); \
+ luaT_pushudata(L, storage, "torch." #TYPEC "Storage"); \
nread = THFile_read##TYPEC(self, storage); \
if(nread != size) \
TH##TYPEC##Storage_resize(storage, size); \
return 1; \
} \
- else if(luaT_toudata(L, 2, torch_##TYPEC##Storage_id)) \
+ else if(luaT_toudata(L, 2, "torch." #TYPEC "Storage")) \
{ \
- TH##TYPEC##Storage *storage = luaT_toudata(L, 2, torch_##TYPEC##Storage_id); \
+ TH##TYPEC##Storage *storage = luaT_toudata(L, 2, "torch." #TYPEC "Storage"); \
lua_pushnumber(L, THFile_read##TYPEC(self, storage)); \
return 1; \
} \
@@ -103,7 +94,7 @@ IMPLEMENT_TORCH_FILE_FUNC(close)
\
static int torch_File_write##TYPEC(lua_State *L) \
{ \
- THFile *self = luaT_checkudata(L, 1, torch_File_id); \
+ THFile *self = luaT_checkudata(L, 1, "torch.File"); \
int narg = lua_gettop(L); \
\
if(narg == 2) \
@@ -114,9 +105,9 @@ IMPLEMENT_TORCH_FILE_FUNC(close)
THFile_write##TYPEC##Scalar(self, (TYPE)value); \
return 0; \
} \
- else if(luaT_toudata(L, 2, torch_##TYPEC##Storage_id)) \
+ else if(luaT_toudata(L, 2, "torch." #TYPEC "Storage")) \
{ \
- TH##TYPEC##Storage *storage = luaT_toudata(L, 2, torch_##TYPEC##Storage_id); \
+ TH##TYPEC##Storage *storage = luaT_toudata(L, 2, "torch." #TYPEC "Storage"); \
lua_pushnumber(L, THFile_write##TYPEC(self, storage)); \
return 1; \
} \
@@ -137,7 +128,7 @@ IMPLEMENT_TORCH_FILE_RW(Double, double)
static int torch_File_readString(lua_State *L)
{
- THFile *self = luaT_checkudata(L, 1, torch_File_id);
+ THFile *self = luaT_checkudata(L, 1, "torch.File");
const char *format = luaL_checkstring(L, 2);
char *str;
long size;
@@ -151,7 +142,7 @@ static int torch_File_readString(lua_State *L)
static int torch_File_writeString(lua_State *L)
{
- THFile *self = luaT_checkudata(L, 1, torch_File_id);
+ THFile *self = luaT_checkudata(L, 1, "torch.File");
const char *str = NULL;
size_t size;
@@ -195,7 +186,7 @@ static const struct luaL_Reg torch_File__ [] = {
{"writeFloat", torch_File_writeFloat},
{"writeDouble", torch_File_writeDouble},
{"writeString", torch_File_writeString},
-
+
{"synchronize", torch_File_synchronize},
{"seek", torch_File_seek},
{"seekEnd", torch_File_seekEnd},
@@ -207,18 +198,7 @@ static const struct luaL_Reg torch_File__ [] = {
void torch_File_init(lua_State *L)
{
- torch_File_id = luaT_newmetatable(L, "torch.File", NULL, NULL, NULL, NULL);
+ luaT_newmetatable(L, "torch.File", NULL, NULL, NULL, NULL);
luaL_register(L, NULL, torch_File__);
lua_pop(L, 1);
}
-
-void torch_File_init_storage_id(lua_State *L)
-{
- 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");
-}
View
@@ -1,12 +1,9 @@
#include "general.h"
-static const void* torch_MemoryFile_id;
-static const void* torch_CharStorage_id;
-
static int torch_MemoryFile_new(lua_State *L)
{
const char *mode;
- THCharStorage *storage = luaT_toudata(L, 1, torch_CharStorage_id);
+ THCharStorage *storage = luaT_toudata(L, 1, "torch.CharStorage");
THFile *self;
if(storage)
@@ -16,32 +13,32 @@ static int torch_MemoryFile_new(lua_State *L)
}
else
{
- mode = luaL_optstring(L, 1, "rw");
+ mode = luaL_optstring(L, 1, "rw");
self = THMemoryFile_new(mode);
}
- luaT_pushudata(L, self, torch_MemoryFile_id);
+ luaT_pushudata(L, self, "torch.MemoryFile");
return 1;
}
static int torch_MemoryFile_storage(lua_State *L)
{
- THFile *self = luaT_checkudata(L, 1, torch_MemoryFile_id);
+ THFile *self = luaT_checkudata(L, 1, "torch.MemoryFile");
THCharStorage_retain(THMemoryFile_storage(self));
- luaT_pushudata(L, THMemoryFile_storage(self), torch_CharStorage_id);
+ luaT_pushudata(L, THMemoryFile_storage(self), "torch.CharStorage");
return 1;
}
static int torch_MemoryFile_free(lua_State *L)
{
- THFile *self = luaT_checkudata(L, 1, torch_MemoryFile_id);
+ THFile *self = luaT_checkudata(L, 1, "torch.MemoryFile");
THFile_free(self);
return 0;
}
static int torch_MemoryFile___tostring__(lua_State *L)
{
- THFile *self = luaT_checkudata(L, 1, torch_MemoryFile_id);
+ THFile *self = luaT_checkudata(L, 1, "torch.MemoryFile");
lua_pushfstring(L, "torch.MemoryFile [status: %s -- mode: %c%c]",
(THFile_isOpened(self) ? "open" : "closed"),
(THFile_isReadable(self) ? 'r' : ' '),
@@ -57,11 +54,8 @@ static const struct luaL_Reg torch_MemoryFile__ [] = {
void torch_MemoryFile_init(lua_State *L)
{
- torch_CharStorage_id = luaT_checktypename2id(L, "torch.CharStorage");
-
- torch_MemoryFile_id = luaT_newmetatable(L, "torch.MemoryFile", "torch.File",
- torch_MemoryFile_new, torch_MemoryFile_free, NULL);
-
+ luaT_newmetatable(L, "torch.MemoryFile", "torch.File",
+ torch_MemoryFile_new, torch_MemoryFile_free, NULL);
luaL_register(L, NULL, torch_MemoryFile__);
lua_pop(L, 1);
}
View
@@ -1,28 +1,26 @@
#include "general.h"
-static const void* torch_PipeFile_id = NULL;
-
static int torch_PipeFile_new(lua_State *L)
{
const char *name = luaL_checkstring(L, 1);
const char *mode = luaL_optstring(L, 2, "r");
int isQuiet = luaT_optboolean(L, 3, 0);
THFile *self = THPipeFile_new(name, mode, isQuiet);
- luaT_pushudata(L, self, torch_PipeFile_id);
+ luaT_pushudata(L, self, "torch.PipeFile");
return 1;
}
static int torch_PipeFile_free(lua_State *L)
{
- THFile *self = luaT_checkudata(L, 1, torch_PipeFile_id);
+ THFile *self = luaT_checkudata(L, 1, "torch.PipeFile");
THFile_free(self);
return 0;
}
static int torch_PipeFile___tostring__(lua_State *L)
{
- THFile *self = luaT_checkudata(L, 1, torch_PipeFile_id);
+ THFile *self = luaT_checkudata(L, 1, "torch.PipeFile");
lua_pushfstring(L, "torch.PipeFile on <%s> [status: %s -- mode: %c%c]",
THDiskFile_name(self),
(THFile_isOpened(self) ? "open" : "closed"),
@@ -38,9 +36,8 @@ static const struct luaL_Reg torch_PipeFile__ [] = {
void torch_PipeFile_init(lua_State *L)
{
- torch_PipeFile_id = luaT_newmetatable(L, "torch.PipeFile", "torch.DiskFile",
- torch_PipeFile_new, torch_PipeFile_free, NULL);
-
+ luaT_newmetatable(L, "torch.PipeFile", "torch.DiskFile",
+ torch_PipeFile_new, torch_PipeFile_free, NULL);
luaL_register(L, NULL, torch_PipeFile__);
lua_pop(L, 1);
}
View
@@ -1,19 +1,9 @@
#include "general.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;
-
#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 TH_CONCAT_3(THFile_read, Real, Raw)
#define THFile_writeRealRaw TH_CONCAT_3(THFile_write, Real, Raw)
-#define STRING_torchStorage TH_CONCAT_STRING_3(torch.,Real,Storage)
+#define torch_Storage TH_CONCAT_STRING_3(torch.,Real,Storage)
#include "generic/Storage.c"
#include "THGenerateAllTypes.h"
View
@@ -1,29 +1,9 @@
#include "general.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_ByteTensor_id = NULL;
-static const void *torch_CharTensor_id = NULL;
-static const void *torch_ShortTensor_id = NULL;
-static const void *torch_IntTensor_id = NULL;
-static const void *torch_LongTensor_id = NULL;
-static const void *torch_FloatTensor_id = NULL;
-static const void *torch_DoubleTensor_id = NULL;
-
#define torch_Storage_(NAME) TH_CONCAT_4(torch_,Real,Storage_,NAME)
-#define torch_Storage_id TH_CONCAT_3(torch_,Real,Storage_id)
-#define STRING_torchStorage TH_CONCAT_STRING_3(torch.,Real,Storage)
+#define torch_Storage TH_CONCAT_STRING_3(torch.,Real,Storage)
#define torch_Tensor_(NAME) TH_CONCAT_4(torch_,Real,Tensor_,NAME)
-#define torch_Tensor_id TH_CONCAT_3(torch_,Real,Tensor_id)
-#define STRING_torchTensor TH_CONCAT_STRING_3(torch.,Real,Tensor)
+#define torch_Tensor TH_CONCAT_STRING_3(torch.,Real,Tensor)
#include "generic/Tensor.c"
#include "THGenerateAllTypes.h"
Oops, something went wrong.

0 comments on commit 05a6d88

Please sign in to comment.