Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c378c628
提交
c378c628
authored
7月 09, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixes bug in mul canonizer
上级
0fe44b63
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
12 行增加
和
5 行删除
+12
-5
opt.py
theano/tensor/opt.py
+12
-5
没有找到文件。
theano/tensor/opt.py
浏览文件 @
c378c628
...
@@ -638,6 +638,7 @@ class Canonizer(gof.LocalOptimizer):
...
@@ -638,6 +638,7 @@ class Canonizer(gof.LocalOptimizer):
# Lists representing the numerator and denumerator
# Lists representing the numerator and denumerator
num
,
denum
=
list
(
orig_num
),
list
(
orig_denum
)
num
,
denum
=
list
(
orig_num
),
list
(
orig_denum
)
out_type
=
self
.
merge_num_denum
(
orig_num
,
orig_denum
)
.
type
# Lists representing the *constant* elements of num and denum
# Lists representing the *constant* elements of num and denum
numct
,
denumct
=
[],
[]
numct
,
denumct
=
[],
[]
...
@@ -660,14 +661,14 @@ class Canonizer(gof.LocalOptimizer):
...
@@ -660,14 +661,14 @@ class Canonizer(gof.LocalOptimizer):
# This will calculate either:
# This will calculate either:
# [inverse(main(*numct), main(*denumct))]
# [inverse(main(*numct), main(*denumct))]
# [] - if inverse(main(*numct), main(*denumct)) is the neutral element
# [] - if inverse(main(*numct), main(*denumct)) is the neutral element
ct
=
self
.
calculate
(
numct
,
denumct
,
aslist
=
True
)
ct
=
self
.
calculate
(
numct
,
denumct
,
aslist
=
True
,
out_type
=
out_type
)
else
:
else
:
# This happens if we don't allow the reciprocal and the
# This happens if we don't allow the reciprocal and the
# numerator is empty. That means we will need to represent
# numerator is empty. That means we will need to represent
# reciprocal(x) like inverse(neutral_element, x) so
# reciprocal(x) like inverse(neutral_element, x) so
# we can't allow ct == []
# we can't allow ct == []
# TODO: why is this branch needed when merge_num_denum does it for us?
# TODO: why is this branch needed when merge_num_denum does it for us?
ct
=
[
self
.
calculate
(
numct
,
denumct
,
aslist
=
False
)]
ct
=
[
self
.
calculate
(
numct
,
denumct
,
aslist
=
False
,
out_type
=
out_type
)]
# TODO: why are we not wrapping ct in a gof.Constant right now?
# TODO: why are we not wrapping ct in a gof.Constant right now?
if
orig_num
and
len
(
numct
)
==
1
and
len
(
denumct
)
==
0
and
ct
and
N
.
all
(
ct
==
self
.
get_constant
(
orig_num
[
0
])):
if
orig_num
and
len
(
numct
)
==
1
and
len
(
denumct
)
==
0
and
ct
and
N
.
all
(
ct
==
self
.
get_constant
(
orig_num
[
0
])):
...
@@ -725,13 +726,17 @@ class Canonizer(gof.LocalOptimizer):
...
@@ -725,13 +726,17 @@ class Canonizer(gof.LocalOptimizer):
return
getattr
(
self
,
'name'
,
'Canonizer(
%
s,
%
s,
%
s)'
%
(
self
.
main
,
self
.
inverse
,
self
.
reciprocal
))
return
getattr
(
self
,
'name'
,
'Canonizer(
%
s,
%
s,
%
s)'
%
(
self
.
main
,
self
.
inverse
,
self
.
reciprocal
))
def
mul_calculate
(
num
,
denum
,
aslist
=
False
):
def
mul_calculate
(
num
,
denum
,
aslist
=
False
,
out_type
=
None
):
if
not
num
and
not
denum
:
if
not
num
and
not
denum
:
# Smallest 1 possible.
# Smallest 1 possible.
return
[]
if
aslist
else
N
.
int8
(
1
)
return
[]
if
aslist
else
N
.
int8
(
1
)
# Make sure we do not accidently upcast data types.
# Make sure we do not accidently upcast data types.
if
out_type
is
None
:
# TODO: remove this error-causing heuristic
first
=
num
[
0
]
if
num
else
denum
[
0
]
first
=
num
[
0
]
if
num
else
denum
[
0
]
one
=
N
.
asarray
(
first
)
.
dtype
.
type
(
1
)
one
=
N
.
asarray
(
first
)
.
dtype
.
type
(
1
)
else
:
one
=
N
.
asarray
(
1
,
dtype
=
out_type
.
dtype
)
v
=
reduce
(
N
.
multiply
,
num
,
one
)
/
reduce
(
N
.
multiply
,
denum
,
one
)
v
=
reduce
(
N
.
multiply
,
num
,
one
)
/
reduce
(
N
.
multiply
,
denum
,
one
)
if
aslist
:
if
aslist
:
if
N
.
all
(
v
==
1
):
if
N
.
all
(
v
==
1
):
...
@@ -898,8 +903,10 @@ mul_canonizer = in2out(gof.LocalOptGroup(local_mul_canonizer, local_fill_cut, lo
...
@@ -898,8 +903,10 @@ mul_canonizer = in2out(gof.LocalOptGroup(local_mul_canonizer, local_fill_cut, lo
def
add_calculate
(
num
,
denum
,
aslist
=
False
):
def
add_calculate
(
num
,
denum
,
aslist
=
False
,
out_type
=
None
):
v
=
reduce
(
N
.
add
,
num
,
0.0
)
-
reduce
(
N
.
add
,
denum
,
0.0
)
#TODO: make sure that this function and mul_calculate are similar
zero
=
0.0
if
out_type
is
None
else
N
.
asarray
(
0
,
dtype
=
out_type
.
dtype
)
v
=
reduce
(
N
.
add
,
num
,
zero
)
-
reduce
(
N
.
add
,
denum
,
zero
)
if
aslist
:
if
aslist
:
if
N
.
all
(
v
==
0
):
if
N
.
all
(
v
==
0
):
return
[]
return
[]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论