aboutsummaryrefslogtreecommitdiff
path: root/nerv/tnn/sutil.lua
diff options
context:
space:
mode:
authortxh18 <cloudygooseg@gmail.com>2015-12-03 12:48:49 +0800
committertxh18 <cloudygooseg@gmail.com>2015-12-03 12:48:49 +0800
commitbba82cac04474b8177ab45d41543bc993801a4e0 (patch)
tree4ec102da65f39d778b1ec9631a123540453b2158 /nerv/tnn/sutil.lua
parent63cd5b0ab0d2fd1693fdaec0e57b5e02ad718dfb (diff)
moved tnn to main nerv dir and added it to Makefile
Diffstat (limited to 'nerv/tnn/sutil.lua')
-rw-r--r--nerv/tnn/sutil.lua52
1 files changed, 52 insertions, 0 deletions
diff --git a/nerv/tnn/sutil.lua b/nerv/tnn/sutil.lua
new file mode 100644
index 0000000..f5bc408
--- /dev/null
+++ b/nerv/tnn/sutil.lua
@@ -0,0 +1,52 @@
+local Util = nerv.class("nerv.SUtil") --Scheduler Utility
+
+function Util.simple_split(inputstr, sep)
+ if sep == nil then
+ sep = "%s"
+ end
+ local t={} ; i=1
+ for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
+ t[i] = str
+ i = i + 1
+ end
+ return t
+end
+
+function Util.parse_schedule(str)
+ --parse a string like "1.2*10:1.5" to a list of numbers
+ local sch = {}
+ local s = Util.simple_split(str, ':')
+ for i = 1, #s do
+ local p = Util.simple_split(s[i], "%*")
+ if #p ~= 2 and #p ~= 1 then
+ nerv.error("nerv.SUtil:parse_schedule error, unit(%s) not proper, has %d components.", s[i], #p)
+ end
+ if p[2] == nil then
+ p[2] = "1"
+ end
+ p[1] = tonumber(p[1])
+ p[2] = tonumber(p[2])
+ for j = 1, p[2] do
+ table.insert(sch, p[1])
+ end
+ end
+
+ --for i = 1, #sch do
+ -- print(sch[i])
+ --end
+ return sch
+end
+
+function Util.sche_get(s, it)
+ --get s[it]
+ if s == nil then
+ nerv.info("Util.sche_get: warning, scheule is nil, returning zero...")
+ return 0
+ end
+ if #s >= it then
+ return s[it]
+ else
+ nerv.info("Util.sche_get: warning, it(%d) > #schedule(%d), returning the last one of schedule(%f)...", it, #s, s[#s])
+ return s[#s]
+ end
+end