Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f41011a9
提交
f41011a9
authored
5月 10, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
moved test of rng_mrg to a separate file and fix one of the tests.
上级
aca8eb0e
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
155 行增加
和
151 行删除
+155
-151
rng_mrg.py
theano/sandbox/rng_mrg.py
+5
-151
test_rng_mrg.py
theano/sandbox/test_rng_mrg.py
+150
-0
没有找到文件。
theano/sandbox/rng_mrg.py
浏览文件 @
f41011a9
...
...
@@ -14,9 +14,9 @@ from theano.tensor import zeros_like, sqrt, log, sin, cos, join
from
theano.compile
import
optdb
from
theano.gof
import
local_optimizer
from
theano.sandbox.cuda
import
cuda_
enabled
if
cuda_
enabled
:
from
theano.sandbox.cuda
import
CudaNdarrayType
from
theano.sandbox.cuda
import
cuda_
available
if
cuda_
available
:
from
theano.sandbox.cuda
import
CudaNdarrayType
,
float32_shared_constructor
def
mulmod
(
a
,
b
,
c
,
m
):
r
=
numpy
.
int32
((
numpy
.
int64
(
a
)
*
b
+
c
)
%
m
)
...
...
@@ -628,7 +628,7 @@ class MRG_RandomStreams(object):
tmp_float_buf
=
numpy
.
frombuffer
(
rstates
.
data
,
dtype
=
'float32'
)
assert
tmp_float_buf
.
shape
==
rstates
.
shape
assert
tmp_float_buf
.
data
[:
24
]
==
rstates
.
data
[:
24
]
node_rstate
=
shared
(
tmp_float_buf
)
# transfer to device
node_rstate
=
float32_shared_constructor
(
tmp_float_buf
)
# transfer to device
assert
isinstance
(
node_rstate
.
type
,
CudaNdarrayType
)
# we can't use the normal mrg_uniform constructor + later optimization
...
...
@@ -706,154 +706,8 @@ def mrg_random_make_inplace(node):
optdb
.
register
(
'random_make_inplace_mrg'
,
opt
.
in2out
(
mrg_random_make_inplace
,
ignore_newtrees
=
True
),
99
,
'fast_run'
,
'inplace'
)
#
#
#
#
#
import
time
import
theano
def
test_rng0
():
def
basictest
(
f
,
steps
,
prefix
=
""
):
dt
=
0.0
for
i
in
xrange
(
steps
):
t0
=
time
.
time
()
ival
=
f
()
dt
+=
time
.
time
()
-
t0
ival
=
numpy
.
asarray
(
ival
)
if
i
==
0
:
mean
=
numpy
.
array
(
ival
,
copy
=
True
)
else
:
alpha
=
1.0
/
(
1
+
i
)
mean
=
alpha
*
ival
+
(
1
-
alpha
)
*
mean
print
prefix
,
'mean'
,
numpy
.
mean
(
mean
)
assert
abs
(
numpy
.
mean
(
mean
)
-
0.5
)
<
.
01
,
'bad mean?'
print
prefix
,
'time'
,
dt
print
prefix
,
'elements'
,
steps
*
sample_size
[
0
]
*
sample_size
[
1
]
print
prefix
,
'samples/sec'
,
steps
*
sample_size
[
0
]
*
sample_size
[
1
]
/
dt
if
0
:
mean
,
std
,
min
,
max
=
numpy
.
mean
(
l
),
numpy
.
std
(
l
),
numpy
.
min
(
l
),
numpy
.
max
(
l
)
print
prefix
,
'mean'
,
mean
print
prefix
,
'std'
,
std
print
prefix
,
'min'
,
repr
(
min
)
print
prefix
,
'max'
,
repr
(
max
)
assert
max
<
1.0
assert
min
>=
0.0
assert
abs
(
mean
-
0.5
)
<
.
01
,
'bad mean?'
sample_size
=
(
1000
,
100
)
print
''
print
'ON CPU:'
R
=
MRG_RandomStreams
(
234
,
use_cuda
=
False
)
u
=
R
.
uniform
(
size
=
sample_size
)
f
=
theano
.
function
([],
u
)
theano
.
printing
.
debugprint
(
f
)
print
'random?[:10]
\n
'
,
f
()[
0
,
0
:
10
]
basictest
(
f
,
1000
,
prefix
=
'mrg '
)
print
''
print
'ON GPU:'
R
=
MRG_RandomStreams
(
234
,
use_cuda
=
True
)
u
=
R
.
uniform
(
size
=
sample_size
)
assert
u
.
dtype
==
'float32'
#well, it's really that this test w GPU doesn't make sense otw
f
=
theano
.
function
([],
theano
.
Out
(
theano
.
sandbox
.
cuda
.
basic_ops
.
gpu_from_host
(
u
),
borrow
=
True
))
theano
.
printing
.
debugprint
(
f
)
print
'random?[:10]
\n
'
,
numpy
.
asarray
(
f
())[
0
,
0
:
10
]
basictest
(
f
,
1000
,
prefix
=
'mrg '
)
print
''
print
'ON CPU w NUMPY:'
RR
=
theano
.
tensor
.
shared_randomstreams
.
RandomStreams
(
234
)
uu
=
RR
.
uniform
(
size
=
sample_size
)
ff
=
theano
.
function
([],
uu
)
basictest
(
ff
,
1000
,
prefix
=
'numpy'
)
def
test_normal0
():
def
basictest
(
f
,
steps
,
target_avg
,
target_std
,
prefix
=
""
):
dt
=
0.0
avg_std
=
0.0
for
i
in
xrange
(
steps
):
t0
=
time
.
time
()
ival
=
f
()
dt
+=
time
.
time
()
-
t0
ival
=
numpy
.
asarray
(
ival
)
if
i
==
0
:
mean
=
numpy
.
array
(
ival
,
copy
=
True
)
avg_std
=
numpy
.
std
(
ival
)
else
:
alpha
=
1.0
/
(
1
+
i
)
mean
=
alpha
*
ival
+
(
1
-
alpha
)
*
mean
avg_std
=
alpha
*
numpy
.
std
(
ival
)
+
(
1
-
alpha
)
*
avg_std
print
prefix
,
'mean'
,
numpy
.
mean
(
mean
)
assert
abs
(
numpy
.
mean
(
mean
)
-
target_avg
)
<
.
01
,
'bad mean?'
print
prefix
,
'std'
,
avg_std
assert
abs
(
avg_std
-
target_std
)
<
.
01
,
'bad std?'
print
prefix
,
'time'
,
dt
print
prefix
,
'elements'
,
steps
*
sample_size
[
0
]
*
sample_size
[
1
]
print
prefix
,
'samples/sec'
,
steps
*
sample_size
[
0
]
*
sample_size
[
1
]
/
dt
sample_size
=
(
999
,
100
)
print
''
print
'ON CPU:'
R
=
MRG_RandomStreams
(
234
,
use_cuda
=
False
)
n
=
R
.
normal
(
size
=
sample_size
,
avg
=-
5.0
,
std
=
2.0
)
f
=
theano
.
function
([],
n
)
theano
.
printing
.
debugprint
(
f
)
print
'random?[:10]
\n
'
,
f
()[
0
,
0
:
10
]
basictest
(
f
,
50
,
-
5.0
,
2.0
,
prefix
=
'mrg '
)
sys
.
stdout
.
flush
()
# now with odd number of samples
sample_size
=
(
999
,
99
)
print
''
print
'ON GPU:'
R
=
MRG_RandomStreams
(
234
,
use_cuda
=
True
)
n
=
R
.
normal
(
size
=
sample_size
,
avg
=-
5.0
,
std
=
2.0
,
dtype
=
'float32'
)
assert
n
.
dtype
==
'float32'
#well, it's really that this test w GPU doesn't make sense otw
f
=
theano
.
function
([],
theano
.
Out
(
theano
.
sandbox
.
cuda
.
basic_ops
.
gpu_from_host
(
n
),
borrow
=
True
))
theano
.
printing
.
debugprint
(
f
)
sys
.
stdout
.
flush
()
print
'random?[:10]
\n
'
,
numpy
.
asarray
(
f
())[
0
,
0
:
10
]
print
'----'
sys
.
stdout
.
flush
()
basictest
(
f
,
50
,
-
5.0
,
2.0
,
prefix
=
'gpu mrg '
)
print
''
print
'ON CPU w NUMPY:'
RR
=
theano
.
tensor
.
shared_randomstreams
.
RandomStreams
(
234
)
nn
=
RR
.
normal
(
size
=
sample_size
,
avg
=-
5.0
,
std
=
2.0
)
ff
=
theano
.
function
([],
nn
)
basictest
(
ff
,
50
,
-
5.0
,
2.0
,
prefix
=
'numpy '
)
if
__name__
==
'__main__'
:
# with: export THEANO_FLAGS=device=gpu0,floatX=float32
test_normal0
()
#
test_normal0()
theano/sandbox/test_rng_mrg.py
0 → 100644
浏览文件 @
f41011a9
import
sys
,
time
import
numpy
import
theano
from
theano.sandbox.rng_mrg
import
MRG_RandomStreams
#TODO: test gpu
#TODO: test MRG_RandomStreams
#TODO: test optimizer mrg_random_make_inplace
#def test_rng_mrg_cpu():
#TODO: make tests work when no flags gived. Now need: THEANO_FLAGS=device=gpu0,floatX=float32
#TODO: bug fix test_normal0, in normal() fct, n_samples currently need to be numpy.prod(size) not self.n_streams(size)
def
test_rng0
():
def
basictest
(
f
,
steps
,
prefix
=
""
):
dt
=
0.0
for
i
in
xrange
(
steps
):
t0
=
time
.
time
()
ival
=
f
()
dt
+=
time
.
time
()
-
t0
ival
=
numpy
.
asarray
(
ival
)
if
i
==
0
:
mean
=
numpy
.
array
(
ival
,
copy
=
True
)
else
:
alpha
=
1.0
/
(
1
+
i
)
mean
=
alpha
*
ival
+
(
1
-
alpha
)
*
mean
assert
ival
.
min
()
>
0
and
ival
.
max
()
<
1
print
prefix
,
'mean'
,
numpy
.
mean
(
mean
)
assert
abs
(
numpy
.
mean
(
mean
)
-
0.5
)
<
.
01
,
'bad mean?'
print
prefix
,
'time'
,
dt
print
prefix
,
'elements'
,
steps
*
sample_size
[
0
]
*
sample_size
[
1
]
print
prefix
,
'samples/sec'
,
steps
*
sample_size
[
0
]
*
sample_size
[
1
]
/
dt
if
0
:
mean
,
std
,
min
,
max
=
numpy
.
mean
(
l
),
numpy
.
std
(
l
),
numpy
.
min
(
l
),
numpy
.
max
(
l
)
print
prefix
,
'mean'
,
mean
print
prefix
,
'std'
,
std
print
prefix
,
'min'
,
repr
(
min
)
print
prefix
,
'max'
,
repr
(
max
)
assert
max
<
1.0
assert
min
>=
0.0
assert
abs
(
mean
-
0.5
)
<
.
01
,
'bad mean?'
sample_size
=
(
1000
,
100
)
print
''
print
'ON CPU:'
R
=
MRG_RandomStreams
(
234
,
use_cuda
=
False
)
u
=
R
.
uniform
(
size
=
sample_size
)
f
=
theano
.
function
([],
u
)
theano
.
printing
.
debugprint
(
f
)
print
'random?[:10]
\n
'
,
f
()[
0
,
0
:
10
]
basictest
(
f
,
1000
,
prefix
=
'mrg '
)
print
''
print
'ON GPU:'
R
=
MRG_RandomStreams
(
234
,
use_cuda
=
True
)
u
=
R
.
uniform
(
size
=
sample_size
,
dtype
=
'float32'
)
assert
u
.
dtype
==
'float32'
#well, it's really that this test w GPU doesn't make sense otw
f
=
theano
.
function
([],
theano
.
Out
(
theano
.
sandbox
.
cuda
.
basic_ops
.
gpu_from_host
(
u
),
borrow
=
True
))
theano
.
printing
.
debugprint
(
f
)
print
'random?[:10]
\n
'
,
numpy
.
asarray
(
f
())[
0
,
0
:
10
]
basictest
(
f
,
1000
,
prefix
=
'mrg '
)
print
''
print
'ON CPU w NUMPY:'
RR
=
theano
.
tensor
.
shared_randomstreams
.
RandomStreams
(
234
)
uu
=
RR
.
uniform
(
size
=
sample_size
)
ff
=
theano
.
function
([],
uu
)
basictest
(
ff
,
1000
,
prefix
=
'numpy'
)
def
test_normal0
():
def
basictest
(
f
,
steps
,
target_avg
,
target_std
,
prefix
=
""
):
dt
=
0.0
avg_std
=
0.0
for
i
in
xrange
(
steps
):
t0
=
time
.
time
()
ival
=
f
()
dt
+=
time
.
time
()
-
t0
ival
=
numpy
.
asarray
(
ival
)
if
i
==
0
:
mean
=
numpy
.
array
(
ival
,
copy
=
True
)
avg_std
=
numpy
.
std
(
ival
)
else
:
alpha
=
1.0
/
(
1
+
i
)
mean
=
alpha
*
ival
+
(
1
-
alpha
)
*
mean
avg_std
=
alpha
*
numpy
.
std
(
ival
)
+
(
1
-
alpha
)
*
avg_std
print
prefix
,
'mean'
,
numpy
.
mean
(
mean
)
assert
abs
(
numpy
.
mean
(
mean
)
-
target_avg
)
<
.
01
,
'bad mean?'
print
prefix
,
'std'
,
avg_std
assert
abs
(
avg_std
-
target_std
)
<
.
01
,
'bad std?'
print
prefix
,
'time'
,
dt
print
prefix
,
'elements'
,
steps
*
sample_size
[
0
]
*
sample_size
[
1
]
print
prefix
,
'samples/sec'
,
steps
*
sample_size
[
0
]
*
sample_size
[
1
]
/
dt
sample_size
=
(
999
,
100
)
print
''
print
'ON CPU:'
R
=
MRG_RandomStreams
(
234
,
use_cuda
=
False
)
n
=
R
.
normal
(
size
=
sample_size
,
avg
=-
5.0
,
std
=
2.0
)
f
=
theano
.
function
([],
n
)
theano
.
printing
.
debugprint
(
f
)
print
'random?[:10]
\n
'
,
f
()[
0
,
0
:
10
]
basictest
(
f
,
50
,
-
5.0
,
2.0
,
prefix
=
'mrg '
)
sys
.
stdout
.
flush
()
# now with odd number of samples
sample_size
=
(
999
,
99
)
print
''
print
'ON GPU:'
R
=
MRG_RandomStreams
(
234
,
use_cuda
=
True
)
n
=
R
.
normal
(
size
=
sample_size
,
avg
=-
5.0
,
std
=
2.0
,
dtype
=
'float32'
)
assert
n
.
dtype
==
'float32'
#well, it's really that this test w GPU doesn't make sense otw
f
=
theano
.
function
([],
theano
.
Out
(
theano
.
sandbox
.
cuda
.
basic_ops
.
gpu_from_host
(
n
),
borrow
=
True
))
theano
.
printing
.
debugprint
(
f
)
sys
.
stdout
.
flush
()
print
'random?[:10]
\n
'
,
numpy
.
asarray
(
f
())[
0
,
0
:
10
]
print
'----'
sys
.
stdout
.
flush
()
basictest
(
f
,
50
,
-
5.0
,
2.0
,
prefix
=
'gpu mrg '
)
print
''
print
'ON CPU w NUMPY:'
RR
=
theano
.
tensor
.
shared_randomstreams
.
RandomStreams
(
234
)
nn
=
RR
.
normal
(
size
=
sample_size
,
avg
=-
5.0
,
std
=
2.0
)
ff
=
theano
.
function
([],
nn
)
basictest
(
ff
,
50
,
-
5.0
,
2.0
,
prefix
=
'numpy '
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论