Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6302cef1
提交
6302cef1
authored
7月 15, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
8月 17, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename PatternSub to PatternNodeRewriter
上级
371c5447
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
67 行增加
和
62 行删除
+67
-62
opt.py
aesara/graph/opt.py
+12
-7
opt.py
aesara/sparse/opt.py
+2
-2
math_opt.py
aesara/tensor/math_opt.py
+16
-16
graph_rewriting.rst
doc/extending/graph_rewriting.rst
+12
-12
test_types.py
tests/compile/function/test_types.py
+2
-2
test_destroyhandler.py
tests/graph/test_destroyhandler.py
+2
-2
test_opt.py
tests/graph/test_opt.py
+20
-20
test_math_opt.py
tests/tensor/test_math_opt.py
+1
-1
没有找到文件。
aesara/graph/opt.py
浏览文件 @
6302cef1
...
...
@@ -1479,7 +1479,7 @@ class RemovalNodeRewriter(NodeRewriter):
)
class
Pattern
Sub
(
NodeRewriter
):
class
Pattern
NodeRewriter
(
NodeRewriter
):
"""Replace all occurrences of an input pattern with an output pattern.
The input and output patterns have the following syntax:
...
...
@@ -1517,7 +1517,7 @@ class PatternSub(NodeRewriter):
trying to match and returns True or False according to an
arbitrary criterion.
The constructor creates a `Pattern
Sub
` that replaces occurrences of
The constructor creates a `Pattern
NodeRewriter
` that replaces occurrences of
`in_pattern` by occurrences of `out_pattern`.
Parameters
...
...
@@ -1548,11 +1548,11 @@ class PatternSub(NodeRewriter):
Examples
--------
Pattern
Sub
((add, 'x', 'y'), (add, 'y', 'x'))
Pattern
Sub
((multiply, 'x', 'x'), (square, 'x'))
Pattern
Sub
((subtract, (add, 'x', 'y'), 'y'), 'x')
Pattern
Sub
((power, 'x', Constant(double, 2.0)), (square, 'x'))
Pattern
Sub
((boggle, {'pattern': 'x',
Pattern
NodeRewriter
((add, 'x', 'y'), (add, 'y', 'x'))
Pattern
NodeRewriter
((multiply, 'x', 'x'), (square, 'x'))
Pattern
NodeRewriter
((subtract, (add, 'x', 'y'), 'y'), 'x')
Pattern
NodeRewriter
((power, 'x', Constant(double, 2.0)), (square, 'x'))
Pattern
NodeRewriter
((boggle, {'pattern': 'x',
'constraint': lambda expr: expr.type == scrabble}),
(scrabble, 'x'))
...
...
@@ -3183,6 +3183,11 @@ DEPRECATED_NAMES = [
"`OpRemove` is deprecated: use `RemovalNodeRewriter` instead."
,
RemovalNodeRewriter
,
),
(
"PatternSub"
,
"`PatternSub` is deprecated: use `PatternNodeRewriter` instead."
,
PatternNodeRewriter
,
),
]
...
...
aesara/sparse/opt.py
浏览文件 @
6302cef1
...
...
@@ -4,7 +4,7 @@ import aesara
import
aesara.scalar
as
aes
from
aesara.configdefaults
import
config
from
aesara.graph.basic
import
Apply
from
aesara.graph.opt
import
Pattern
Sub
,
TopoOptimizer
,
node_rewriter
from
aesara.graph.opt
import
Pattern
NodeRewriter
,
TopoOptimizer
,
node_rewriter
from
aesara.link.c.op
import
COp
,
_NoPythonCOp
from
aesara.misc.safe_asarray
import
_asarray
from
aesara.sparse
import
basic
as
sparse
...
...
@@ -928,7 +928,7 @@ usmm_csc_dense_inplace = UsmmCscDense(inplace=True)
# This is tested in tests/test_basic.py:UsmmTests
local_usmm
=
Pattern
Sub
(
local_usmm
=
Pattern
NodeRewriter
(
(
sub
,
"z"
,
...
...
aesara/tensor/math_opt.py
浏览文件 @
6302cef1
...
...
@@ -11,7 +11,7 @@ import aesara.scalar.math as aes_math
from
aesara.graph.basic
import
Constant
,
Variable
from
aesara.graph.opt
import
(
NodeRewriter
,
Pattern
Sub
,
Pattern
NodeRewriter
,
SequentialNodeRewriter
,
copy_stack_trace
,
in2out
,
...
...
@@ -2512,7 +2512,7 @@ get_clients_at_depth1 = partial(get_clients_at_depth, depth=1)
get_clients_at_depth2
=
partial
(
get_clients_at_depth
,
depth
=
2
)
# 1+erf(x)=>erfc(-x)
local_one_plus_erf
=
Pattern
Sub
(
local_one_plus_erf
=
Pattern
NodeRewriter
(
(
add
,
1
,
(
erf
,
"x"
)),
(
erfc
,
(
neg
,
"x"
)),
allow_multiple_clients
=
True
,
...
...
@@ -2527,7 +2527,7 @@ register_specialize(local_one_plus_erf)
# Only one of the two rewrites below is needed if a canonicalization is added
# for sub(x, y) -> add(x, -y) or a specialization for add(x, -y) -> sub(x, y)
# 1-erf(x)=>erfc(x)
local_one_minus_erf
=
Pattern
Sub
(
local_one_minus_erf
=
Pattern
NodeRewriter
(
(
sub
,
1
,
(
erf
,
"x"
)),
(
erfc
,
"x"
),
allow_multiple_clients
=
True
,
...
...
@@ -2539,7 +2539,7 @@ register_canonicalize(local_one_minus_erf)
register_stabilize
(
local_one_minus_erf
)
register_specialize
(
local_one_minus_erf
)
local_one_minus_erf2
=
Pattern
Sub
(
local_one_minus_erf2
=
Pattern
NodeRewriter
(
(
add
,
1
,
(
neg
,
(
erf
,
"x"
))),
(
erfc
,
"x"
),
allow_multiple_clients
=
True
,
...
...
@@ -2554,7 +2554,7 @@ register_specialize(local_one_minus_erf2)
# (-1)+erf(x) => -erfc(x)
# There is no need for erf(x)+(-1) nor erf(x) - 1, as the canonicalize will
# convert those to the matched pattern
local_erf_minus_one
=
Pattern
Sub
(
local_erf_minus_one
=
Pattern
NodeRewriter
(
(
add
,
-
1
,
(
erf
,
"x"
)),
(
neg
,
(
erfc
,
"x"
)),
allow_multiple_clients
=
True
,
...
...
@@ -2569,7 +2569,7 @@ register_specialize(local_erf_minus_one)
# Only one of the two rewrites below is needed if a canonicalization is added
# for sub(x, y) -> add(x, -y) or a specialization for add(x, -y) -> sub(x, y)
# 1-erfc(x) => erf(x)
local_one_minus_erfc
=
Pattern
Sub
(
local_one_minus_erfc
=
Pattern
NodeRewriter
(
(
sub
,
1
,
(
erfc
,
"x"
)),
(
erf
,
"x"
),
allow_multiple_clients
=
True
,
...
...
@@ -2581,7 +2581,7 @@ register_canonicalize(local_one_minus_erfc)
register_stabilize
(
local_one_minus_erfc
)
register_specialize
(
local_one_minus_erfc
)
local_one_minus_erfc2
=
Pattern
Sub
(
local_one_minus_erfc2
=
Pattern
NodeRewriter
(
(
add
,
1
,
(
neg
,
(
erfc
,
"x"
))),
(
erf
,
"x"
),
allow_multiple_clients
=
True
,
...
...
@@ -2594,7 +2594,7 @@ register_stabilize(local_one_minus_erfc2)
register_specialize
(
local_one_minus_erfc2
)
# (-1)+erfc(-x)=>erf(x)
local_erf_neg_minus_one
=
Pattern
Sub
(
local_erf_neg_minus_one
=
Pattern
NodeRewriter
(
(
add
,
-
1
,
(
erfc
,
(
neg
,
"x"
))),
(
erf
,
"x"
),
allow_multiple_clients
=
True
,
...
...
@@ -2914,7 +2914,7 @@ def _is_1(expr):
return
False
logsigm_to_softplus
=
Pattern
Sub
(
logsigm_to_softplus
=
Pattern
NodeRewriter
(
(
log
,
(
sigmoid
,
"x"
)),
(
neg
,
(
softplus
,
(
neg
,
"x"
))),
allow_multiple_clients
=
True
,
...
...
@@ -2923,7 +2923,7 @@ logsigm_to_softplus = PatternSub(
tracks
=
[
sigmoid
],
get_nodes
=
get_clients_at_depth1
,
)
log1msigm_to_softplus
=
Pattern
Sub
(
log1msigm_to_softplus
=
Pattern
NodeRewriter
(
(
log
,
(
sub
,
dict
(
pattern
=
"y"
,
constraint
=
_is_1
),
(
sigmoid
,
"x"
))),
(
neg
,
(
softplus
,
"x"
)),
allow_multiple_clients
=
True
,
...
...
@@ -2932,13 +2932,13 @@ log1msigm_to_softplus = PatternSub(
tracks
=
[
sigmoid
],
get_nodes
=
get_clients_at_depth2
,
)
log1pexp_to_softplus
=
Pattern
Sub
(
log1pexp_to_softplus
=
Pattern
NodeRewriter
(
(
log1p
,
(
exp
,
"x"
)),
(
softplus
,
"x"
),
values_eq_approx
=
values_eq_approx_remove_inf
,
allow_multiple_clients
=
True
,
)
log1p_neg_sigmoid
=
Pattern
Sub
(
log1p_neg_sigmoid
=
Pattern
NodeRewriter
(
(
log1p
,
(
neg
,
(
sigmoid
,
"x"
))),
(
neg
,
(
softplus
,
"x"
)),
values_eq_approx
=
values_eq_approx_remove_inf
,
...
...
@@ -3511,7 +3511,7 @@ def local_reciprocal_1_plus_exp(fgraph, node):
# 1 - sigmoid(x) -> sigmoid(-x)
local_1msigmoid
=
Pattern
Sub
(
local_1msigmoid
=
Pattern
NodeRewriter
(
(
sub
,
dict
(
pattern
=
"y"
,
constraint
=
_is_1
),
(
sigmoid
,
"x"
)),
(
sigmoid
,
(
neg
,
"x"
)),
tracks
=
[
sigmoid
],
...
...
@@ -3522,7 +3522,7 @@ register_stabilize(local_1msigmoid)
register_specialize
(
local_1msigmoid
)
log1pmexp_to_log1mexp
=
Pattern
Sub
(
log1pmexp_to_log1mexp
=
Pattern
NodeRewriter
(
(
log1p
,
(
neg
,
(
exp
,
"x"
))),
(
log1mexp
,
"x"
),
allow_multiple_clients
=
True
,
...
...
@@ -3532,7 +3532,7 @@ register_stabilize(log1pmexp_to_log1mexp, name="log1pmexp_to_log1mexp")
# log(sigmoid(x) / (1 - sigmoid(x))) -> x
# i.e logit(sigmoid(x)) -> x
local_logit_sigmoid
=
Pattern
Sub
(
local_logit_sigmoid
=
Pattern
NodeRewriter
(
(
log
,
(
true_div
,
(
sigmoid
,
"x"
),
(
sub
,
1
,
(
sigmoid
,
"x"
)))),
"x"
,
tracks
=
[
sigmoid
],
...
...
@@ -3546,7 +3546,7 @@ register_specialize(local_logit_sigmoid)
# sigmoid(log(x / (1-x)) -> x
# i.e., sigmoid(logit(x)) -> x
local_sigmoid_logit
=
Pattern
Sub
(
local_sigmoid_logit
=
Pattern
NodeRewriter
(
(
sigmoid
,
(
log
,
(
true_div
,
"x"
,
(
sub
,
1
,
"x"
)))),
"x"
,
allow_multiple_clients
=
True
,
...
...
doc/extending/graph_rewriting.rst
浏览文件 @
6302cef1
...
...
@@ -89,7 +89,7 @@ For starters, let's define the following simplification:
\frac{xy}{y} = x
We will implement it in three ways: using a global optimization, a
local optimization with a :class:`NavigatorOptimizer` and then using the :class:`Pattern
Sub
`
local optimization with a :class:`NavigatorOptimizer` and then using the :class:`Pattern
NodeRewriter
`
facility.
Global optimization
...
...
@@ -270,8 +270,8 @@ FunctionGraph(add(z, mul(true_div(mul(y, x), y), true_div(z, x))))
>>> e
FunctionGraph(add(z, mul(x, true_div(z, x))))
:class:`SubstitutionNodeRewriter`, :class:`RemovalNodeRewriter`, :class:`Pattern
Sub
`
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
:class:`SubstitutionNodeRewriter`, :class:`RemovalNodeRewriter`, :class:`Pattern
NodeRewriter
`
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++
Aesara defines some shortcuts to make :class:`NodeRewriter`\s:
...
...
@@ -288,15 +288,15 @@ Aesara defines some shortcuts to make :class:`NodeRewriter`\s:
outputs as it has inputs. The first output becomes the first input,
the second output becomes the second input, and so on.
.. function:: Pattern
Sub
(pattern1, pattern2)
.. function:: Pattern
NodeRewriter
(pattern1, pattern2)
Replaces all occurrences of the first pattern by the second pattern.
See :class:`Pattern
Sub
`.
See :class:`Pattern
NodeRewriter
`.
.. code::
from aesara.scalar import identity
from aesara.graph.opt import SubstitutionNodeRewriter, RemovalNodeRewriter, Pattern
Sub
from aesara.graph.opt import SubstitutionNodeRewriter, RemovalNodeRewriter, Pattern
NodeRewriter
# Replacing `add` by `mul` (this is not recommended for primarily
# mathematical reasons):
...
...
@@ -308,25 +308,25 @@ Aesara defines some shortcuts to make :class:`NodeRewriter`\s:
# The "simplify" operation we've been defining in the past few
# sections. Note that we need two patterns to account for the
# permutations of the arguments to `mul`.
local_simplify_1 = Pattern
Sub
((true_div, (mul, 'x', 'y'), 'y'), 'x')
local_simplify_2 = Pattern
Sub
((true_div, (mul, 'x', 'y'), 'x'), 'y')
local_simplify_1 = Pattern
NodeRewriter
((true_div, (mul, 'x', 'y'), 'y'), 'x')
local_simplify_2 = Pattern
NodeRewriter
((true_div, (mul, 'x', 'y'), 'x'), 'y')
.. note::
:class:`SubstitutionNodeRewriter`, :class:`RemovalNodeRewriter` and :class:`Pattern
Sub
` produce local optimizers, which
:class:`SubstitutionNodeRewriter`, :class:`RemovalNodeRewriter` and :class:`Pattern
NodeRewriter
` produce local optimizers, which
means that everything we said previously about local optimizers
apply (e.g. they need to be wrapped in a :class:`NavigatorOptimizer`, etc.)
When an optimization can be naturally expressed using :class:`SubstitutionNodeRewriter`, :class:`RemovalNodeRewriter`
or :class:`Pattern
Sub
`, it is highly recommended to use them.
or :class:`Pattern
NodeRewriter
`, it is highly recommended to use them.
.. _unification:
Unification and reification
===========================
The :class:`Pattern
Sub
` class uses `unification and reification
The :class:`Pattern
NodeRewriter
` class uses `unification and reification
<https://en.wikipedia.org/wiki/Unification_(computer_science)>`_ to implement a
more succinct and reusable form of "pattern matching and replacement".
In general, *use of the unification and reification tools is preferable when
...
...
@@ -345,7 +345,7 @@ In order to use :func:`unify` and :func:`reify` with Aesara graphs, we need an i
structure that will allow us to represent Aesara graphs that contain :class:`var`\s, because
Aesara :class:`Op`\s and :class:`Apply` nodes will not accept these foreign objects as inputs.
:class:`Pattern
Sub
` uses Python ``tuple``\s to effectively represent :class:`Apply` nodes and
:class:`Pattern
NodeRewriter
` uses Python ``tuple``\s to effectively represent :class:`Apply` nodes and
``str``\s to represent logic variables (i.e. :class:`var`\s in the :mod:`unification` library).
Behind the scenes, these ``tuple``\s are converted to a ``tuple`` subclass called :class:`ExpressionTuple`\s,
which behave just like normal ``tuple``\s except for some special caching features that allow for easy
...
...
tests/compile/function/test_types.py
浏览文件 @
6302cef1
...
...
@@ -13,7 +13,7 @@ from aesara.compile.io import In, Out
from
aesara.compile.mode
import
Mode
,
get_default_mode
from
aesara.configdefaults
import
config
from
aesara.graph.basic
import
Constant
from
aesara.graph.opt
import
OpKeyOptimizer
,
Pattern
Sub
from
aesara.graph.opt
import
OpKeyOptimizer
,
Pattern
NodeRewriter
from
aesara.graph.utils
import
MissingInputError
from
aesara.link.vm
import
VMLinker
from
aesara.tensor.math
import
dot
...
...
@@ -35,7 +35,7 @@ from aesara.utils import exc_message
def
PatternOptimizer
(
p1
,
p2
,
ign
=
True
):
return
OpKeyOptimizer
(
Pattern
Sub
(
p1
,
p2
),
ignore_newtrees
=
ign
)
return
OpKeyOptimizer
(
Pattern
NodeRewriter
(
p1
,
p2
),
ignore_newtrees
=
ign
)
class
TestFunction
:
...
...
tests/graph/test_destroyhandler.py
浏览文件 @
6302cef1
...
...
@@ -11,7 +11,7 @@ from aesara.graph.op import Op
from
aesara.graph.opt
import
(
NavigatorOptimizer
,
OpKeyOptimizer
,
Pattern
Sub
,
Pattern
NodeRewriter
,
SubstitutionNodeRewriter
,
TopoOptimizer
,
)
...
...
@@ -21,7 +21,7 @@ from tests.unittest_tools import assertFailure_fast
def
PatternOptimizer
(
p1
,
p2
,
ign
=
True
):
return
OpKeyOptimizer
(
Pattern
Sub
(
p1
,
p2
),
ignore_newtrees
=
ign
)
return
OpKeyOptimizer
(
Pattern
NodeRewriter
(
p1
,
p2
),
ignore_newtrees
=
ign
)
def
TopoSubstitutionNodeRewriter
(
...
...
tests/graph/test_opt.py
浏览文件 @
6302cef1
...
...
@@ -10,7 +10,7 @@ from aesara.graph.opt import (
MergeOptimizer
,
OpKeyOptimizer
,
OpToRewriterTracker
,
Pattern
Sub
,
Pattern
NodeRewriter
,
SequentialNodeRewriter
,
SubstitutionNodeRewriter
,
TopoOptimizer
,
...
...
@@ -51,11 +51,11 @@ class AssertNoChanges(Feature):
def
PatternOptimizer
(
p1
,
p2
,
ign
=
False
):
return
OpKeyOptimizer
(
Pattern
Sub
(
p1
,
p2
),
ignore_newtrees
=
ign
)
return
OpKeyOptimizer
(
Pattern
NodeRewriter
(
p1
,
p2
),
ignore_newtrees
=
ign
)
def
TopoPatternOptimizer
(
p1
,
p2
,
ign
=
True
):
return
TopoOptimizer
(
Pattern
Sub
(
p1
,
p2
),
ignore_newtrees
=
ign
)
return
TopoOptimizer
(
Pattern
NodeRewriter
(
p1
,
p2
),
ignore_newtrees
=
ign
)
class
TestPatternOptimizer
:
...
...
@@ -448,9 +448,9 @@ class TestEquilibrium:
# print g
opt
=
EquilibriumOptimizer
(
[
Pattern
Sub
((
op1
,
"x"
,
"y"
),
(
op2
,
"x"
,
"y"
)),
Pattern
Sub
((
op4
,
"x"
,
"y"
),
(
op1
,
"x"
,
"y"
)),
Pattern
Sub
((
op3
,
(
op2
,
"x"
,
"y"
)),
(
op4
,
"x"
,
"y"
)),
Pattern
NodeRewriter
((
op1
,
"x"
,
"y"
),
(
op2
,
"x"
,
"y"
)),
Pattern
NodeRewriter
((
op4
,
"x"
,
"y"
),
(
op1
,
"x"
,
"y"
)),
Pattern
NodeRewriter
((
op3
,
(
op2
,
"x"
,
"y"
)),
(
op4
,
"x"
,
"y"
)),
],
max_use_ratio
=
10
,
)
...
...
@@ -465,11 +465,11 @@ class TestEquilibrium:
# print g
opt
=
EquilibriumOptimizer
(
[
Pattern
Sub
((
op1
,
(
op2
,
"x"
,
"y"
)),
(
op4
,
"x"
,
"y"
)),
Pattern
Sub
((
op3
,
"x"
,
"y"
),
(
op4
,
"x"
,
"y"
)),
Pattern
Sub
((
op4
,
"x"
,
"y"
),
(
op5
,
"x"
,
"y"
)),
Pattern
Sub
((
op5
,
"x"
,
"y"
),
(
op6
,
"x"
,
"y"
)),
Pattern
Sub
((
op6
,
"x"
,
"y"
),
(
op2
,
"x"
,
"y"
)),
Pattern
NodeRewriter
((
op1
,
(
op2
,
"x"
,
"y"
)),
(
op4
,
"x"
,
"y"
)),
Pattern
NodeRewriter
((
op3
,
"x"
,
"y"
),
(
op4
,
"x"
,
"y"
)),
Pattern
NodeRewriter
((
op4
,
"x"
,
"y"
),
(
op5
,
"x"
,
"y"
)),
Pattern
NodeRewriter
((
op5
,
"x"
,
"y"
),
(
op6
,
"x"
,
"y"
)),
Pattern
NodeRewriter
((
op6
,
"x"
,
"y"
),
(
op2
,
"x"
,
"y"
)),
],
max_use_ratio
=
10
,
)
...
...
@@ -490,9 +490,9 @@ class TestEquilibrium:
try
:
opt
=
EquilibriumOptimizer
(
[
Pattern
Sub
((
op1
,
"x"
,
"y"
),
(
op2
,
"x"
,
"y"
)),
Pattern
Sub
((
op4
,
"x"
,
"y"
),
(
op1
,
"x"
,
"y"
)),
Pattern
Sub
((
op3
,
(
op2
,
"x"
,
"y"
)),
(
op4
,
"x"
,
"y"
)),
Pattern
NodeRewriter
((
op1
,
"x"
,
"y"
),
(
op2
,
"x"
,
"y"
)),
Pattern
NodeRewriter
((
op4
,
"x"
,
"y"
),
(
op1
,
"x"
,
"y"
)),
Pattern
NodeRewriter
((
op3
,
(
op2
,
"x"
,
"y"
)),
(
op4
,
"x"
,
"y"
)),
],
max_use_ratio
=
1.0
/
len
(
g
.
apply_nodes
),
)
# each opt can only be applied once
...
...
@@ -595,14 +595,14 @@ def test_pre_greedy_node_rewriter():
@pytest.mark.parametrize
(
"tracks"
,
[
True
,
False
])
@pytest.mark.parametrize
(
"out_pattern"
,
[(
op2
,
"x"
),
"x"
,
1.0
])
def
test_patternsub_values_eq_approx
(
out_pattern
,
tracks
):
# Pattern
Sub
would fail when `values_eq_approx` and `get_nodes` were specified
# Pattern
NodeRewriter
would fail when `values_eq_approx` and `get_nodes` were specified
x
=
MyVariable
(
"x"
)
e
=
op1
(
x
)
fg
=
FunctionGraph
([
x
],
[
e
],
clone
=
False
)
opt
=
EquilibriumOptimizer
(
[
Pattern
Sub
(
Pattern
NodeRewriter
(
(
op1
,
"x"
),
out_pattern
,
tracks
=
[
op1
]
if
tracks
else
(),
...
...
@@ -628,14 +628,14 @@ def test_patternsub_values_eq_approx(out_pattern, tracks):
@pytest.mark.parametrize
(
"out_pattern"
,
[(
op1
,
"x"
),
"x"
])
def
test_patternsub_invalid_dtype
(
out_pattern
):
# Pattern
Sub
would wrongly return output of different dtype as the original node
# Pattern
NodeRewriter
would wrongly return output of different dtype as the original node
x
=
MyVariable
(
"x"
)
e
=
op_cast_type2
(
x
)
fg
=
FunctionGraph
([
x
],
[
e
])
opt
=
EquilibriumOptimizer
(
[
Pattern
Sub
(
Pattern
NodeRewriter
(
(
op_cast_type2
,
"x"
),
out_pattern
,
)
...
...
@@ -647,8 +647,8 @@ def test_patternsub_invalid_dtype(out_pattern):
def
test_patternsub_different_output_lengths
():
# Test that Pattern
Sub
won't replace nodes with different numbers of outputs
ps
=
Pattern
Sub
(
# Test that Pattern
NodeRewriter
won't replace nodes with different numbers of outputs
ps
=
Pattern
NodeRewriter
(
(
op1
,
"x"
),
(
"x"
),
name
=
"ps"
,
...
...
tests/tensor/test_math_opt.py
浏览文件 @
6302cef1
...
...
@@ -4312,7 +4312,7 @@ class TestSigmoidOpts:
# tests exp_over_1_plus_exp
f
=
aesara
.
function
([
x
],
1
-
exp
(
x
)
/
(
1
+
exp
(
x
)),
mode
=
m
)
# FIXME: Pattern
Sub
does not copy stack trace
# FIXME: Pattern
NodeRewriter
does not copy stack trace
# (see https://github.com/Theano/Theano/issues/4581)
# assert check_stack_trace(f, ops_to_check=[neg, sigmoid])
assert
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
==
[
neg
,
sigmoid
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论