Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3a2556a8
提交
3a2556a8
authored
11月 25, 2020
作者:
Brandon T. Willard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make equal_computations support mixed NumPy/primitive inputs
上级
3635eacd
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
50 行增加
和
2 行删除
+50
-2
test_graph.py
tests/gof/test_graph.py
+22
-1
graph.py
theano/gof/graph.py
+28
-1
没有找到文件。
tests/gof/test_graph.py
浏览文件 @
3a2556a8
...
...
@@ -326,9 +326,30 @@ class TestAutoName:
def
test_equal_computations
():
# This was a bug report by a Theano user.
a
,
b
=
tensor
.
iscalars
(
2
)
with
pytest
.
raises
(
ValueError
):
equal_computations
([
a
],
[
a
,
b
])
assert
equal_computations
([
a
],
[
a
])
assert
equal_computations
([
tensor
.
as_tensor
(
1
)],
[
tensor
.
as_tensor
(
1
)])
assert
not
equal_computations
([
b
],
[
a
])
assert
not
equal_computations
([
tensor
.
as_tensor
(
1
)],
[
tensor
.
as_tensor
(
2
)])
assert
equal_computations
([
2
],
[
2
])
assert
equal_computations
([
np
.
r_
[
2
,
1
]],
[
np
.
r_
[
2
,
1
]])
assert
equal_computations
([
np
.
r_
[
2
,
1
]],
[
tensor
.
as_tensor
(
np
.
r_
[
2
,
1
])])
assert
equal_computations
([
tensor
.
as_tensor
(
np
.
r_
[
2
,
1
])],
[
np
.
r_
[
2
,
1
]])
assert
not
equal_computations
([
2
],
[
a
])
assert
not
equal_computations
([
np
.
r_
[
2
,
1
]],
[
a
])
assert
not
equal_computations
([
a
],
[
2
])
assert
not
equal_computations
([
a
],
[
np
.
r_
[
2
,
1
]])
c
=
tensor
.
type_other
.
NoneConst
assert
equal_computations
([
c
],
[
c
])
m
=
tensor
.
matrix
()
max_argmax1
=
tensor
.
max_and_argmax
(
m
)
max_argmax2
=
tensor
.
max_and_argmax
(
m
)
...
...
theano/gof/graph.py
浏览文件 @
3a2556a8
...
...
@@ -7,6 +7,8 @@ from collections import deque
from
copy
import
copy
from
itertools
import
count
import
numpy
as
np
import
theano
from
theano
import
config
from
theano.gof.utils
import
(
...
...
@@ -1420,14 +1422,37 @@ def equal_computations(xs, ys, in_xs=None, in_ys=None):
`ys`, but also represent subgraphs of a computational graph in `xs`
or `ys`.
Parameters
----------
xs : list of Variable
ys : list of Variable
Returns
-------
bool
"""
assert
len
(
xs
)
==
len
(
ys
)
if
len
(
xs
)
!=
len
(
ys
):
raise
ValueError
(
"The number of graphs/Variables in each argument must match."
)
if
in_xs
is
None
:
in_xs
=
[]
if
in_ys
is
None
:
in_ys
=
[]
for
x
,
y
in
zip
(
xs
,
ys
):
if
not
isinstance
(
x
,
Variable
)
and
not
isinstance
(
y
,
Variable
):
return
np
.
array_equal
(
x
,
y
)
if
not
isinstance
(
x
,
Variable
):
if
isinstance
(
y
,
Constant
):
return
np
.
array_equal
(
y
.
data
,
x
)
return
False
if
not
isinstance
(
y
,
Variable
):
if
isinstance
(
x
,
Constant
):
return
np
.
array_equal
(
x
.
data
,
y
)
return
False
if
not
isinstance
(
y
,
Variable
):
return
False
if
x
.
owner
and
not
y
.
owner
:
return
False
if
y
.
owner
and
not
x
.
owner
:
...
...
@@ -1437,8 +1462,10 @@ def equal_computations(xs, ys, in_xs=None, in_ys=None):
return
False
if
x
not
in
in_xs
and
x
.
type
!=
y
.
type
:
return
False
if
len
(
in_xs
)
!=
len
(
in_ys
):
return
False
for
_x
,
_y
in
zip
(
in_xs
,
in_ys
):
if
_x
.
type
!=
_y
.
type
:
return
False
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论