Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b25fb1be
提交
b25fb1be
authored
11月 10, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
11月 15, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Prevent unnecessary shadowing of builtin input
上级
9078756f
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
22 行增加
和
22 行删除
+22
-22
basic_opt.py
aesara/tensor/basic_opt.py
+0
-0
math_opt.py
aesara/tensor/math_opt.py
+22
-22
没有找到文件。
aesara/tensor/basic_opt.py
浏览文件 @
b25fb1be
差异被折叠。
点击展开。
aesara/tensor/math_opt.py
浏览文件 @
b25fb1be
...
...
@@ -627,7 +627,7 @@ class AlgebraicCanonizer(LocalOptimizer):
def
tracks
(
self
):
return
[
self
.
main
,
self
.
inverse
,
self
.
reciprocal
]
def
get_num_denum
(
self
,
inp
ut
):
def
get_num_denum
(
self
,
inp
):
r"""
This extract two lists, ``num`` and ``denum``, such that the input is:
``self.inverse(self.main(\*num), self.main(\*denum))``. It returns
...
...
@@ -656,12 +656,12 @@ class AlgebraicCanonizer(LocalOptimizer):
# argument. The leaf-Variables of the graph covered by the
# recursion may be of any Variable type.
if
inp
ut
.
owner
is
None
or
input
.
owner
.
op
not
in
[
if
inp
.
owner
is
None
or
inp
.
owner
.
op
not
in
[
self
.
main
,
self
.
inverse
,
self
.
reciprocal
,
]:
if
inp
ut
.
owner
and
isinstance
(
input
.
owner
.
op
,
DimShuffle
):
if
inp
.
owner
and
isinstance
(
inp
.
owner
.
op
,
DimShuffle
):
# If input is a DimShuffle of some input which does
# something like this:
...
...
@@ -671,7 +671,7 @@ class AlgebraicCanonizer(LocalOptimizer):
# with broadcastable 1s to the *left*
# Then we will simply discard the DimShuffle and return
# the num/denum of its input
dsn
=
inp
ut
.
owner
# dimshuffle node
dsn
=
inp
.
owner
# dimshuffle node
dsop
=
dsn
.
op
# dimshuffle op
# the first input of the dimshuffle i.e. the ndarray to redim
...
...
@@ -687,22 +687,22 @@ class AlgebraicCanonizer(LocalOptimizer):
# different numbers of dimensions (hence why we can
# discard its information - we know we can retrieve it
# later on).
compatible_order
=
(
"x"
,)
*
(
inp
ut
.
type
.
ndim
-
dsi0
.
type
.
ndim
)
+
tuple
(
compatible_order
=
(
"x"
,)
*
(
inp
.
type
.
ndim
-
dsi0
.
type
.
ndim
)
+
tuple
(
range
(
dsi0
.
type
.
ndim
)
)
if
dsop
.
new_order
==
compatible_order
:
# If the "new_order" is the one we recognize,
# we return the num_denum of the dimshuffled input.
return
self
.
get_num_denum
(
inp
ut
.
owner
.
inputs
[
0
])
return
self
.
get_num_denum
(
inp
.
owner
.
inputs
[
0
])
else
:
# This is when the input isn't produced by main,
# inverse or reciprocal.
return
[
inp
ut
],
[]
return
[
inp
],
[]
else
:
return
[
inp
ut
],
[]
return
[
inp
],
[]
num
=
[]
denum
=
[]
parent
=
inp
ut
.
owner
parent
=
inp
.
owner
# We get the (num, denum) pairs for each input
# pairs = [self.get_num_denum(input2) if input2.type.dtype ==
...
...
@@ -1699,22 +1699,22 @@ def local_opt_alloc(fgraph, node):
if
isinstance
(
node
.
op
,
Sum
)
or
isinstance
(
node
.
op
,
Prod
):
(
node_inps
,)
=
node
.
inputs
if
node_inps
.
owner
and
isinstance
(
node_inps
.
owner
.
op
,
Alloc
):
inp
ut
=
node_inps
.
owner
.
inputs
[
0
]
inp
=
node_inps
.
owner
.
inputs
[
0
]
shapes
=
node_inps
.
owner
.
inputs
[
1
:]
try
:
val
=
get_scalar_constant_value
(
inp
ut
,
only_process_constants
=
True
)
val
=
get_scalar_constant_value
(
inp
,
only_process_constants
=
True
)
assert
val
.
size
==
1
val
=
val
.
reshape
(
1
)[
0
]
# check which type of op
size
=
mul
(
*
shapes
)
if
inp
ut
.
dtype
in
[
"float16"
,
"float32"
]:
if
inp
.
dtype
in
[
"float16"
,
"float32"
]:
# shapes are ints and normally int64.
# We don't want to have a float64 upcast
# We don't want to downcast to float16
# as we fear it could loose too much precision
# that will be amplified by the mul/pow below.
size
=
size
.
astype
(
"float32"
)
if
node
.
op
.
axis
is
None
or
node
.
op
.
axis
==
tuple
(
range
(
inp
ut
.
ndim
)):
if
node
.
op
.
axis
is
None
or
node
.
op
.
axis
==
tuple
(
range
(
inp
.
ndim
)):
if
isinstance
(
node
.
op
,
Sum
):
val
=
val
*
size
else
:
...
...
@@ -2010,15 +2010,15 @@ def local_mul_specialize(fgraph, node):
new_inputs
=
[]
nb_neg_node
=
0
nb_cst
=
0
for
inp
ut
in
node
.
inputs
:
for
inp
in
node
.
inputs
:
# remove any neg arguments
while
inp
ut
.
owner
and
input
.
owner
.
op
==
neg
:
while
inp
.
owner
and
inp
.
owner
.
op
==
neg
:
has_neg
^=
True
inp
ut
=
input
.
owner
.
inputs
[
0
]
inp
=
inp
.
owner
.
inputs
[
0
]
nb_neg_node
+=
1
# remove special case arguments of 1, -1 or 0
y
=
local_mul_canonizer
.
get_constant
(
inp
ut
)
y
=
local_mul_canonizer
.
get_constant
(
inp
)
if
y
==
1.0
:
nb_cst
+=
1
elif
y
==
-
1.0
:
...
...
@@ -2028,7 +2028,7 @@ def local_mul_specialize(fgraph, node):
# if we find any zero, we just return right away
return
[
broadcast_like
(
0
,
node
.
outputs
[
0
],
fgraph
)]
else
:
new_inputs
.
append
(
inp
ut
)
new_inputs
.
append
(
inp
)
if
new_inputs
!=
node
.
inputs
:
if
new_inputs
:
...
...
@@ -2072,14 +2072,14 @@ def local_add_specialize(fgraph, node):
# to put in un-necessary fills.
if
node
.
op
==
add
:
new_inputs
=
[]
for
inp
ut
in
node
.
inputs
:
for
inp
in
node
.
inputs
:
try
:
y
=
get_scalar_constant_value
(
inp
ut
)
y
=
get_scalar_constant_value
(
inp
)
except
NotScalarConstantError
:
y
=
inp
ut
y
=
inp
if
np
.
all
(
y
==
0.0
):
continue
new_inputs
.
append
(
inp
ut
)
new_inputs
.
append
(
inp
)
if
len
(
new_inputs
)
<
len
(
node
.
inputs
):
dtype
=
node
.
outputs
[
0
]
.
type
.
dtype
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论