提交 16474203 authored 作者: AdeB's avatar AdeB

raise an error if the user provides an unknown flag

上级 fbb9a5ac
...@@ -11,7 +11,7 @@ import socket ...@@ -11,7 +11,7 @@ import socket
import theano import theano
from theano.configparser import (AddConfigVar, BoolParam, ConfigParam, EnumStr, from theano.configparser import (AddConfigVar, BoolParam, ConfigParam, EnumStr,
FloatParam, IntParam, StrParam, FloatParam, IntParam, StrParam,
TheanoConfigParser) TheanoConfigParser, THEANO_FLAGS_DICT)
from theano.gof.compiledir import (local_bitwidth, python_int_bitwidth, from theano.gof.compiledir import (local_bitwidth, python_int_bitwidth,
gcc_version_str) gcc_version_str)
from theano.misc.cpucount import cpuCount from theano.misc.cpucount import cpuCount
...@@ -1396,4 +1396,7 @@ AddConfigVar( ...@@ -1396,4 +1396,7 @@ AddConfigVar(
allow_override=False), allow_override=False),
in_c_key=False) in_c_key=False)
# Check if there are remaining flags provided by the user through THEANO_FLAGS.
if THEANO_FLAGS_DICT:
raise ValueError('theano does not recognise this flag: {}'
.format(THEANO_FLAGS_DICT.keys()[0]))
...@@ -124,7 +124,7 @@ def change_flags(**kwargs): ...@@ -124,7 +124,7 @@ def change_flags(**kwargs):
return change_flags_exec return change_flags_exec
def fetch_val_for_key(key): def fetch_val_for_key(key, delete_key=False):
"""Return the overriding config value for a key. """Return the overriding config value for a key.
A successful search returns a string value. A successful search returns a string value.
An unsuccessful search raises a KeyError An unsuccessful search raises a KeyError
...@@ -137,6 +137,8 @@ def fetch_val_for_key(key): ...@@ -137,6 +137,8 @@ def fetch_val_for_key(key):
# first try to find it in the FLAGS # first try to find it in the FLAGS
try: try:
if delete_key:
return THEANO_FLAGS_DICT.pop(key, None)
return THEANO_FLAGS_DICT[key] return THEANO_FLAGS_DICT[key]
except KeyError: except KeyError:
pass pass
...@@ -310,7 +312,7 @@ class ConfigParam(object): ...@@ -310,7 +312,7 @@ class ConfigParam(object):
return self return self
if not hasattr(self, 'val'): if not hasattr(self, 'val'):
try: try:
val_str = fetch_val_for_key(self.fullname) val_str = fetch_val_for_key(self.fullname, delete_key=True)
self.is_default = False self.is_default = False
except KeyError: except KeyError:
if callable(self.default): if callable(self.default):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论