--- NERV: a Lua-based toolkit for high-performance deep learning.
-- This file contains misc utility functions of NERV and finally initializes
-- NERV by including `init.lua` of other basic modules.
-- @author Ted Yin <ted.sybil@gmail.com>
-- @module nerv
require 'libnerv'
--- Dummy function.
-- Display a friendly error message when user attempts to invoke a
-- non-implemented function.
function nerv.error_method_not_implemented()
nerv.error("method not implemented");
end
function nerv.set_logfile(filename)
nerv._logfile = io.open(filename, "w")
end
--- Format a string just like `sprintf` in C.
-- @param fmt the format string
-- @param ... args, the data to be formatted
-- @return the formatted string
function nerv.sprintf(fmt, ...)
return string.format(fmt, ...)
end
--- Print a formatted string to stdout.
-- @param fmt the format string
-- @param ... args, the data to be formatted
function nerv.printf(fmt, ...)
local line = nerv.sprintf(fmt, ...)
io.stderr:write(line)
-- duplicate the all output to the log file, if set
if nerv._logfile then
nerv._logfile:write(line)
nerv._logfile:flush()
end
end
--- Raise an global error with the formatted message.
-- @param fmt the format string
-- @param ... args, the data to be formatted
function nerv.error(fmt, ...)
error(nerv.sprintf("[nerv] internal error: " .. fmt .. "\n", ...))
end
--- Print a notification message that begins with "info" and a timestamp.
-- Instead of using `nerv.printf`, normal users should use this to print any
-- notification information.
-- @param fmt the format string
-- @param ... args, the data to be formatted
function nerv.info(fmt, ...)
nerv.printf(
string.format("(%s)[nerv] info: %s