提交 bc362620 authored 作者: AlexLamb's avatar AlexLamb

Moved type check on keys to ensure that python2.7 and python3.3 have the same errors.

上级 8d5dd46f
......@@ -189,12 +189,14 @@ def function(inputs, outputs=None, mode=None, updates=None, givens=None,
if isinstance(outputs, dict):
output_items = outputs.items()
for item_pair in output_items:
assert isinstance(item_pair[0], basestring)
output_items_sorted = sorted(output_items)
output_keys = []
outputs = []
for pair in output_items_sorted:
assert isinstance(pair[0], basestring)
output_keys.append(pair[0])
outputs.append(pair[1])
......
......@@ -135,3 +135,25 @@ class dictionary_output_checker(unittest.TestCase):
assert result[0] == 5.0
assert result[1] == 10.0
assert result[2] == 15.0
def test_key_string_requirement(self):
'''
Tests that an exception is thrown if a non-string key is used in
the outputs dictionary.
'''
x = T.scalar('x')
try:
theano.function([x], outputs={1.0: x})
raise Exception("Did not throw exception with 1.0 as only key")
except AssertionError:
pass
try:
theano.function([x], outputs={1.0: x, "a": x**2})
raise Exception("Did not throw exception with 1.0 as one key")
except AssertionError:
pass
try:
theano.function([x], outputs={(1, "b"): x, 1.0: x**2})
raise Exception("Did not throw exception with tuple as key")
except AssertionError:
pass
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论