Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/xlua.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Zagoruyko <zagoruyko2@gmail.com>2016-02-18 17:18:55 +0300
committerSergey Zagoruyko <zagoruyko2@gmail.com>2016-02-18 17:18:55 +0300
commitf14d91cd23c0b1d1d9c555021d5ae7dd6d7c11ab (patch)
tree8e7d560284230fd3ab61f785dd55c381b5ab4c4b
parent3c1d3c9aaa4f7c0c2ad84ae54a154eee596019c0 (diff)
envparams
-rw-r--r--init.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/init.lua b/init.lua
index 7e59d34..838362f 100644
--- a/init.lua
+++ b/init.lua
@@ -720,4 +720,34 @@ function string.tosymbol(str)
end
end
+
+--------------------------------------------------------------------------------
+-- parses arguments passed as ENV variables
+-- example:
+-- learningRate=1e-3 nesterov=false th train.lua
+-- opt = xlua.envparams{learningRate=1e-2, nesterov=true}
+--------------------------------------------------------------------------------
+function xlua.envparams(default)
+ local params = {}
+ for k, v in pairs(default) do
+ params[k] = v
+ if os.getenv(k) ~= nil then
+ local v_new = os.getenv(k)
+ if type(v) == "number" then
+ v_new = tonumber(v_new)
+ end
+ if type(v) == "boolean" then
+ if v_new == "false" or v_new == "False" then
+ v_new = false
+ elseif v_new == "true" or v_new == "True" then
+ v_new = true
+ end
+ end
+ assert(v_new ~= nil)
+ params[k] = v_new
+ end
+ end
+ return params
+end
+
return xlua