Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0344f1a8
提交
0344f1a8
authored
2月 06, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
2月 06, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove pointless print statements and some evaluations
上级
616f8d26
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
5 行增加
和
26 行删除
+5
-26
test_math_opt.py
tests/tensor/test_math_opt.py
+5
-26
没有找到文件。
tests/tensor/test_math_opt.py
浏览文件 @
0344f1a8
...
@@ -174,23 +174,19 @@ class TestGreedyDistribute:
...
@@ -174,23 +174,19 @@ class TestGreedyDistribute:
# 1. ((a/x + b/y) * x * y) --> a*y + b*x
# 1. ((a/x + b/y) * x * y) --> a*y + b*x
e
=
(
a
/
z
+
b
/
x
)
*
x
*
z
e
=
(
a
/
z
+
b
/
x
)
*
x
*
z
g
=
FunctionGraph
([
a
,
b
,
c
,
d
,
x
,
y
,
z
],
[
e
])
g
=
FunctionGraph
([
a
,
b
,
c
,
d
,
x
,
y
,
z
],
[
e
])
# print pprint(g.outputs[0])
mul_canonizer
.
optimize
(
g
)
mul_canonizer
.
optimize
(
g
)
TopoOptimizer
(
TopoOptimizer
(
LocalOptGroup
(
local_greedy_distributor
),
order
=
"out_to_in"
LocalOptGroup
(
local_greedy_distributor
),
order
=
"out_to_in"
)
.
optimize
(
g
)
)
.
optimize
(
g
)
# print pprint(g.outputs[0])
assert
str
(
pprint
(
g
.
outputs
[
0
]))
==
"((a * x) + (b * z))"
assert
str
(
pprint
(
g
.
outputs
[
0
]))
==
"((a * x) + (b * z))"
# 2. ((a/x + b) * x) --> a + b*x
# 2. ((a/x + b) * x) --> a + b*x
e
=
(
a
/
x
+
b
)
*
x
e
=
(
a
/
x
+
b
)
*
x
g
=
FunctionGraph
([
a
,
b
,
x
],
[
e
])
g
=
FunctionGraph
([
a
,
b
,
x
],
[
e
])
# print pprint(g.outputs[0])
mul_canonizer
.
optimize
(
g
)
mul_canonizer
.
optimize
(
g
)
TopoOptimizer
(
TopoOptimizer
(
LocalOptGroup
(
local_greedy_distributor
),
order
=
"out_to_in"
LocalOptGroup
(
local_greedy_distributor
),
order
=
"out_to_in"
)
.
optimize
(
g
)
)
.
optimize
(
g
)
# print pprint(g.outputs[0])
assert
str
(
pprint
(
g
.
outputs
[
0
]))
==
"(a + (b * x))"
assert
str
(
pprint
(
g
.
outputs
[
0
]))
==
"(a + (b * x))"
def
test_kording_bug
(
self
):
def
test_kording_bug
(
self
):
...
@@ -233,9 +229,7 @@ class TestAlgebraicCanonize:
...
@@ -233,9 +229,7 @@ class TestAlgebraicCanonize:
# e = (x / x) * (y / y)
# e = (x / x) * (y / y)
e
=
(
-
1
*
x
)
/
y
/
(
-
2
*
z
)
e
=
(
-
1
*
x
)
/
y
/
(
-
2
*
z
)
g
=
FunctionGraph
([
x
,
y
,
z
,
a
,
b
,
c
,
d
],
[
e
])
g
=
FunctionGraph
([
x
,
y
,
z
,
a
,
b
,
c
,
d
],
[
e
])
print
(
pprint
(
g
.
outputs
[
0
]))
mul_canonizer
.
optimize
(
g
)
mul_canonizer
.
optimize
(
g
)
print
(
pprint
(
g
.
outputs
[
0
]))
def
test_elemwise_multiple_inputs_optimisation
(
self
):
def
test_elemwise_multiple_inputs_optimisation
(
self
):
# verify that the AlgebraicCanonizer merge sequential Elemwise({mul,add}) part 1
# verify that the AlgebraicCanonizer merge sequential Elemwise({mul,add}) part 1
...
@@ -856,8 +850,6 @@ class TestAlgebraicCanonize:
...
@@ -856,8 +850,6 @@ class TestAlgebraicCanonize:
mode
=
get_default_mode
()
.
excluding
(
"local_elemwise_fusion"
)
mode
=
get_default_mode
()
.
excluding
(
"local_elemwise_fusion"
)
f
=
function
([
x
],
[(
4
*
x
)
/
abs
(
2
*
x
)],
mode
=
mode
)
f
=
function
([
x
],
[(
4
*
x
)
/
abs
(
2
*
x
)],
mode
=
mode
)
print
(
f
.
maker
.
fgraph
.
toposort
())
print
()
f
(
0.1
)
f
(
0.1
)
f
(
-
1
)
f
(
-
1
)
# some stabilization optimization make the output be finite instead of nan
# some stabilization optimization make the output be finite instead of nan
...
@@ -869,8 +861,6 @@ class TestAlgebraicCanonize:
...
@@ -869,8 +861,6 @@ class TestAlgebraicCanonize:
assert
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
==
sgn
assert
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
==
sgn
f
=
function
([
x
],
[(
4
*
x
)
/
abs
(
x
/
2
)],
mode
=
mode
)
f
=
function
([
x
],
[(
4
*
x
)
/
abs
(
x
/
2
)],
mode
=
mode
)
print
(
f
.
maker
.
fgraph
.
toposort
())
print
()
f
(
0.1
)
f
(
0.1
)
f
(
-
1
)
f
(
-
1
)
# some stabilization optimization make the output be finite instead of nan
# some stabilization optimization make the output be finite instead of nan
...
@@ -1038,7 +1028,6 @@ def test_cast_in_mul_canonizer():
...
@@ -1038,7 +1028,6 @@ def test_cast_in_mul_canonizer():
o2
=
e
*
go
o2
=
e
*
go
mode
=
get_default_mode
()
.
excluding
(
"fusion"
)
.
including
(
"fast_run"
)
mode
=
get_default_mode
()
.
excluding
(
"fusion"
)
.
including
(
"fast_run"
)
f
=
function
([
x
,
y
],
[
o1
,
o2
],
mode
=
mode
)
f
=
function
([
x
,
y
],
[
o1
,
o2
],
mode
=
mode
)
aesara
.
printing
.
debugprint
(
f
,
print_type
=
True
)
nodes
=
f
.
maker
.
fgraph
.
apply_nodes
nodes
=
f
.
maker
.
fgraph
.
apply_nodes
assert
(
assert
(
len
(
len
(
...
@@ -1992,6 +1981,7 @@ class TestLocalUselessElemwiseComparison:
...
@@ -1992,6 +1981,7 @@ class TestLocalUselessElemwiseComparison:
self
.
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
self
.
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
def
test_local_useless_elemwise_comparison
(
self
):
def
test_local_useless_elemwise_comparison
(
self
):
# TODO FIXME: This is not a real test!
# TODO: test each case individually.
# TODO: test each case individually.
# The following case is what made me discover those cases.
# The following case is what made me discover those cases.
X
=
matrix
(
"X"
)
X
=
matrix
(
"X"
)
...
@@ -2667,19 +2657,17 @@ class TestLocalErf:
...
@@ -2667,19 +2657,17 @@ class TestLocalErf:
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
erfc
erfc
],
f
.
maker
.
fgraph
.
toposort
()
],
f
.
maker
.
fgraph
.
toposort
()
print
(
f
(
val
)
)
f
(
val
)
f
=
function
([
x
],
1
+
(
-
erf
(
x
)),
mode
=
self
.
mode
)
f
=
function
([
x
],
1
+
(
-
erf
(
x
)),
mode
=
self
.
mode
)
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
erfc
erfc
],
f
.
maker
.
fgraph
.
toposort
()
],
f
.
maker
.
fgraph
.
toposort
()
print
(
f
(
val
))
f
=
function
([
x
],
(
-
erf
(
x
))
+
1
,
mode
=
self
.
mode
)
f
=
function
([
x
],
(
-
erf
(
x
))
+
1
,
mode
=
self
.
mode
)
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
erfc
erfc
],
f
.
maker
.
fgraph
.
toposort
()
],
f
.
maker
.
fgraph
.
toposort
()
print
(
f
(
val
))
f
=
function
([
x
],
2
-
erf
(
x
),
mode
=
self
.
mode
)
f
=
function
([
x
],
2
-
erf
(
x
),
mode
=
self
.
mode
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
...
@@ -2689,7 +2677,6 @@ class TestLocalErf:
...
@@ -2689,7 +2677,6 @@ class TestLocalErf:
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
aes
.
Add
)
or
isinstance
(
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
aes
.
Add
)
or
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
aes
.
Sub
topo
[
1
]
.
op
.
scalar_op
,
aes
.
Sub
),
f
.
maker
.
fgraph
.
toposort
()
),
f
.
maker
.
fgraph
.
toposort
()
print
(
f
(
val
))
def
test_local_erf_minus_one
(
self
):
def
test_local_erf_minus_one
(
self
):
val
=
np
.
asarray
([
-
30
,
-
3
,
-
2
,
-
1
,
0
,
1
,
2
,
3
,
30
],
dtype
=
config
.
floatX
)
val
=
np
.
asarray
([
-
30
,
-
3
,
-
2
,
-
1
,
0
,
1
,
2
,
3
,
30
],
dtype
=
config
.
floatX
)
...
@@ -2697,15 +2684,13 @@ class TestLocalErf:
...
@@ -2697,15 +2684,13 @@ class TestLocalErf:
f
=
function
([
x
],
erf
(
x
)
-
1
,
mode
=
self
.
mode
)
f
=
function
([
x
],
erf
(
x
)
-
1
,
mode
=
self
.
mode
)
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
erfc
,
mul
]
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
erfc
,
mul
]
print
(
f
(
val
)
)
f
(
val
)
f
=
function
([
x
],
erf
(
x
)
+
(
-
1
),
mode
=
self
.
mode
)
f
=
function
([
x
],
erf
(
x
)
+
(
-
1
),
mode
=
self
.
mode
)
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
erfc
,
mul
]
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
erfc
,
mul
]
print
(
f
(
val
))
f
=
function
([
x
],
-
1
+
erf
(
x
),
mode
=
self
.
mode
)
f
=
function
([
x
],
-
1
+
erf
(
x
),
mode
=
self
.
mode
)
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
erfc
,
mul
]
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
erfc
,
mul
]
print
(
f
(
val
))
f
=
function
([
x
],
erf
(
x
)
-
2
,
mode
=
self
.
mode
)
f
=
function
([
x
],
erf
(
x
)
-
2
,
mode
=
self
.
mode
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
...
@@ -2715,7 +2700,6 @@ class TestLocalErf:
...
@@ -2715,7 +2700,6 @@ class TestLocalErf:
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
aes
.
Add
)
or
isinstance
(
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
aes
.
Add
)
or
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
aes
.
Sub
topo
[
1
]
.
op
.
scalar_op
,
aes
.
Sub
)
)
print
(
f
(
val
))
@pytest.mark.skipif
(
@pytest.mark.skipif
(
...
@@ -2743,13 +2727,12 @@ class TestLocalErfc:
...
@@ -2743,13 +2727,12 @@ class TestLocalErfc:
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
erf
erf
],
f
.
maker
.
fgraph
.
toposort
()
],
f
.
maker
.
fgraph
.
toposort
()
print
(
f
(
val
)
)
f
(
val
)
f
=
function
([
x
],
(
-
erfc
(
x
))
+
1
,
mode
=
self
.
mode
)
f
=
function
([
x
],
(
-
erfc
(
x
))
+
1
,
mode
=
self
.
mode
)
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
erf
erf
],
f
.
maker
.
fgraph
.
toposort
()
],
f
.
maker
.
fgraph
.
toposort
()
print
(
f
(
val
))
f
=
function
([
x
],
2
-
erfc
(
x
),
mode
=
self
.
mode
)
f
=
function
([
x
],
2
-
erfc
(
x
),
mode
=
self
.
mode
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
...
@@ -2757,11 +2740,9 @@ class TestLocalErfc:
...
@@ -2757,11 +2740,9 @@ class TestLocalErfc:
assert
topo
[
0
]
.
op
==
erfc
,
f
.
maker
.
fgraph
.
toposort
()
assert
topo
[
0
]
.
op
==
erfc
,
f
.
maker
.
fgraph
.
toposort
()
assert
isinstance
(
topo
[
1
]
.
op
,
Elemwise
),
f
.
maker
.
fgraph
.
toposort
()
assert
isinstance
(
topo
[
1
]
.
op
,
Elemwise
),
f
.
maker
.
fgraph
.
toposort
()
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
aes
.
Sub
),
f
.
maker
.
fgraph
.
toposort
()
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
aes
.
Sub
),
f
.
maker
.
fgraph
.
toposort
()
print
(
f
(
val
))
def
test_local_erf_neg_minus_one
(
self
):
def
test_local_erf_neg_minus_one
(
self
):
# test opt: (-1)+erfc(-x)=>erf(x)
# test opt: (-1)+erfc(-x)=>erf(x)
val
=
np
.
asarray
([
-
30
,
-
3
,
-
2
,
-
1
,
0
,
1
,
2
,
3
,
30
],
dtype
=
config
.
floatX
)
val
=
np
.
asarray
([
-
30
,
-
3
,
-
2
,
-
1
,
0
,
1
,
2
,
3
,
30
],
dtype
=
config
.
floatX
)
x
=
vector
(
"x"
)
x
=
vector
(
"x"
)
...
@@ -2769,19 +2750,17 @@ class TestLocalErfc:
...
@@ -2769,19 +2750,17 @@ class TestLocalErfc:
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
erf
erf
],
f
.
maker
.
fgraph
.
toposort
()
],
f
.
maker
.
fgraph
.
toposort
()
print
(
f
(
val
)
)
f
(
val
)
f
=
function
([
x
],
erfc
(
-
x
)
-
1
,
mode
=
self
.
mode
)
f
=
function
([
x
],
erfc
(
-
x
)
-
1
,
mode
=
self
.
mode
)
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
erf
erf
],
f
.
maker
.
fgraph
.
toposort
()
],
f
.
maker
.
fgraph
.
toposort
()
print
(
f
(
val
))
f
=
function
([
x
],
erfc
(
-
x
)
+
(
-
1
),
mode
=
self
.
mode
)
f
=
function
([
x
],
erfc
(
-
x
)
+
(
-
1
),
mode
=
self
.
mode
)
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
erf
erf
],
f
.
maker
.
fgraph
.
toposort
()
],
f
.
maker
.
fgraph
.
toposort
()
print
(
f
(
val
))
@pytest.mark.xfail
()
@pytest.mark.xfail
()
def
test_local_log_erfc
(
self
):
def
test_local_log_erfc
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论