Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9136e783
提交
9136e783
authored
11月 14, 2013
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests for scalar outputs (size=())
上级
000307f1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
49 行增加
和
19 行删除
+49
-19
test_rng_mrg.py
theano/sandbox/test_rng_mrg.py
+49
-19
没有找到文件。
theano/sandbox/test_rng_mrg.py
浏览文件 @
9136e783
...
@@ -369,11 +369,14 @@ def test_uniform():
...
@@ -369,11 +369,14 @@ def test_uniform():
steps
=
int
(
1e3
)
steps
=
int
(
1e3
)
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
for
size
,
var_input
,
input
in
[
for
size
,
const_size
,
var_input
,
input
in
[
(
sample_size
,
[],
[]),
(
sample_size
,
sample_size
,
[],
[]),
(
x
.
shape
,
[
x
],
[
numpy
.
zeros
(
sample_size
,
dtype
=
config
.
floatX
)]),
(
x
.
shape
,
sample_size
,
[
x
],
((
x
.
shape
[
0
],
sample_size
[
1
]),
[
x
],
[
numpy
.
zeros
(
sample_size
,
dtype
=
config
.
floatX
)]),
[
numpy
.
zeros
(
sample_size
,
dtype
=
config
.
floatX
)])
((
x
.
shape
[
0
],
sample_size
[
1
]),
sample_size
,
[
x
],
[
numpy
.
zeros
(
sample_size
,
dtype
=
config
.
floatX
)]),
# test empty size (scalar)
((),
(),
[],
[]),
]:
]:
#### TEST CPU IMPLEMENTATION ####
#### TEST CPU IMPLEMENTATION ####
...
@@ -397,7 +400,13 @@ def test_uniform():
...
@@ -397,7 +400,13 @@ def test_uniform():
#print 'CPU: random?[:10], random?[-10:]'
#print 'CPU: random?[:10], random?[-10:]'
#print cpu_out[0, 0:10]
#print cpu_out[0, 0:10]
#print cpu_out[-1, -10:]
#print cpu_out[-1, -10:]
basictest
(
f
,
steps
,
sample_size
,
prefix
=
'mrg cpu'
,
inputs
=
input
)
# Increase the number of steps if sizes implies only a few samples
if
numpy
.
prod
(
const_size
)
<
10
:
steps_
=
steps
*
100
else
:
steps_
=
steps
basictest
(
f
,
steps_
,
const_size
,
prefix
=
'mrg cpu'
,
inputs
=
input
)
if
mode
!=
'FAST_COMPILE'
and
cuda_available
:
if
mode
!=
'FAST_COMPILE'
and
cuda_available
:
#print ''
#print ''
...
@@ -419,7 +428,7 @@ def test_uniform():
...
@@ -419,7 +428,7 @@ def test_uniform():
#print 'GPU: random?[:10], random?[-10:]'
#print 'GPU: random?[:10], random?[-10:]'
#print gpu_out[0, 0:10]
#print gpu_out[0, 0:10]
#print gpu_out[-1, -10:]
#print gpu_out[-1, -10:]
basictest
(
f
,
steps
,
sample
_size
,
prefix
=
'mrg gpu'
,
inputs
=
input
)
basictest
(
f
,
steps
_
,
const
_size
,
prefix
=
'mrg gpu'
,
inputs
=
input
)
numpy
.
testing
.
assert_array_almost_equal
(
cpu_out
,
gpu_out
,
numpy
.
testing
.
assert_array_almost_equal
(
cpu_out
,
gpu_out
,
decimal
=
6
)
decimal
=
6
)
...
@@ -431,7 +440,7 @@ def test_uniform():
...
@@ -431,7 +440,7 @@ def test_uniform():
uu
=
RR
.
uniform
(
size
=
size
)
uu
=
RR
.
uniform
(
size
=
size
)
ff
=
theano
.
function
(
var_input
,
uu
,
mode
=
mode
)
ff
=
theano
.
function
(
var_input
,
uu
,
mode
=
mode
)
# It's not our problem if numpy generates 0 or 1
# It's not our problem if numpy generates 0 or 1
basictest
(
ff
,
steps
,
sample
_size
,
prefix
=
'numpy'
,
basictest
(
ff
,
steps
_
,
const
_size
,
prefix
=
'numpy'
,
allow_01
=
True
,
inputs
=
input
)
allow_01
=
True
,
inputs
=
input
)
...
@@ -457,11 +466,14 @@ def test_binomial():
...
@@ -457,11 +466,14 @@ def test_binomial():
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
v
=
tensor
.
vector
()
v
=
tensor
.
vector
()
for
mean
in
[
0.1
,
0.5
]:
for
mean
in
[
0.1
,
0.5
]:
for
size
,
var_input
,
input
in
[
for
size
,
const_size
,
var_input
,
input
in
[
(
sample_size
,
[],
[]),
(
sample_size
,
sample_size
,
[],
[]),
(
x
.
shape
,
[
x
],
[
numpy
.
zeros
(
sample_size
,
dtype
=
config
.
floatX
)]),
(
x
.
shape
,
sample_size
,
[
x
],
((
x
.
shape
[
0
],
sample_size
[
1
]),
[
x
],
[
numpy
.
zeros
(
sample_size
,
dtype
=
config
.
floatX
)]),
[
numpy
.
zeros
(
sample_size
,
dtype
=
config
.
floatX
)])
((
x
.
shape
[
0
],
sample_size
[
1
]),
sample_size
,
[
x
],
[
numpy
.
zeros
(
sample_size
,
dtype
=
config
.
floatX
)]),
# test empty size (scalar)
((),
(),
[],
[]),
]:
]:
#print ''
#print ''
...
@@ -475,7 +487,13 @@ def test_binomial():
...
@@ -475,7 +487,13 @@ def test_binomial():
out
=
f
(
*
input
)
out
=
f
(
*
input
)
#print 'random?[:10]\n', out[0, 0:10]
#print 'random?[:10]\n', out[0, 0:10]
#print 'random?[-1,-10:]\n', out[-1, -10:]
#print 'random?[-1,-10:]\n', out[-1, -10:]
basictest
(
f
,
steps
,
sample_size
,
prefix
=
'mrg cpu'
,
# Increase the number of steps if sizes implies only a few samples
if
numpy
.
prod
(
const_size
)
<
10
:
steps_
=
steps
*
100
else
:
steps_
=
steps
basictest
(
f
,
steps_
,
const_size
,
prefix
=
'mrg cpu'
,
inputs
=
input
,
allow_01
=
True
,
inputs
=
input
,
allow_01
=
True
,
target_avg
=
mean
,
mean_rtol
=
rtol
)
target_avg
=
mean
,
mean_rtol
=
rtol
)
...
@@ -495,7 +513,7 @@ def test_binomial():
...
@@ -495,7 +513,7 @@ def test_binomial():
gpu_out
=
numpy
.
asarray
(
f
(
*
input
))
gpu_out
=
numpy
.
asarray
(
f
(
*
input
))
#print 'random?[:10]\n', gpu_out[0, 0:10]
#print 'random?[:10]\n', gpu_out[0, 0:10]
#print 'random?[-1,-10:]\n', gpu_out[-1, -10:]
#print 'random?[-1,-10:]\n', gpu_out[-1, -10:]
basictest
(
f
,
steps
,
sample
_size
,
prefix
=
'mrg gpu'
,
basictest
(
f
,
steps
_
,
const
_size
,
prefix
=
'mrg gpu'
,
inputs
=
input
,
allow_01
=
True
,
inputs
=
input
,
allow_01
=
True
,
target_avg
=
mean
,
mean_rtol
=
rtol
)
target_avg
=
mean
,
mean_rtol
=
rtol
)
numpy
.
testing
.
assert_array_almost_equal
(
out
,
gpu_out
,
numpy
.
testing
.
assert_array_almost_equal
(
out
,
gpu_out
,
...
@@ -509,7 +527,7 @@ def test_binomial():
...
@@ -509,7 +527,7 @@ def test_binomial():
uu
=
RR
.
binomial
(
size
=
size
,
p
=
mean
)
uu
=
RR
.
binomial
(
size
=
size
,
p
=
mean
)
ff
=
theano
.
function
(
var_input
,
uu
,
mode
=
mode
)
ff
=
theano
.
function
(
var_input
,
uu
,
mode
=
mode
)
# It's not our problem if numpy generates 0 or 1
# It's not our problem if numpy generates 0 or 1
basictest
(
ff
,
steps
,
sample
_size
,
prefix
=
'numpy'
,
allow_01
=
True
,
basictest
(
ff
,
steps
_
,
const
_size
,
prefix
=
'numpy'
,
allow_01
=
True
,
inputs
=
input
,
target_avg
=
mean
,
mean_rtol
=
rtol
)
inputs
=
input
,
target_avg
=
mean
,
mean_rtol
=
rtol
)
...
@@ -544,6 +562,12 @@ def test_normal0():
...
@@ -544,6 +562,12 @@ def test_normal0():
numpy
.
arange
(
numpy
.
prod
(
sample_size
),
numpy
.
arange
(
numpy
.
prod
(
sample_size
),
dtype
=
'float32'
)
.
reshape
(
sample_size
),
dtype
=
'float32'
)
.
reshape
(
sample_size
),
10.
*
std
/
numpy
.
sqrt
(
steps
)),
10.
*
std
/
numpy
.
sqrt
(
steps
)),
# test empty size (scalar)
((),
(),
[],
[],
-
5.
,
default_rtol
),
# test with few samples at the same time
((
1
,),
(
1
,),
[],
[],
-
5.
,
default_rtol
),
((
2
,),
(
2
,),
[],
[],
-
5.
,
default_rtol
),
((
3
,),
(
3
,),
[],
[],
-
5.
,
default_rtol
),
]:
]:
#print ''
#print ''
#print 'ON CPU:'
#print 'ON CPU:'
...
@@ -556,7 +580,13 @@ def test_normal0():
...
@@ -556,7 +580,13 @@ def test_normal0():
#theano.printing.debugprint(f)
#theano.printing.debugprint(f)
out
=
f
(
*
input
)
out
=
f
(
*
input
)
#print 'random?[:10]\n', out[0, 0:10]
#print 'random?[:10]\n', out[0, 0:10]
basictest
(
f
,
steps
,
const_size
,
target_avg
=
avg
,
target_std
=
std
,
# Increase the number of steps if size implies only a few samples
if
numpy
.
prod
(
const_size
)
<
10
:
steps_
=
steps
*
numpy
.
prod
(
sample_size
,
dtype
=
int
)
/
10
else
:
steps_
=
steps
basictest
(
f
,
steps_
,
const_size
,
target_avg
=
avg
,
target_std
=
std
,
prefix
=
'mrg '
,
allow_01
=
True
,
inputs
=
input
,
mean_rtol
=
rtol
)
prefix
=
'mrg '
,
allow_01
=
True
,
inputs
=
input
,
mean_rtol
=
rtol
)
sys
.
stdout
.
flush
()
sys
.
stdout
.
flush
()
...
@@ -579,7 +609,7 @@ def test_normal0():
...
@@ -579,7 +609,7 @@ def test_normal0():
#print 'random?[:10]\n', gpu_out[0, 0:10]
#print 'random?[:10]\n', gpu_out[0, 0:10]
#print '----'
#print '----'
sys
.
stdout
.
flush
()
sys
.
stdout
.
flush
()
basictest
(
f
,
steps
,
const_size
,
target_avg
=
avg
,
target_std
=
std
,
basictest
(
f
,
steps
_
,
const_size
,
target_avg
=
avg
,
target_std
=
std
,
prefix
=
'gpu mrg '
,
allow_01
=
True
,
inputs
=
input
,
prefix
=
'gpu mrg '
,
allow_01
=
True
,
inputs
=
input
,
mean_rtol
=
rtol
)
mean_rtol
=
rtol
)
# Need to allow some rounding error as their is float
# Need to allow some rounding error as their is float
...
@@ -593,7 +623,7 @@ def test_normal0():
...
@@ -593,7 +623,7 @@ def test_normal0():
nn
=
RR
.
normal
(
size
=
size
,
avg
=
avg
,
std
=
std
)
nn
=
RR
.
normal
(
size
=
size
,
avg
=
avg
,
std
=
std
)
ff
=
theano
.
function
(
var_input
,
nn
)
ff
=
theano
.
function
(
var_input
,
nn
)
basictest
(
ff
,
steps
,
const_size
,
target_avg
=
avg
,
target_std
=
std
,
basictest
(
ff
,
steps
_
,
const_size
,
target_avg
=
avg
,
target_std
=
std
,
prefix
=
'numpy '
,
allow_01
=
True
,
inputs
=
input
,
mean_rtol
=
rtol
)
prefix
=
'numpy '
,
allow_01
=
True
,
inputs
=
input
,
mean_rtol
=
rtol
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论