Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f3da3cc4
提交
f3da3cc4
authored
6月 03, 2015
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactoring
上级
4be051f3
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
16 行增加
和
21 行删除
+16
-21
rng_mrg.py
theano/sandbox/rng_mrg.py
+16
-21
没有找到文件。
theano/sandbox/rng_mrg.py
浏览文件 @
f3da3cc4
...
@@ -1132,16 +1132,8 @@ class MRG_RandomStreams(object):
...
@@ -1132,16 +1132,8 @@ class MRG_RandomStreams(object):
for
old_r
,
new_r
,
size
,
nstreams
in
self
.
state_updates
:
for
old_r
,
new_r
,
size
,
nstreams
in
self
.
state_updates
:
if
nstreams
is
None
:
if
nstreams
is
None
:
nstreams
=
self
.
n_streams
(
size
)
nstreams
=
self
.
n_streams
(
size
)
rstates
=
self
.
get_substream_rstates
(
nstreams
)
rstates
=
self
.
get_substream_rstates
(
nstreams
,
if
self
.
use_cuda
and
new_r
.
owner
.
outputs
[
1
]
.
dtype
==
'float32'
:
new_r
.
owner
.
outputs
[
1
]
.
dtype
)
rstates
=
rstates
.
flatten
()
# HACK - we use fact that int32 and float32 have same size to
# sneak ints into the CudaNdarray type.
# these *SHOULD NEVER BE USED AS FLOATS*
tmp_float_buf
=
numpy
.
frombuffer
(
rstates
.
data
,
dtype
=
'float32'
)
assert
tmp_float_buf
.
shape
==
rstates
.
shape
assert
(
tmp_float_buf
.
view
(
'int32'
)
==
rstates
)
.
all
()
rstates
=
tmp_float_buf
assert
(
old_r
.
get_value
(
borrow
=
True
,
assert
(
old_r
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)
.
shape
==
return_internal_type
=
True
)
.
shape
==
rstates
.
shape
)
rstates
.
shape
)
...
@@ -1154,10 +1146,11 @@ class MRG_RandomStreams(object):
...
@@ -1154,10 +1146,11 @@ class MRG_RandomStreams(object):
self
.
rstate
=
multMatVect
(
self
.
rstate
,
A1p134
,
M1
,
A2p134
,
M2
)
self
.
rstate
=
multMatVect
(
self
.
rstate
,
A1p134
,
M1
,
A2p134
,
M2
)
assert
self
.
rstate
.
dtype
==
numpy
.
int32
assert
self
.
rstate
.
dtype
==
numpy
.
int32
def
get_substream_rstates
(
self
,
n_streams
,
inc_rstate
=
True
):
def
get_substream_rstates
(
self
,
n_streams
,
dtype
,
inc_rstate
=
True
):
"""Initialize a matrix in which each row is a MRG stream state,
"""Initialize a matrix in which each row is a MRG stream state,
and they are spaced by 2**72 samples.
and they are spaced by 2**72 samples.
"""
"""
assert
isinstance
(
dtype
,
str
)
assert
n_streams
<
2
**
72
assert
n_streams
<
2
**
72
assert
n_streams
>
0
assert
n_streams
>
0
rval
=
numpy
.
zeros
((
n_streams
,
6
),
dtype
=
'int32'
)
rval
=
numpy
.
zeros
((
n_streams
,
6
),
dtype
=
'int32'
)
...
@@ -1184,6 +1177,16 @@ class MRG_RandomStreams(object):
...
@@ -1184,6 +1177,16 @@ class MRG_RandomStreams(object):
if
inc_rstate
:
if
inc_rstate
:
self
.
inc_rstate
()
self
.
inc_rstate
()
if
self
.
use_cuda
and
dtype
==
'float32'
:
rval
=
rval
.
flatten
()
# HACK - we use fact that int32 and float32 have same size to
# sneak ints into the CudaNdarray type.
# these *SHOULD NEVER BE USED AS FLOATS*
tmp_float_buf
=
numpy
.
frombuffer
(
rval
.
data
,
dtype
=
'float32'
)
assert
tmp_float_buf
.
shape
==
rval
.
shape
assert
(
tmp_float_buf
.
view
(
'int32'
)
==
rval
)
.
all
()
rval
=
tmp_float_buf
return
rval
return
rval
def
n_streams
(
self
,
size
):
def
n_streams
(
self
,
size
):
...
@@ -1252,18 +1255,10 @@ class MRG_RandomStreams(object):
...
@@ -1252,18 +1255,10 @@ class MRG_RandomStreams(object):
orig_nstreams
=
nstreams
orig_nstreams
=
nstreams
if
nstreams
is
None
:
if
nstreams
is
None
:
nstreams
=
self
.
n_streams
(
size
)
nstreams
=
self
.
n_streams
(
size
)
rstates
=
self
.
get_substream_rstates
(
nstreams
)
rstates
=
self
.
get_substream_rstates
(
nstreams
,
dtype
)
if
self
.
use_cuda
and
dtype
==
'float32'
:
if
self
.
use_cuda
and
dtype
==
'float32'
:
rstates
=
rstates
.
flatten
()
node_rstate
=
float32_shared_constructor
(
rstates
)
# HACK - we use fact that int32 and float32 have same size to
# sneak ints into the CudaNdarray type.
# these *SHOULD NEVER BE USED AS FLOATS*
tmp_float_buf
=
numpy
.
frombuffer
(
rstates
.
data
,
dtype
=
'float32'
)
assert
tmp_float_buf
.
shape
==
rstates
.
shape
assert
(
tmp_float_buf
.
view
(
'int32'
)
==
rstates
)
.
all
()
# transfer to device
node_rstate
=
float32_shared_constructor
(
tmp_float_buf
)
assert
isinstance
(
node_rstate
.
type
,
CudaNdarrayType
)
assert
isinstance
(
node_rstate
.
type
,
CudaNdarrayType
)
# we can't use the normal mrg_uniform constructor + later
# we can't use the normal mrg_uniform constructor + later
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论