Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
efc5e1c0
提交
efc5e1c0
authored
2月 18, 2010
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Modified local_pow_canonicalize and local_pow_specialize to not use fill()
上级
35635bf3
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
37 行增加
和
17 行删除
+37
-17
opt.py
theano/tensor/opt.py
+37
-17
没有找到文件。
theano/tensor/opt.py
浏览文件 @
efc5e1c0
...
@@ -103,6 +103,19 @@ def scalarconsts_rest(inputs):
...
@@ -103,6 +103,19 @@ def scalarconsts_rest(inputs):
nonconsts
.
append
(
i
)
nonconsts
.
append
(
i
)
return
consts
,
origconsts
,
nonconsts
return
consts
,
origconsts
,
nonconsts
def
broadcast_like
(
value
,
template
,
env
):
"""Return a Variable with the same shape and dtype as the template,
filled by broadcasting value through it. `value` will be casted as necessary.
"""
shape_of
=
env
.
shape_feature
.
shape_of
if
template
not
in
shape_of
:
raise
NotImplementedError
(
'broadcast_like currently requires the template Variable to be in the env already'
)
rval
=
T
.
Alloc
(
template
.
dtype
)(
value
,
*
shape_of
[
template
])
assert
rval
.
type
==
template
.
type
return
rval
@gof.optimizer
@gof.optimizer
def
insert_inplace_optimizer
(
env
):
def
insert_inplace_optimizer
(
env
):
"""
"""
...
@@ -1265,11 +1278,10 @@ register_canonicalize(local_inv_canon)
...
@@ -1265,11 +1278,10 @@ register_canonicalize(local_inv_canon)
@gof.local_optimizer
([
T
.
pow
])
@gof.local_optimizer
([
T
.
pow
])
def
local_pow_canonicalize
(
node
):
def
local_pow_canonicalize
(
node
):
if
node
.
op
==
T
.
pow
:
if
node
.
op
==
T
.
pow
:
if
N
.
all
(
local_mul_canonizer
.
get_constant
(
node
.
inputs
[
1
])
==
1.0
):
if
N
.
all
(
local_mul_canonizer
.
get_constant
(
node
.
inputs
[
1
])
==
0
):
return
[
T
.
fill
(
node
.
inputs
[
1
],
node
.
inputs
[
0
])]
return
[
broadcast_like
(
1
,
node
.
outputs
[
0
],
node
.
env
)]
if
N
.
all
(
local_mul_canonizer
.
get_constant
(
node
.
inputs
[
1
])
==
0.0
):
if
N
.
all
(
local_mul_canonizer
.
get_constant
(
node
.
inputs
[
1
])
==
1
):
#extra fills here are to make sure the size of the output stays constant.
return
[
broadcast_like
(
node
.
inputs
[
0
],
node
.
outputs
[
0
],
node
.
env
)]
return
[
T
.
fill
(
node
.
inputs
[
0
],
T
.
fill
(
node
.
inputs
[
1
],
1.0
))]
else
:
else
:
return
False
return
False
register_canonicalize
(
local_pow_canonicalize
)
register_canonicalize
(
local_pow_canonicalize
)
...
@@ -1279,25 +1291,33 @@ def local_pow_specialize(node):
...
@@ -1279,25 +1291,33 @@ def local_pow_specialize(node):
#here, we are past the point of canonicalization, so we don't want to put in un-necessary fills.
#here, we are past the point of canonicalization, so we don't want to put in un-necessary fills.
if
node
.
op
==
T
.
pow
:
if
node
.
op
==
T
.
pow
:
#the idea here is that we have pow(x, y)
#the idea here is that we have pow(x, y)
odtype
=
node
.
outputs
[
0
]
.
dtype
xsym
=
node
.
inputs
[
0
]
xsym
=
node
.
inputs
[
0
]
ysym
=
node
.
inputs
[
1
]
ysym
=
node
.
inputs
[
1
]
y
=
local_mul_canonizer
.
get_constant
(
ysym
)
y
=
local_mul_canonizer
.
get_constant
(
ysym
)
if
(
y
is
not
None
)
\
if
(
y
is
not
None
)
\
and
encompasses_broadcastable
(
xsym
.
type
.
broadcastable
,
ysym
.
type
.
broadcastable
):
and
encompasses_broadcastable
(
xsym
.
type
.
broadcastable
,
ysym
.
type
.
broadcastable
):
if
N
.
all
(
y
==
2.0
):
rval
=
None
return
[
T
.
sqr
(
xsym
)]
if
N
.
all
(
y
==
1.0
):
if
N
.
all
(
y
==
2
):
return
[
xsym
]
rval
=
[
T
.
sqr
(
xsym
)]
if
N
.
all
(
y
==
0.0
):
if
N
.
all
(
y
==
1
):
return
[
T
.
fill
(
xsym
,
1.0
)]
rval
=
[
xsym
]
if
N
.
all
(
y
==
0
):
rval
=
[
T
.
fill
(
xsym
,
numpy
.
asarray
(
1
,
dtype
=
odtype
))]
if
N
.
all
(
y
==
0.5
):
if
N
.
all
(
y
==
0.5
):
r
eturn
[
T
.
sqrt
(
xsym
)]
r
val
=
[
T
.
sqrt
(
xsym
)]
if
N
.
all
(
y
==
-
0.5
):
if
N
.
all
(
y
==
-
0.5
):
return
[
T
.
inv
(
T
.
sqrt
(
xsym
))]
rval
=
[
T
.
inv
(
T
.
sqrt
(
xsym
))]
if
N
.
all
(
y
==
-
1.0
):
if
N
.
all
(
y
==
-
1
):
return
[
T
.
inv
(
xsym
)]
rval
=
[
T
.
inv
(
xsym
)]
if
N
.
all
(
y
==
-
2.0
):
if
N
.
all
(
y
==
-
2
):
return
[
T
.
inv
(
T
.
sqr
(
xsym
))]
rval
=
[
T
.
inv
(
T
.
sqr
(
xsym
))]
if
rval
:
rval
[
0
]
=
T
.
cast
(
rval
[
0
],
odtype
)
assert
rval
[
0
]
.
type
==
node
.
outputs
[
0
]
.
type
,
(
rval
,
node
.
outputs
)
return
rval
else
:
else
:
return
False
return
False
register_specialize
(
local_pow_specialize
)
register_specialize
(
local_pow_specialize
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论