aboutsummaryrefslogtreecommitdiff
path: root/nerv.lua
diff options
context:
space:
mode:
authorcloudygoose <[email protected]>2015-06-21 10:50:46 +0800
committercloudygoose <[email protected]>2015-06-21 10:50:46 +0800
commitad2c4013dec71667d6bbd5e9a249df2085208507 (patch)
tree474c536ff4a7d757bb61915a1bfc7a073f40d09f /nerv.lua
parent839d938df0d83ec311c5d1299923c667adff6a87 (diff)
parentf3f4e74eb4dbb8829e5ee136ba4b0c0a7938b551 (diff)
Merge upstream 'parameter update big-change'.
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'nerv.lua')
-rw-r--r--nerv.lua37
1 files changed, 32 insertions, 5 deletions
diff --git a/nerv.lua b/nerv.lua
index 467d926..a69dda6 100644
--- a/nerv.lua
+++ b/nerv.lua
@@ -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'