diff options
author | Determinant <[email protected]> | 2015-05-22 10:26:12 +0800 |
---|---|---|
committer | Determinant <[email protected]> | 2015-05-22 10:26:12 +0800 |
commit | 8f18aaba322cf717b8805ebfcacb5a3108d3dda8 (patch) | |
tree | 366b86e2be668da0cf0a7ae430d5d161145b4c16 /matrix/init.c | |
parent | 7503135d355275a17128f8a4c897739669fcd646 (diff) |
add base class CuMatrix for CuMatrixFloat and CuMatrixDouble
Diffstat (limited to 'matrix/init.c')
-rw-r--r-- | matrix/init.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/matrix/init.c b/matrix/init.c index 297f6af..e55558a 100644 --- a/matrix/init.c +++ b/matrix/init.c @@ -2,10 +2,13 @@ #include "generic/matrix.h" const char *nerv_matrix_tname = "nerv.Matrix"; -void nerv_matrix_float_host_init(lua_State *L); -void nerv_matrix_float_cuda_init(lua_State *L); -void nerv_matrix_double_host_init(lua_State *L); -void nerv_matrix_double_cuda_init(lua_State *L); +const char *nerv_matrix_cuda_tname = "nerv.CuMatrix"; +const char *nerv_matrix_host_tname = "nerv.MMatrix"; + +void nerv_matrix_host_float_init(lua_State *L); +void nerv_matrix_cuda_float_init(lua_State *L); +void nerv_matrix_host_double_init(lua_State *L); +void nerv_matrix_cuda_double_init(lua_State *L); static const luaL_Reg matrix_methods[] = { {"__tostring__", nerv_error_method_not_implemented }, @@ -16,12 +19,20 @@ static const luaL_Reg matrix_methods[] = { }; void nerv_matrix_init(lua_State *L) { - /* abstract class */ + /* abstract base class: Matrix */ luaT_newmetatable(L, nerv_matrix_tname, NULL, NULL, NULL, NULL); luaL_register(L, NULL, matrix_methods); lua_pop(L, 1); - nerv_matrix_float_host_init(L); - nerv_matrix_float_cuda_init(L); - nerv_matrix_double_host_init(L); - nerv_matrix_double_cuda_init(L); + + /* CuMatrix inherits from Matrix */ + luaT_newmetatable(L, nerv_matrix_cuda_tname, nerv_matrix_tname, + NULL, NULL, NULL); + nerv_matrix_cuda_float_init(L); + nerv_matrix_cuda_double_init(L); + + /* MMatrix inherits from Matrix */ + luaT_newmetatable(L, nerv_matrix_host_tname, nerv_matrix_tname, + NULL, NULL, NULL); + nerv_matrix_host_float_init(L); + nerv_matrix_host_double_init(L); } |