diff options
author | Determinant <[email protected]> | 2015-06-20 20:00:25 +0800 |
---|---|---|
committer | Determinant <[email protected]> | 2015-06-20 20:00:25 +0800 |
commit | f3f4e74eb4dbb8829e5ee136ba4b0c0a7938b551 (patch) | |
tree | 8beb12182020267ce32904d646ad0c736c27dcd2 /nerv.lua | |
parent | 2ab9610a4fff798c1668cdc041515256fa813865 (diff) |
change concept of ParamRepo; provide generalized param update; code clean-up; #25 #26 #27 #29
Diffstat (limited to 'nerv.lua')
-rw-r--r-- | nerv.lua | 37 |
1 files changed, 32 insertions, 5 deletions
@@ -1,20 +1,35 @@ require 'libnerv' -nerv.utils = require 'pl.utils' function nerv.error(fmt, ...) - error(nerv.utils.printf("[nerv] internal error: " .. fmt .. "\n", ...)) + error(nerv.printf("[nerv] internal error: " .. fmt .. "\n", ...)) end function nerv.error_method_not_implemented() nerv.error("method not implemented"); end +function nerv.printf(fmt, ...) + io.write(string.format(fmt, ...)) +end + +function nerv.mesg_with_timestamp(fmt, ...) + nerv.printf( + string.format("(%s)[nerv] info: %s\n", + os.date("%H:%M:%S %F"), fmt), ...) +end + function nerv.info(fmt, ...) - nerv.utils.printf( + nerv.printf( string.format("(%s)[nerv] info: %s\n", os.date("%H:%M:%S %F"), fmt), ...) end +function nerv.warning(fmt, ...) + nerv.printf( + string.format("(%s)[nerv] warning: %s\n", + os.date("%H:%M:%S %F"), fmt), ...) +end + -- Torch C API wrapper function nerv.class(tname, parenttname) @@ -77,8 +92,20 @@ function table.tostring(tbl) return "{" .. table.concat(result, ",") .. "}" end -function nerv.get_type(typename) - return assert(loadstring("return " .. typename))() +function nerv.get_type(tname) + return assert(loadstring("return " .. tname))() +end + +function nerv.is_type(obj, tname) + local mt0 = nerv.getmetatable(tname) + local mt = getmetatable(obj) + while mt do + if mt == mt0 then + return true + end + mt = getmetatable(mt) + end + return false end require 'matrix.init' |