Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
881f3494
提交
881f3494
authored
11月 09, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
11月 15, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move _fill_chain to aesara.tensor.math_opt
上级
f64d243d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
15 行增加
和
16 行删除
+15
-16
basic_opt.py
aesara/tensor/basic_opt.py
+0
-6
math_opt.py
aesara/tensor/math_opt.py
+15
-10
没有找到文件。
aesara/tensor/basic_opt.py
浏览文件 @
881f3494
...
...
@@ -88,12 +88,6 @@ _logger = logging.getLogger("aesara.tensor.basic_opt")
_logger
.
addFilter
(
NoDuplicateOptWarningFilter
())
def
_fill_chain
(
new_out
,
orig_inputs
):
for
i
in
orig_inputs
:
new_out
=
fill
(
i
,
new_out
)
return
[
new_out
]
def
encompasses_broadcastable
(
b1
,
b2
):
"""
...
...
aesara/tensor/math_opt.py
浏览文件 @
881f3494
...
...
@@ -40,7 +40,6 @@ from aesara.tensor.basic import (
)
from
aesara.tensor.basic_opt
import
(
FusionOptimizer
,
_fill_chain
,
broadcast_like
,
encompasses_broadcastable
,
fuse_seqopt
,
...
...
@@ -104,6 +103,12 @@ _logger = logging.getLogger("aesara.tensor.math_opt")
_logger
.
addFilter
(
NoDuplicateOptWarningFilter
())
def
fill_chain
(
new_out
,
orig_inputs
):
for
i
in
orig_inputs
:
new_out
=
fill
(
i
,
new_out
)
return
[
new_out
]
@register_canonicalize
@register_stabilize
@local_optimizer
([
Dot
])
...
...
@@ -1001,7 +1006,7 @@ class AlgebraicCanonizer(LocalOptimizer):
assert
(
new
.
type
==
out
.
type
)
==
(
not
(
new
.
type
!=
out
.
type
))
if
not
(
new
.
type
==
out
.
type
):
new
=
_
fill_chain
(
new
,
node
.
inputs
)[
0
]
new
=
fill_chain
(
new
,
node
.
inputs
)[
0
]
if
new
.
type
==
out
.
type
:
# This happen with test
...
...
@@ -1792,7 +1797,7 @@ def local_mul_zero(fgraph, node):
# print 'MUL by value', value, node.inputs
if
value
==
0
:
# print '... returning zeros'
return
_
fill_chain
(
_asarray
(
0
,
dtype
=
otype
.
dtype
),
node
.
inputs
)
return
fill_chain
(
_asarray
(
0
,
dtype
=
otype
.
dtype
),
node
.
inputs
)
register_canonicalize
(
local_mul_zero
)
...
...
@@ -2074,8 +2079,8 @@ register_specialize(local_mul_specialize)
@local_optimizer
([
add
])
def
local_add_specialize
(
fgraph
,
node
):
def
fill_chain
(
v
):
out
=
_
fill_chain
(
v
,
node
.
inputs
)
def
_
fill_chain
(
v
):
out
=
fill_chain
(
v
,
node
.
inputs
)
return
out
# here, we are past the point of canonicalization, so we don't want
...
...
@@ -2099,12 +2104,12 @@ def local_add_specialize(fgraph, node):
# Reuse call to constant for cache()
cst
=
constant
(
np
.
zeros
((
1
,)
*
ndim
,
dtype
=
dtype
))
assert
cst
.
type
.
broadcastable
==
(
True
,)
*
ndim
return
fill_chain
(
cst
)
return
_
fill_chain
(
cst
)
if
len
(
new_inputs
)
==
1
:
ret
=
fill_chain
(
new_inputs
[
0
])
ret
=
_
fill_chain
(
new_inputs
[
0
])
else
:
ret
=
fill_chain
(
add
(
*
new_inputs
))
ret
=
_
fill_chain
(
add
(
*
new_inputs
))
# The dtype should not be changed. It can happen if the input
# that was forcing upcasting was equal to 0.
if
ret
[
0
]
.
dtype
!=
dtype
:
...
...
@@ -2223,7 +2228,7 @@ def local_log1p(fgraph, node):
ninp
=
nonconsts
[
0
]
if
ninp
.
dtype
!=
log_arg
.
type
.
dtype
:
ninp
=
ninp
.
astype
(
node
.
outputs
[
0
]
.
dtype
)
return
_
fill_chain
(
log1p
(
ninp
),
scalar_inputs
)
return
fill_chain
(
log1p
(
ninp
),
scalar_inputs
)
elif
log_arg
.
owner
and
log_arg
.
owner
.
op
==
sub
:
one
=
extract_constant
(
log_arg
.
owner
.
inputs
[
0
],
only_process_constants
=
True
)
...
...
@@ -3496,7 +3501,7 @@ def local_reciprocal_1_plus_exp(fgraph, node):
if
len
(
nonconsts
)
==
1
:
if
nonconsts
[
0
]
.
owner
and
nonconsts
[
0
]
.
owner
.
op
==
exp
:
if
scalars_
and
np
.
allclose
(
np
.
sum
(
scalars_
),
1
):
out
=
_
fill_chain
(
out
=
fill_chain
(
sigmoid
(
neg
(
nonconsts
[
0
]
.
owner
.
inputs
[
0
])),
scalar_inputs
,
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论