Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8ec11777
提交
8ec11777
authored
10月 30, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
11月 15, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add local Shape of SpecifyShape canonicalization
上级
f5cc20ca
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
35 行增加
和
2 行删除
+35
-2
basic_opt.py
aesara/tensor/basic_opt.py
+18
-1
test_basic_opt.py
tests/tensor/test_basic_opt.py
+17
-1
没有找到文件。
aesara/tensor/basic_opt.py
浏览文件 @
8ec11777
...
...
@@ -76,7 +76,7 @@ from aesara.tensor.exceptions import NotScalarConstantError, ShapeError
from
aesara.tensor.extra_ops
import
broadcast_shape
from
aesara.tensor.math
import
all
as
at_all
from
aesara.tensor.math
import
eq
from
aesara.tensor.shape
import
Reshape
,
Shape
,
Shape_i
,
shape_padleft
from
aesara.tensor.shape
import
Reshape
,
Shape
,
Shape_i
,
SpecifyShape
,
shape_padleft
from
aesara.tensor.sort
import
TopKOp
from
aesara.tensor.subtensor
import
Subtensor
,
get_idx_list
from
aesara.tensor.type
import
discrete_dtypes
,
integer_dtypes
,
lscalar
...
...
@@ -3536,3 +3536,20 @@ def local_useless_topk(fgraph, node):
)(
x
,
k
)
copy_stack_trace
(
node
.
outputs
[
0
],
new_output
)
return
{
old_output
:
new_output
}
@register_useless
@register_canonicalize
@local_optimizer
([
Shape
])
def
local_Shape_of_SpecifyShape
(
fgraph
,
node
):
"""Replace ``specify_shape(x, s).shape`` with ``s``."""
if
not
isinstance
(
node
.
op
,
Shape
):
return
False
specified_shape
=
node
.
inputs
[
0
]
if
not
isinstance
(
getattr
(
specified_shape
.
owner
,
"op"
,
None
),
SpecifyShape
):
return
False
return
[
specified_shape
.
owner
.
inputs
[
1
]
.
astype
(
np
.
int64
)]
tests/tensor/test_basic_opt.py
浏览文件 @
8ec11777
...
...
@@ -19,6 +19,7 @@ from aesara.graph.basic import Apply, Constant
from
aesara.graph.fg
import
FunctionGraph
from
aesara.graph.op
import
Op
from
aesara.graph.opt
import
check_stack_trace
,
local_optimizer
,
out2in
from
aesara.graph.opt_utils
import
optimize_graph
from
aesara.graph.optdb
import
OptimizationQuery
from
aesara.misc.safe_asarray
import
_asarray
from
aesara.tensor.basic
import
(
...
...
@@ -82,7 +83,7 @@ from aesara.tensor.math import sin, sinh, softplus, sqr, sqrt, sub
from
aesara.tensor.math
import
sum
as
aet_sum
from
aesara.tensor.math
import
tan
,
tanh
,
true_div
,
xor
from
aesara.tensor.math_opt
import
local_lift_transpose_through_dot
from
aesara.tensor.shape
import
Reshape
,
Shape_i
,
reshape
from
aesara.tensor.shape
import
Reshape
,
Shape_i
,
reshape
,
specify_shape
from
aesara.tensor.subtensor
import
(
AdvancedIncSubtensor1
,
Subtensor
,
...
...
@@ -3192,6 +3193,21 @@ class TestShapeFeature:
shape_feature
.
same_shape
(
x
,
o
,
0
,
1
)
@pytest.mark.parametrize
(
"shape"
,
[
lscalar
(),
iscalar
()],
)
def
test_local_Shape_of_SpecifyShape
(
shape
):
x
=
vector
()
s
=
specify_shape
(
x
,
shape
)
.
shape
fgraph
=
FunctionGraph
(
outputs
=
[
s
],
clone
=
False
)
_
=
optimize_graph
(
fgraph
,
clone
=
False
)
assert
x
not
in
fgraph
.
variables
assert
shape
in
fgraph
.
variables
def
test_assert_op_gradient
():
x
=
vector
(
"x"
)
assert_op
=
Assert
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论