Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
30304bd8
提交
30304bd8
authored
1月 26, 2017
作者:
Benjamin Scellier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
file theano/gpuarray/tests/test_multinomial.py
上级
04cf9242
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
39 行增加
和
39 行删除
+39
-39
test_multinomial.py
theano/gpuarray/tests/test_multinomial.py
+39
-39
没有找到文件。
theano/gpuarray/tests/test_multinomial.py
浏览文件 @
30304bd8
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
import
unittest
import
unittest
...
@@ -62,10 +62,10 @@ def test_multinomial_large():
...
@@ -62,10 +62,10 @@ def test_multinomial_large():
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialFromUniform
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialFromUniform
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
pval
=
n
umpy
.
arange
(
10000
*
4
,
pval
=
n
p
.
arange
(
10000
*
4
,
dtype
=
'float32'
)
.
reshape
((
10000
,
4
))
+
0.1
dtype
=
'float32'
)
.
reshape
((
10000
,
4
))
+
0.1
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
uval
=
n
umpy
.
ones_like
(
pval
[:,
0
])
*
0.5
uval
=
n
p
.
ones_like
(
pval
[:,
0
])
*
0.5
mval
=
f
(
pval
,
uval
)
mval
=
f
(
pval
,
uval
)
assert
mval
.
shape
==
pval
.
shape
assert
mval
.
shape
==
pval
.
shape
...
@@ -78,7 +78,7 @@ def test_multinomial_large():
...
@@ -78,7 +78,7 @@ def test_multinomial_large():
else
:
else
:
raise
NotImplementedError
(
config
.
cast_policy
)
raise
NotImplementedError
(
config
.
cast_policy
)
utt
.
assert_allclose
(
mval
.
sum
(
axis
=
1
),
2
)
utt
.
assert_allclose
(
mval
.
sum
(
axis
=
1
),
2
)
asdf
=
n
umpy
.
asarray
([
0
,
0
,
2
,
0
])
+
0
*
pval
asdf
=
n
p
.
asarray
([
0
,
0
,
2
,
0
])
+
0
*
pval
utt
.
assert_allclose
(
mval
,
asdf
)
# broadcast over all rows
utt
.
assert_allclose
(
mval
,
asdf
)
# broadcast over all rows
...
@@ -92,9 +92,9 @@ def test_gpu_opt_dtypes():
...
@@ -92,9 +92,9 @@ def test_gpu_opt_dtypes():
f
=
function
([
p
,
u
],
m
,
allow_input_downcast
=
True
,
mode
=
mode_with_gpu
)
f
=
function
([
p
,
u
],
m
,
allow_input_downcast
=
True
,
mode
=
mode_with_gpu
)
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialFromUniform
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialFromUniform
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
pval
=
n
umpy
.
arange
(
10000
*
4
,
dtype
=
'float32'
)
.
reshape
((
10000
,
4
))
+
0.1
pval
=
n
p
.
arange
(
10000
*
4
,
dtype
=
'float32'
)
.
reshape
((
10000
,
4
))
+
0.1
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
uval
=
n
umpy
.
ones_like
(
pval
[:,
0
])
*
0.5
uval
=
n
p
.
ones_like
(
pval
[:,
0
])
*
0.5
samples
=
f
(
pval
,
uval
)
samples
=
f
(
pval
,
uval
)
assert
samples
.
dtype
==
dtype
,
"
%
s !=
%
s"
%
(
samples
.
dtype
,
dtype
)
assert
samples
.
dtype
==
dtype
,
"
%
s !=
%
s"
%
(
samples
.
dtype
,
dtype
)
...
@@ -112,9 +112,9 @@ def test_gpu_opt():
...
@@ -112,9 +112,9 @@ def test_gpu_opt():
f
=
function
([
p
,
u
],
m
,
allow_input_downcast
=
True
,
mode
=
mode_with_gpu
)
f
=
function
([
p
,
u
],
m
,
allow_input_downcast
=
True
,
mode
=
mode_with_gpu
)
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialFromUniform
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialFromUniform
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
pval
=
n
umpy
.
arange
(
10000
*
4
,
dtype
=
'float32'
)
.
reshape
((
10000
,
4
))
+
0.1
pval
=
n
p
.
arange
(
10000
*
4
,
dtype
=
'float32'
)
.
reshape
((
10000
,
4
))
+
0.1
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
uval
=
n
umpy
.
ones_like
(
pval
[:,
0
])
*
0.5
uval
=
n
p
.
ones_like
(
pval
[:,
0
])
*
0.5
f
(
pval
,
uval
)
f
(
pval
,
uval
)
# Test with a row, it was failing in the past.
# Test with a row, it was failing in the past.
...
@@ -125,9 +125,9 @@ def test_gpu_opt():
...
@@ -125,9 +125,9 @@ def test_gpu_opt():
f
=
function
([
r
,
u
],
m
,
allow_input_downcast
=
True
,
mode
=
mode_with_gpu
)
f
=
function
([
r
,
u
],
m
,
allow_input_downcast
=
True
,
mode
=
mode_with_gpu
)
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialFromUniform
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialFromUniform
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
pval
=
n
umpy
.
arange
(
1
*
4
,
dtype
=
'float32'
)
.
reshape
((
1
,
4
))
+
0.1
pval
=
n
p
.
arange
(
1
*
4
,
dtype
=
'float32'
)
.
reshape
((
1
,
4
))
+
0.1
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
uval
=
n
umpy
.
ones_like
(
pval
[:,
0
])
*
0.5
uval
=
n
p
.
ones_like
(
pval
[:,
0
])
*
0.5
f
(
pval
,
uval
)
f
(
pval
,
uval
)
...
@@ -146,15 +146,15 @@ class test_OP_wor(unittest.TestCase):
...
@@ -146,15 +146,15 @@ class test_OP_wor(unittest.TestCase):
n_elements
=
1000
n_elements
=
1000
all_indices
=
range
(
n_elements
)
all_indices
=
range
(
n_elements
)
n
umpy
.
random
.
seed
(
12345
)
n
p
.
random
.
seed
(
12345
)
for
i
in
[
5
,
10
,
50
,
100
,
500
,
n_elements
]:
for
i
in
[
5
,
10
,
50
,
100
,
500
,
n_elements
]:
uni
=
n
umpy
.
random
.
rand
(
i
)
.
astype
(
config
.
floatX
)
uni
=
n
p
.
random
.
rand
(
i
)
.
astype
(
config
.
floatX
)
pvals
=
n
umpy
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
=
n
p
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
/=
pvals
.
sum
(
1
)
pvals
/=
pvals
.
sum
(
1
)
res
=
f
(
pvals
,
uni
,
i
)
res
=
f
(
pvals
,
uni
,
i
)
res
=
n
umpy
.
squeeze
(
res
)
res
=
n
p
.
squeeze
(
res
)
assert
len
(
res
)
==
i
,
res
assert
len
(
res
)
==
i
,
res
assert
n
umpy
.
all
(
numpy
.
in1d
(
numpy
.
unique
(
res
),
all_indices
)),
res
assert
n
p
.
all
(
np
.
in1d
(
np
.
unique
(
res
),
all_indices
)),
res
def
test_fail_select_alot
(
self
):
def
test_fail_select_alot
(
self
):
"""
"""
...
@@ -170,9 +170,9 @@ class test_OP_wor(unittest.TestCase):
...
@@ -170,9 +170,9 @@ class test_OP_wor(unittest.TestCase):
n_elements
=
100
n_elements
=
100
n_selected
=
200
n_selected
=
200
n
umpy
.
random
.
seed
(
12345
)
n
p
.
random
.
seed
(
12345
)
uni
=
n
umpy
.
random
.
rand
(
n_selected
)
.
astype
(
config
.
floatX
)
uni
=
n
p
.
random
.
rand
(
n_selected
)
.
astype
(
config
.
floatX
)
pvals
=
n
umpy
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
=
n
p
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
/=
pvals
.
sum
(
1
)
pvals
/=
pvals
.
sum
(
1
)
self
.
assertRaises
(
ValueError
,
f
,
pvals
,
uni
,
n_selected
)
self
.
assertRaises
(
ValueError
,
f
,
pvals
,
uni
,
n_selected
)
...
@@ -191,18 +191,18 @@ class test_OP_wor(unittest.TestCase):
...
@@ -191,18 +191,18 @@ class test_OP_wor(unittest.TestCase):
n_elements
=
100
n_elements
=
100
n_selected
=
10
n_selected
=
10
mean_rtol
=
0.0005
mean_rtol
=
0.0005
n
umpy
.
random
.
seed
(
12345
)
n
p
.
random
.
seed
(
12345
)
pvals
=
n
umpy
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
=
n
p
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
/=
pvals
.
sum
(
1
)
pvals
/=
pvals
.
sum
(
1
)
avg_pvals
=
n
umpy
.
zeros
((
n_elements
,),
dtype
=
config
.
floatX
)
avg_pvals
=
n
p
.
zeros
((
n_elements
,),
dtype
=
config
.
floatX
)
for
rep
in
range
(
10000
):
for
rep
in
range
(
10000
):
uni
=
n
umpy
.
random
.
rand
(
n_selected
)
.
astype
(
config
.
floatX
)
uni
=
n
p
.
random
.
rand
(
n_selected
)
.
astype
(
config
.
floatX
)
res
=
f
(
pvals
,
uni
,
n_selected
)
res
=
f
(
pvals
,
uni
,
n_selected
)
res
=
n
umpy
.
squeeze
(
res
)
res
=
n
p
.
squeeze
(
res
)
avg_pvals
[
res
]
+=
1
avg_pvals
[
res
]
+=
1
avg_pvals
/=
avg_pvals
.
sum
()
avg_pvals
/=
avg_pvals
.
sum
()
avg_diff
=
n
umpy
.
mean
(
abs
(
avg_pvals
-
pvals
))
avg_diff
=
n
p
.
mean
(
abs
(
avg_pvals
-
pvals
))
assert
avg_diff
<
mean_rtol
,
avg_diff
assert
avg_diff
<
mean_rtol
,
avg_diff
...
@@ -222,14 +222,14 @@ class test_function_wor(unittest.TestCase):
...
@@ -222,14 +222,14 @@ class test_function_wor(unittest.TestCase):
n_elements
=
1000
n_elements
=
1000
all_indices
=
range
(
n_elements
)
all_indices
=
range
(
n_elements
)
n
umpy
.
random
.
seed
(
12345
)
n
p
.
random
.
seed
(
12345
)
for
i
in
[
5
,
10
,
50
,
100
,
500
,
n_elements
]:
for
i
in
[
5
,
10
,
50
,
100
,
500
,
n_elements
]:
pvals
=
n
umpy
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
=
n
p
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
/=
pvals
.
sum
(
1
)
pvals
/=
pvals
.
sum
(
1
)
res
=
f
(
pvals
,
i
)
res
=
f
(
pvals
,
i
)
res
=
n
umpy
.
squeeze
(
res
)
res
=
n
p
.
squeeze
(
res
)
assert
len
(
res
)
==
i
assert
len
(
res
)
==
i
assert
n
umpy
.
all
(
numpy
.
in1d
(
numpy
.
unique
(
res
),
all_indices
)),
res
assert
n
p
.
all
(
np
.
in1d
(
np
.
unique
(
res
),
all_indices
)),
res
def
test_fail_select_alot
(
self
):
def
test_fail_select_alot
(
self
):
"""
"""
...
@@ -246,8 +246,8 @@ class test_function_wor(unittest.TestCase):
...
@@ -246,8 +246,8 @@ class test_function_wor(unittest.TestCase):
n_elements
=
100
n_elements
=
100
n_selected
=
200
n_selected
=
200
n
umpy
.
random
.
seed
(
12345
)
n
p
.
random
.
seed
(
12345
)
pvals
=
n
umpy
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
=
n
p
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
/=
pvals
.
sum
(
1
)
pvals
/=
pvals
.
sum
(
1
)
self
.
assertRaises
(
ValueError
,
f
,
pvals
,
n_selected
)
self
.
assertRaises
(
ValueError
,
f
,
pvals
,
n_selected
)
...
@@ -267,17 +267,17 @@ class test_function_wor(unittest.TestCase):
...
@@ -267,17 +267,17 @@ class test_function_wor(unittest.TestCase):
n_elements
=
100
n_elements
=
100
n_selected
=
10
n_selected
=
10
mean_rtol
=
0.0005
mean_rtol
=
0.0005
n
umpy
.
random
.
seed
(
12345
)
n
p
.
random
.
seed
(
12345
)
pvals
=
n
umpy
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
=
n
p
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
/=
pvals
.
sum
(
1
)
pvals
/=
pvals
.
sum
(
1
)
avg_pvals
=
n
umpy
.
zeros
((
n_elements
,),
dtype
=
config
.
floatX
)
avg_pvals
=
n
p
.
zeros
((
n_elements
,),
dtype
=
config
.
floatX
)
for
rep
in
range
(
10000
):
for
rep
in
range
(
10000
):
res
=
f
(
pvals
,
n_selected
)
res
=
f
(
pvals
,
n_selected
)
res
=
n
umpy
.
squeeze
(
res
)
res
=
n
p
.
squeeze
(
res
)
avg_pvals
[
res
]
+=
1
avg_pvals
[
res
]
+=
1
avg_pvals
/=
avg_pvals
.
sum
()
avg_pvals
/=
avg_pvals
.
sum
()
avg_diff
=
n
umpy
.
mean
(
abs
(
avg_pvals
-
pvals
))
avg_diff
=
n
p
.
mean
(
abs
(
avg_pvals
-
pvals
))
assert
avg_diff
<
mean_rtol
assert
avg_diff
<
mean_rtol
...
@@ -294,9 +294,9 @@ def test_gpu_opt_wor():
...
@@ -294,9 +294,9 @@ def test_gpu_opt_wor():
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialWOReplacementFromUniform
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialWOReplacementFromUniform
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
n_samples
=
3
n_samples
=
3
pval
=
n
umpy
.
arange
(
10000
*
4
,
dtype
=
'float32'
)
.
reshape
((
10000
,
4
))
+
0.1
pval
=
n
p
.
arange
(
10000
*
4
,
dtype
=
'float32'
)
.
reshape
((
10000
,
4
))
+
0.1
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
uval
=
n
umpy
.
ones
(
pval
.
shape
[
0
]
*
n_samples
)
*
0.5
uval
=
n
p
.
ones
(
pval
.
shape
[
0
]
*
n_samples
)
*
0.5
f
(
pval
,
uval
,
n_samples
)
f
(
pval
,
uval
,
n_samples
)
# Test with a row, it was failing in the past.
# Test with a row, it was failing in the past.
...
@@ -307,7 +307,7 @@ def test_gpu_opt_wor():
...
@@ -307,7 +307,7 @@ def test_gpu_opt_wor():
f
=
function
([
r
,
u
,
n
],
m
,
allow_input_downcast
=
True
,
mode
=
mode_with_gpu
)
f
=
function
([
r
,
u
,
n
],
m
,
allow_input_downcast
=
True
,
mode
=
mode_with_gpu
)
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialWOReplacementFromUniform
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialWOReplacementFromUniform
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
pval
=
n
umpy
.
arange
(
1
*
4
,
dtype
=
'float32'
)
.
reshape
((
1
,
4
))
+
0.1
pval
=
n
p
.
arange
(
1
*
4
,
dtype
=
'float32'
)
.
reshape
((
1
,
4
))
+
0.1
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
uval
=
n
umpy
.
ones_like
(
pval
[:,
0
])
*
0.5
uval
=
n
p
.
ones_like
(
pval
[:,
0
])
*
0.5
f
(
pval
,
uval
,
1
)
f
(
pval
,
uval
,
1
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论