提交 353ae858 authored 作者: Matthew Rocklin's avatar Matthew Rocklin

add idempotent note and test

上级 970ecbbc
...@@ -10,6 +10,19 @@ def test_give_variables_names(): ...@@ -10,6 +10,19 @@ def test_give_variables_names():
assert all(var.name for var in variables) assert all(var.name for var in variables)
assert unique([var.name for var in variables]) assert unique([var.name for var in variables])
def test_give_variables_names_idempotence():
x = theano.tensor.matrix('x')
y = x + 1
z = theano.tensor.dot(x, y)
variables = (x, y, z)
give_variables_names(variables)
names = [var.name for var in variables]
give_variables_names(variables)
names2 = [var.name for var in variables]
assert names == names2
def test_give_variables_names_small(): def test_give_variables_names_small():
x = theano.tensor.matrix('x') x = theano.tensor.matrix('x')
y = theano.tensor.dot(x, x) y = theano.tensor.dot(x, x)
......
...@@ -341,7 +341,9 @@ def hist(coll): ...@@ -341,7 +341,9 @@ def hist(coll):
return counts return counts
def give_variables_names(variables): def give_variables_names(variables):
""" Gives unique names to an iterable of variables. Modifies input.""" """ Gives unique names to an iterable of variables. Modifies input.
This function is idempotent."""
names = map(lambda var: var.name, variables) names = map(lambda var: var.name, variables)
h = hist(names) h = hist(names)
bad_var = lambda var: not var.name or h[var.name] > 1 bad_var = lambda var: not var.name or h[var.name] > 1
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论