Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2692a34a
提交
2692a34a
authored
9月 14, 2012
作者:
Matthew Rocklin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add function to give variables unique names
上级
00183e72
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
42 行增加
和
7 行删除
+42
-7
test_utils.py
theano/gof/tests/test_utils.py
+11
-0
utils.py
theano/gof/utils.py
+31
-7
没有找到文件。
theano/gof/tests/test_utils.py
0 → 100644
浏览文件 @
2692a34a
import
theano
from
theano.gof.utils
import
give_variables_names
,
unique
def
test_variables_with_names
():
x
=
theano
.
tensor
.
matrix
(
'x'
)
y
=
x
+
1
z
=
theano
.
tensor
.
dot
(
x
,
y
)
variables
=
{
x
,
y
,
z
}
give_variables_names
(
variables
)
assert
all
(
var
.
name
for
var
in
variables
)
assert
unique
([
var
.
name
for
var
in
variables
])
theano/gof/utils.py
浏览文件 @
2692a34a
...
...
@@ -7,7 +7,7 @@ import re, os, traceback
def
add_tag_trace
(
thing
):
"""Add tag.trace to an node or variable.
The argument is returned after being affected (inplace).
"""
limit
=
config
.
traceback
.
limit
...
...
@@ -20,7 +20,7 @@ def hashgen():
return
hashgen
.
next
hashgen
.
next
=
0
class
MethodNotDefined
(
Exception
):
class
MethodNotDefined
(
Exception
):
"""
To be raised by functions defined as part of an interface.
...
...
@@ -78,7 +78,7 @@ def memoize(f):
def
deprecated
(
filename
,
msg
=
''
):
"""Decorator which will print a warning message on the first call.
Use it like this:
@deprecated('myfile', 'do something different...')
...
...
@@ -107,9 +107,9 @@ def uniq(seq):
def
difference
(
seq1
,
seq2
):
"""
Returns all elements in seq1 which are not in seq2: i.e seq1
\
seq2
Returns all elements in seq1 which are not in seq2: i.e seq1
\
seq2
"""
try
:
try
:
# try to use O(const * len(seq1)) algo
if
len
(
seq2
)
<
4
:
# I'm guessing this threshold -JB
raise
Exception
(
'not worth it'
)
...
...
@@ -131,7 +131,7 @@ def partition(f, seq):
else
:
seqf
.
append
(
elem
)
return
seqt
,
seqf
def
attr_checker
(
*
attrs
):
def
f
(
candidate
):
for
attr
in
attrs
:
...
...
@@ -204,7 +204,7 @@ def toposort(prereqs_d):
# for x, y in prereqs_d.items():
# all2.update(y)
# print all1.difference(all2)
seq
=
[]
done
=
set
()
postreqs_d
=
{}
...
...
@@ -330,3 +330,27 @@ def flatten(a):
return
l
else
:
return
[
a
]
def
unique
(
x
):
return
len
(
set
(
x
))
==
len
(
x
)
def
hist
(
coll
):
counts
=
{}
for
elem
in
coll
:
counts
[
elem
]
=
counts
.
get
(
elem
,
0
)
+
1
return
counts
def
give_variables_names
(
variables
):
""" Gives unique names to an iterable of variables. Modifies input."""
names
=
map
(
lambda
var
:
var
.
name
,
variables
)
h
=
hist
(
names
)
bad_var
=
lambda
var
:
h
[
var
.
name
]
>
1
for
i
,
var
in
enumerate
(
filter
(
bad_var
,
variables
)):
var
.
name
=
(
var
.
name
or
""
)
+
"_
%
d"
%
i
if
not
unique
(
map
(
str
,
variables
)):
raise
ValueError
(
"Not all variables have unique names."
"Maybe you've named some of the variables identically"
)
return
variables
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论