Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
dd478b4e
提交
dd478b4e
authored
5月 15, 2015
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix gpu lazy opt warning
上级
51368a6b
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
42 行增加
和
5 行删除
+42
-5
opt.py
theano/sandbox/cuda/opt.py
+15
-5
test_ifelse.py
theano/tests/test_ifelse.py
+27
-0
没有找到文件。
theano/sandbox/cuda/opt.py
浏览文件 @
dd478b4e
...
@@ -497,12 +497,19 @@ def local_gpu_lazy_ifelse(node):
...
@@ -497,12 +497,19 @@ def local_gpu_lazy_ifelse(node):
# Should not happen, but just in case
# Should not happen, but just in case
if
isinstance
(
c
.
type
,
CudaNdarrayType
):
if
isinstance
(
c
.
type
,
CudaNdarrayType
):
c
=
host_from_gpu
(
c
)
c
=
host_from_gpu
(
c
)
if
all
([
isinstance
(
o
.
type
,
CudaNdarrayType
)
or
o
.
dtype
!=
'float32'
for
o
in
outs
]):
return
for
i
in
range
(
len
(
outs
)):
for
i
in
range
(
len
(
outs
)):
if
not
isinstance
(
outs
[
i
],
CudaNdarrayType
):
if
(
not
isinstance
(
outs
[
i
]
.
type
,
CudaNdarrayType
)
and
outs
[
i
]
.
dtype
==
'float32'
):
outs
[
i
]
=
gpu_from_host
(
outs
[
i
])
outs
[
i
]
=
gpu_from_host
(
outs
[
i
])
return
[
host_from_gpu
(
out
)
for
out
in
outs
=
gpu_ifelse
(
c
,
*
outs
,
return_list
=
True
)
gpu_ifelse
.
make_node
(
c
,
*
outs
)
.
outputs
]
for
i
in
range
(
len
(
outs
)):
if
isinstance
(
outs
[
i
]
.
type
,
CudaNdarrayType
):
outs
[
i
]
=
host_from_gpu
(
outs
[
i
])
return
outs
if
isinstance
(
node
.
op
,
GpuFromHost
):
if
isinstance
(
node
.
op
,
GpuFromHost
):
host_input
=
node
.
inputs
[
0
]
host_input
=
node
.
inputs
[
0
]
...
@@ -522,11 +529,14 @@ def local_gpu_lazy_ifelse(node):
...
@@ -522,11 +529,14 @@ def local_gpu_lazy_ifelse(node):
# Should not happen, but just in case
# Should not happen, but just in case
if
isinstance
(
c
.
type
,
CudaNdarrayType
):
if
isinstance
(
c
.
type
,
CudaNdarrayType
):
c
=
host_from_gpu
(
c
)
c
=
host_from_gpu
(
c
)
if
all
([
isinstance
(
o
.
type
,
CudaNdarrayType
)
or
o
.
dtype
!=
'float32'
for
o
in
outs
]):
return
for
i
in
range
(
len
(
outs
)):
for
i
in
range
(
len
(
outs
)):
if
not
isinstance
(
outs
[
i
],
CudaNdarrayType
):
if
(
not
isinstance
(
outs
[
i
]
.
type
,
CudaNdarrayType
)
and
outs
[
i
]
.
dtype
==
'float32'
):
outs
[
i
]
=
gpu_from_host
(
outs
[
i
])
outs
[
i
]
=
gpu_from_host
(
outs
[
i
])
outs
=
gpu_ifelse
.
make_node
(
c
,
*
outs
)
.
outputs
outs
=
gpu_ifelse
.
make_node
(
c
,
*
outs
)
.
outputs
return
outs
return
outs
...
...
theano/tests/test_ifelse.py
浏览文件 @
dd478b4e
...
@@ -51,6 +51,33 @@ class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -51,6 +51,33 @@ 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_mixed_dtype
(
self
):
x1
=
tensor
.
vector
(
'x1'
,
dtype
=
'int32'
)
x2
=
tensor
.
vector
(
'x2'
,
dtype
=
self
.
dtype
)
y1
=
tensor
.
vector
(
'y1'
,
dtype
=
'int32'
)
y2
=
tensor
.
vector
(
'y2'
,
dtype
=
self
.
dtype
)
c
=
tensor
.
iscalar
(
'c'
)
f
=
theano
.
function
([
c
,
x1
,
x2
,
y1
,
y2
],
ifelse
(
c
,
(
x1
,
x2
),
(
y1
,
y2
)),
mode
=
self
.
mode
)
self
.
assertFunctionContains1
(
f
,
self
.
get_ifelse
(
2
))
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
xlen
=
rng
.
randint
(
200
)
ylen
=
rng
.
randint
(
200
)
vx1
=
numpy
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,))
*
3
,
'int32'
)
vx2
=
numpy
.
asarray
(
rng
.
uniform
(
size
=
(
xlen
,)),
self
.
dtype
)
vy1
=
numpy
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,))
*
3
,
'int32'
)
vy2
=
numpy
.
asarray
(
rng
.
uniform
(
size
=
(
ylen
,)),
self
.
dtype
)
o1
,
o2
=
f
(
1
,
vx1
,
vx2
,
vy1
,
vy2
)
assert
numpy
.
allclose
(
vx1
,
o1
)
assert
numpy
.
allclose
(
vx2
,
o2
)
o1
,
o2
=
f
(
0
,
vx1
,
vx2
,
vy1
,
vy2
)
assert
numpy
.
allclose
(
vy1
,
o1
)
assert
numpy
.
allclose
(
vy2
,
o2
)
def
test_lazy_if_on_generics
(
self
):
def
test_lazy_if_on_generics
(
self
):
x
=
theano
.
generic
()
x
=
theano
.
generic
()
y
=
theano
.
generic
()
y
=
theano
.
generic
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论