Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c229fa84
提交
c229fa84
authored
11月 29, 2016
作者:
Simon Lefrancois
提交者:
GitHub
11月 29, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5288 from chinnadhurai/ccw_4916
fix crash in MRG_RandomStreams with the new backend
上级
cdac0c69
ce832a18
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
55 行增加
和
14 行删除
+55
-14
rng_mrg.py
theano/sandbox/rng_mrg.py
+44
-14
test_rng_mrg.py
theano/sandbox/tests/test_rng_mrg.py
+11
-0
没有找到文件。
theano/sandbox/rng_mrg.py
浏览文件 @
c229fa84
...
...
@@ -24,7 +24,8 @@ from . import multinomial
import
theano.sandbox.cuda
from
theano.sandbox.cuda
import
GpuOp
from
theano.gpuarray.basic_ops
import
GpuKernelBase
,
Kernel
,
infer_context_name
from
theano.sandbox.cuda.basic_ops
import
as_cuda_ndarray_variable
from
theano.gpuarray.basic_ops
import
GpuKernelBase
,
Kernel
,
infer_context_name
,
as_gpuarray_variable
from
theano.gpuarray.type
import
GpuArrayType
from
theano.gpuarray.fp16_help
import
write_w
from
theano.gpuarray.opt
import
(
register_opt
as
register_gpua
,
...
...
@@ -312,19 +313,6 @@ class mrg_uniform_base(Op):
s
=
"no_inplace"
return
self
.
__class__
.
__name__
+
"{
%
s,
%
s}"
%
(
self
.
output_type
,
s
)
def
make_node
(
self
,
rstate
,
size
):
# error checking slightly redundant here, since
# this op should not be called directly.
#
# call through MRG_RandomStreams instead.
broad
=
[]
for
i
in
range
(
self
.
output_type
.
ndim
):
broad
.
append
(
tensor
.
extract_constant
(
size
[
i
])
==
1
)
output_type
=
self
.
output_type
.
clone
(
broadcastable
=
broad
)()
return
Apply
(
self
,
[
rstate
,
size
],
[
rstate
.
type
(),
output_type
])
def
grad
(
self
,
inputs
,
ograd
):
return
[
gradient
.
grad_undefined
(
self
,
k
,
inp
,
'No gradient defined through '
...
...
@@ -338,6 +326,20 @@ class mrg_uniform_base(Op):
class
mrg_uniform
(
mrg_uniform_base
):
# CPU VERSION
def
make_node
(
self
,
rstate
,
size
):
# error checking slightly redundant here, since
# this op should not be called directly.
#
# call through MRG_RandomStreams instead.
broad
=
[]
for
i
in
range
(
self
.
output_type
.
ndim
):
broad
.
append
(
tensor
.
extract_constant
(
size
[
i
])
==
1
)
output_type
=
self
.
output_type
.
clone
(
broadcastable
=
broad
)()
rstate
=
as_tensor_variable
(
rstate
)
return
Apply
(
self
,
[
rstate
,
size
],
[
rstate
.
type
(),
output_type
])
@classmethod
def
new
(
cls
,
rstate
,
ndim
,
dtype
,
size
):
v_size
=
as_tensor_variable
(
size
)
...
...
@@ -564,6 +566,20 @@ class mrg_uniform(mrg_uniform_base):
class
GPU_mrg_uniform
(
mrg_uniform_base
,
GpuOp
):
# GPU VERSION
def
make_node
(
self
,
rstate
,
size
):
# error checking slightly redundant here, since
# this op should not be called directly.
#
# call through MRG_RandomStreams instead.
broad
=
[]
for
i
in
range
(
self
.
output_type
.
ndim
):
broad
.
append
(
tensor
.
extract_constant
(
size
[
i
])
==
1
)
output_type
=
self
.
output_type
.
clone
(
broadcastable
=
broad
)()
rstate
=
as_cuda_ndarray_variable
(
rstate
)
return
Apply
(
self
,
[
rstate
,
size
],
[
rstate
.
type
(),
output_type
])
@classmethod
def
new
(
cls
,
rstate
,
ndim
,
dtype
,
size
):
v_size
=
as_tensor_variable
(
size
)
...
...
@@ -809,6 +825,20 @@ class GPUA_mrg_uniform(GpuKernelBase, mrg_uniform_base):
# GpuArray version
_f16_ok
=
True
def
make_node
(
self
,
rstate
,
size
):
# error checking slightly redundant here, since
# this op should not be called directly.
#
# call through MRG_RandomStreams instead.
broad
=
[]
for
i
in
range
(
self
.
output_type
.
ndim
):
broad
.
append
(
tensor
.
extract_constant
(
size
[
i
])
==
1
)
output_type
=
self
.
output_type
.
clone
(
broadcastable
=
broad
)()
rstate
=
as_gpuarray_variable
(
rstate
,
infer_context_name
(
rstate
))
return
Apply
(
self
,
[
rstate
,
size
],
[
rstate
.
type
(),
output_type
])
def
get_params
(
self
,
node
):
return
node
.
inputs
[
0
]
.
type
.
context
...
...
theano/sandbox/tests/test_rng_mrg.py
浏览文件 @
c229fa84
...
...
@@ -18,6 +18,7 @@ from theano.sandbox.rng_mrg import MRG_RandomStreams
from
theano.sandbox.cuda
import
cuda_available
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests.unittest_tools
import
attr
import
theano.gpuarray.tests.config
if
cuda_available
:
from
theano.sandbox.cuda
import
float32_shared_constructor
...
...
@@ -1178,6 +1179,16 @@ def test_overflow_gpu_new_backend():
rng_mrg_overflow
(
sizes
,
fct
,
mode
,
should_raise_error
=
False
)
def
test_validate_input_types_gpuarray_backend
():
from
theano.sandbox.rng_mrg
import
mrg_uniform
from
theano.gpuarray.type
import
gpuarray_shared_constructor
from
theano.configparser
import
change_flags
with
change_flags
(
compute_test_value
=
"raise"
):
rstate
=
numpy
.
zeros
((
7
,
6
),
dtype
=
"int32"
)
rstate
=
gpuarray_shared_constructor
(
rstate
)
mrg_uniform
.
new
(
rstate
,
ndim
=
None
,
dtype
=
"float32"
,
size
=
(
3
,))
if
__name__
==
"__main__"
:
rng
=
MRG_RandomStreams
(
numpy
.
random
.
randint
(
2147462579
))
print
(
theano
.
__file__
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论