Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9beb6c2d
提交
9beb6c2d
authored
1月 23, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
1月 23, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove broken warning in AlgebraicCanonizer and refactor it tests
上级
77bcd689
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
49 行增加
和
41 行删除
+49
-41
math_opt.py
aesara/tensor/math_opt.py
+1
-19
test_math_opt.py
tests/tensor/test_math_opt.py
+48
-22
没有找到文件。
aesara/tensor/math_opt.py
浏览文件 @
9beb6c2d
...
...
@@ -1024,28 +1024,10 @@ class AlgebraicCanonizer(LocalOptimizer):
new
=
fill_chain
(
new
,
node
.
inputs
)[
0
]
if
new
.
type
==
out
.
type
:
# This happen with test
# aesara/tensor/tests/test_opt.py:T_local_switch_sink
new
.
tag
.
values_eq_approx
=
values_eq_approx_remove_inf_nan
# We need to implement the copy over of the stacktrace.
# See issue #5104.
copy_stack_trace
(
out
,
new
)
return
[
new
]
else
:
_logger
.
warning
(
" "
.
join
(
(
"CANONIZE FAILED: new, out = "
,
new
,
","
,
out
,
"types"
,
new
.
type
,
","
,
out
.
type
,
)
)
)
return
False
def
__str__
(
self
):
...
...
tests/tensor/test_math_opt.py
浏览文件 @
9beb6c2d
...
...
@@ -16,9 +16,15 @@ from aesara.compile.function import function
from
aesara.compile.mode
import
Mode
,
get_default_mode
,
get_mode
from
aesara.compile.ops
import
DeepCopyOp
,
deep_copy_op
from
aesara.configdefaults
import
config
from
aesara.graph.basic
import
Constant
from
aesara.graph.basic
import
Apply
,
Constant
,
equal_computations
from
aesara.graph.fg
import
FunctionGraph
from
aesara.graph.opt
import
LocalOptGroup
,
TopoOptimizer
,
check_stack_trace
,
out2in
from
aesara.graph.opt
import
(
LocalOptGroup
,
TopoOptimizer
,
check_stack_trace
,
in2out
,
out2in
,
)
from
aesara.graph.opt_utils
import
is_same_graph
,
optimize_graph
from
aesara.graph.optdb
import
OptimizationQuery
from
aesara.misc.safe_asarray
import
_asarray
...
...
@@ -79,6 +85,7 @@ from aesara.tensor.math_opt import (
is_1pexp
,
local_grad_log_erfc_neg
,
local_greedy_distributor
,
local_mul_canonizer
,
mul_canonizer
,
parse_mul_tree
,
perform_sigm_times_exp
,
...
...
@@ -220,23 +227,31 @@ class TestGreedyDistribute:
assert
np
.
all
(
r0
==
r2
)
class
TestAlgebraicCanonize
:
def
test_muldiv
(
self
):
x
,
y
,
z
=
matrices
(
"xyz"
)
a
,
b
,
c
,
d
=
matrices
(
"abcd"
)
# e = (2.0 * x) / (2.0 * y)
# e = (2.0 * x) / (4.0 * y)
# e = x / (y / z)
# e = (x * y) / x
# e = (x / y) * (y / z) * (z / x)
# e = (a / b) * (b / c) * (c / d)
# e = (a * b) / (b * c) / (c * d)
# e = 2 * x / 2
# e = x / y / x
# e = (x / x) * (y / y)
e
=
(
-
1
*
x
)
/
y
/
(
-
2
*
z
)
g
=
FunctionGraph
([
x
,
y
,
z
,
a
,
b
,
c
,
d
],
[
e
])
mul_canonizer
.
optimize
(
g
)
class
TestAlgebraicCanonizer
:
x
,
y
,
z
=
matrices
(
"xyz"
)
@pytest.mark.parametrize
(
"e, exp_g"
,
[
# ((2.0 * x) / (2.0 * y), None),
# ((2.0 * x) / (4.0 * y), None),
# (x / (y / z), None),
# ((x * y) / x, None),
# ((x / y) * (y / z) * (z / x), None),
# ((a / b) * (b / c) * (c / d), None),
# ((a * b) / (b * c) / (c * d), None),
# (2 * x / 2, None),
# (x / y / x, None),
# ((x / x) * (y / y), None),
(
(
-
1
*
x
)
/
y
/
(
-
2
*
z
),
(
at
.
as_tensor
([[
0.5
]],
dtype
=
"floatX"
)
*
x
)
/
(
y
*
z
),
),
],
)
def
test_muldiv
(
self
,
e
,
exp_g
):
g_opt
=
optimize_graph
(
e
,
custom_opt
=
mul_canonizer
)
assert
equal_computations
([
g_opt
],
[
exp_g
])
def
test_elemwise_multiple_inputs_optimisation
(
self
):
# verify that the AlgebraicCanonizer merge sequential Elemwise({mul,add}) part 1
...
...
@@ -245,7 +260,6 @@ class TestAlgebraicCanonize:
# that are not implemented but are supposed to be.
#
# Test with and without DimShuffle
shp
=
(
5
,
5
)
fx
,
fy
,
fz
=
fmatrices
(
"xyz"
)
dx
,
dy
,
dz
=
dmatrices
(
"xyz"
)
...
...
@@ -369,8 +383,7 @@ class TestAlgebraicCanonize:
assert
out_dtype
==
out
.
dtype
@pytest.mark.skip
(
reason
=
"Current implementation of AlgebraicCanonizer does not "
"implement all cases. Skip the corresponding test."
reason
=
"Current implementation of AlgebraicCanonizer does not implement all cases."
)
def
test_elemwise_multiple_inputs_optimisation2
(
self
):
# verify that the AlgebraicCanonizer merge sequential Elemwise({mul,add}) part 2.
...
...
@@ -951,6 +964,19 @@ class TestAlgebraicCanonize:
# at all.
assert
not
sio
.
getvalue
()
def
test_mismatching_types
(
self
):
a
=
at
.
as_tensor
([[
0.0
]],
dtype
=
np
.
float64
)
b
=
tensor
(
"float64"
,
(
None
,))
.
dimshuffle
(
"x"
,
0
)
z
=
add
(
a
,
b
)
# Construct a node with the wrong output `Type`
z
=
Apply
(
z
.
owner
.
op
,
z
.
owner
.
inputs
,
[
tensor
(
"float64"
,
(
None
,
None
))]
)
.
outputs
[
0
]
z_opt
=
optimize_graph
(
z
,
custom_opt
=
in2out
(
local_mul_canonizer
,
name
=
"blah"
))
# No rewrite was applied
assert
z_opt
is
z
def
test_local_merge_abs
():
x
,
y
,
z
=
matrices
(
"xyz"
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论