Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ce2c8613
提交
ce2c8613
authored
10月 30, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
11月 15, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add local Shape_i of broadcastable dimension canonicalization
上级
8ec11777
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
50 行增加
和
2 行删除
+50
-2
basic_opt.py
aesara/tensor/basic_opt.py
+19
-1
test_basic_opt.py
tests/tensor/test_basic_opt.py
+31
-1
没有找到文件。
aesara/tensor/basic_opt.py
浏览文件 @
ce2c8613
...
...
@@ -79,7 +79,7 @@ from aesara.tensor.math import eq
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
from
aesara.tensor.type
import
TensorType
,
discrete_dtypes
,
integer_dtypes
,
lscalar
from
aesara.tensor.var
import
TensorConstant
from
aesara.utils
import
NoDuplicateOptWarningFilter
...
...
@@ -3553,3 +3553,21 @@ def local_Shape_of_SpecifyShape(fgraph, node):
return
False
return
[
specified_shape
.
owner
.
inputs
[
1
]
.
astype
(
np
.
int64
)]
@register_useless
@register_canonicalize
@local_optimizer
([
Shape_i
])
def
local_Shape_i_of_broadcastable
(
fgraph
,
node
):
"""Replace ``shape_i(x, i)`` with ``1`` when ``x.broadcastable[i]`` is ``True``."""
if
not
isinstance
(
node
.
op
,
Shape_i
):
return
False
shape_arg
=
node
.
inputs
[
0
]
if
not
isinstance
(
shape_arg
.
type
,
TensorType
):
return
False
if
shape_arg
.
broadcastable
[
node
.
op
.
i
]:
return
[
as_tensor_variable
(
1
,
dtype
=
np
.
int64
)]
tests/tensor/test_basic_opt.py
浏览文件 @
ce2c8613
...
...
@@ -15,12 +15,13 @@ 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
Apply
,
Constant
from
aesara.graph.basic
import
Apply
,
Constant
,
Variable
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.graph.type
import
Type
from
aesara.misc.safe_asarray
import
_asarray
from
aesara.tensor.basic
import
(
Alloc
,
...
...
@@ -3208,6 +3209,35 @@ def test_local_Shape_of_SpecifyShape(shape):
assert
shape
in
fgraph
.
variables
def
test_local_Shape_i_of_broadcastable
():
x
=
tensor
(
np
.
float64
,
[
False
,
True
])
s
=
Shape_i
(
1
)(
x
)
fgraph
=
FunctionGraph
(
outputs
=
[
s
],
clone
=
False
)
_
=
optimize_graph
(
fgraph
,
clone
=
False
)
assert
x
not
in
fgraph
.
variables
assert
fgraph
.
outputs
[
0
]
.
data
==
1
# A test for a non-`TensorType`
class
MyType
(
Type
):
def
filter
(
self
,
*
args
,
**
kwargs
):
raise
NotImplementedError
()
def
__eq__
(
self
,
other
):
return
isinstance
(
other
,
MyType
)
and
other
.
thingy
==
self
.
thingy
class
MyVariable
(
Variable
):
ndim
=
1
x
=
MyVariable
(
MyType
(),
None
,
None
)
s
=
Shape_i
(
0
)(
x
)
fgraph
=
FunctionGraph
(
outputs
=
[
s
],
clone
=
False
)
_
=
optimize_graph
(
fgraph
,
clone
=
False
)
assert
fgraph
.
outputs
[
0
]
==
s
def
test_assert_op_gradient
():
x
=
vector
(
"x"
)
assert_op
=
Assert
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论