Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ee7fa8b5
提交
ee7fa8b5
authored
9月 09, 2015
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Disable ifelse opt to make it inplace with scalar and big graph
上级
f106536d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
33 行增加
和
1 行删除
+33
-1
ifelse.py
theano/ifelse.py
+7
-1
test_ifelse.py
theano/tests/test_ifelse.py
+26
-0
没有找到文件。
theano/ifelse.py
浏览文件 @
ee7fa8b5
...
@@ -395,7 +395,13 @@ def ifelse(condition, then_branch, else_branch, name=None):
...
@@ -395,7 +395,13 @@ def ifelse(condition, then_branch, else_branch, name=None):
@gof.local_optimizer
([
IfElse
])
@gof.local_optimizer
([
IfElse
])
def
cond_make_inplace
(
node
):
def
cond_make_inplace
(
node
):
op
=
node
.
op
op
=
node
.
op
if
isinstance
(
op
,
IfElse
)
and
not
op
.
as_view
:
if
(
isinstance
(
op
,
IfElse
)
and
not
op
.
as_view
and
# For big graph, do not make inplace scalar to speed up
# optimization.
(
len
(
node
.
fgraph
.
apply_nodes
)
<
500
or
not
all
([
getattr
(
o
.
type
,
'ndim'
,
-
1
)
==
0
for
o
in
node
.
outputs
]))):
return
IfElse
(
n_outs
=
op
.
n_outs
,
return
IfElse
(
n_outs
=
op
.
n_outs
,
as_view
=
True
,
as_view
=
True
,
gpu
=
op
.
gpu
,
gpu
=
op
.
gpu
,
...
...
theano/tests/test_ifelse.py
浏览文件 @
ee7fa8b5
...
@@ -51,6 +51,32 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -51,6 +51,32 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
assert
numpy
.
allclose
(
vx
,
f
(
1
,
vx
,
vy
))
assert
numpy
.
allclose
(
vx
,
f
(
1
,
vx
,
vy
))
assert
numpy
.
allclose
(
vy
,
f
(
0
,
vx
,
vy
))
assert
numpy
.
allclose
(
vy
,
f
(
0
,
vx
,
vy
))
def
test_not_lazy_if_inplace
(
self
):
# Tests that if the outputs are scalars and the graph is big,
# we disable the inplace opt to speed up optimization
x
=
tensor
.
vector
(
'x'
,
dtype
=
self
.
dtype
)
y
=
tensor
.
vector
(
'y'
,
dtype
=
self
.
dtype
)
c
=
tensor
.
iscalar
(
'c'
)
mode
=
theano
.
compile
.
get_mode
(
self
.
mode
)
.
excluding
(
# Disable many opt to keep the graph big enough to disable
# the opt.
'fusion'
,
'local_add_canonizer'
,
'inplace'
,
'constant_folding'
,
'constant_folding'
)
y2
=
reduce
(
lambda
x
,
y
:
x
+
y
,
[
y
]
+
range
(
200
))
f
=
theano
.
function
([
c
,
x
,
y
],
ifelse
(
c
,
x
,
y2
),
mode
=
mode
)
# For not inplace ifelse
self
.
assertFunctionContains1
(
f
,
IfElse
(
1
))
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
xlen
=
rng
.
randint
(
200
)
ylen
=
rng
.
randint
(
200
)
vx
=
numpy
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,)),
self
.
dtype
)
vy
=
numpy
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,)),
self
.
dtype
)
assert
numpy
.
allclose
(
vx
,
f
(
1
,
vx
,
vy
))
assert
numpy
.
allclose
(
vy
+
sum
(
range
(
200
)),
f
(
0
,
vx
,
vy
))
def
test_mixed_dtype
(
self
):
def
test_mixed_dtype
(
self
):
x1
=
tensor
.
vector
(
'x1'
,
dtype
=
'int32'
)
x1
=
tensor
.
vector
(
'x1'
,
dtype
=
'int32'
)
x2
=
tensor
.
vector
(
'x2'
,
dtype
=
self
.
dtype
)
x2
=
tensor
.
vector
(
'x2'
,
dtype
=
self
.
dtype
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论