Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e6576b19
提交
e6576b19
authored
1月 26, 2017
作者:
Benjamin Scellier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
file theano/gpuarray/tests/test_scan.py
上级
ea838a11
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
15 行增加
和
15 行删除
+15
-15
test_scan.py
theano/gpuarray/tests/test_scan.py
+15
-15
没有找到文件。
theano/gpuarray/tests/test_scan.py
浏览文件 @
e6576b19
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
from
unittest
import
TestCase
from
unittest
import
TestCase
import
numpy
import
numpy
as
np
from
six.moves
import
xrange
from
six.moves
import
xrange
import
theano
import
theano
...
@@ -43,19 +43,19 @@ class T_Scan(TestCase):
...
@@ -43,19 +43,19 @@ class T_Scan(TestCase):
allow_input_downcast
=
True
,
allow_input_downcast
=
True
,
mode
=
mode
)
mode
=
mode
)
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=-
5.
,
high
=
5.
)
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=-
5.
,
high
=
5.
)
v_x0
=
rng
.
uniform
()
v_x0
=
rng
.
uniform
()
W
=
rng
.
uniform
()
W
=
rng
.
uniform
()
W_in
=
rng
.
uniform
()
W_in
=
rng
.
uniform
()
v_u
=
n
umpy
.
asarray
(
v_u
,
dtype
=
'float32'
)
v_u
=
n
p
.
asarray
(
v_u
,
dtype
=
'float32'
)
v_x0
=
n
umpy
.
asarray
(
v_x0
,
dtype
=
'float32'
)
v_x0
=
n
p
.
asarray
(
v_x0
,
dtype
=
'float32'
)
W
=
n
umpy
.
asarray
(
W
,
dtype
=
'float32'
)
W
=
n
p
.
asarray
(
W
,
dtype
=
'float32'
)
W_in
=
n
umpy
.
asarray
(
W_in
,
dtype
=
'float32'
)
W_in
=
n
p
.
asarray
(
W_in
,
dtype
=
'float32'
)
# compute the output in numpy
# compute the output in numpy
v_out
=
n
umpy
.
zeros
((
4
,))
v_out
=
n
p
.
zeros
((
4
,))
v_out
[
0
]
=
v_u
[
0
]
*
W_in
+
v_x0
*
W
v_out
[
0
]
=
v_u
[
0
]
*
W_in
+
v_x0
*
W
for
step
in
xrange
(
1
,
4
):
for
step
in
xrange
(
1
,
4
):
v_out
[
step
]
=
v_u
[
step
]
*
W_in
+
v_out
[
step
-
1
]
*
W
v_out
[
step
]
=
v_u
[
step
]
*
W_in
+
v_out
[
step
-
1
]
*
W
...
@@ -115,14 +115,14 @@ class T_Scan(TestCase):
...
@@ -115,14 +115,14 @@ class T_Scan(TestCase):
mode
=
mode_with_gpu
)
mode
=
mode_with_gpu
)
# get random initial values
# get random initial values
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=-
5.
,
high
=
5.
)
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=-
5.
,
high
=
5.
)
v_x0
=
rng
.
uniform
()
v_x0
=
rng
.
uniform
()
W
=
rng
.
uniform
()
W
=
rng
.
uniform
()
W_in
=
rng
.
uniform
()
W_in
=
rng
.
uniform
()
# compute the output in numpy
# compute the output in numpy
v_out
=
n
umpy
.
zeros
((
4
,))
v_out
=
n
p
.
zeros
((
4
,))
v_out
[
0
]
=
v_u
[
0
]
*
W_in
+
v_x0
*
W
v_out
[
0
]
=
v_u
[
0
]
*
W_in
+
v_x0
*
W
for
step
in
xrange
(
1
,
4
):
for
step
in
xrange
(
1
,
4
):
v_out
[
step
]
=
v_u
[
step
]
*
W_in
+
v_out
[
step
-
1
]
*
W
v_out
[
step
]
=
v_u
[
step
]
*
W_in
+
v_out
[
step
-
1
]
*
W
...
@@ -177,20 +177,20 @@ class T_Scan(TestCase):
...
@@ -177,20 +177,20 @@ class T_Scan(TestCase):
mode
=
mode_with_gpu
)
mode
=
mode_with_gpu
)
# get random initial values
# get random initial values
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=-
5.
,
high
=
5.
)
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=-
5.
,
high
=
5.
)
v_x0
=
rng
.
uniform
()
v_x0
=
rng
.
uniform
()
W
=
rng
.
uniform
()
W
=
rng
.
uniform
()
W_in
=
rng
.
uniform
()
W_in
=
rng
.
uniform
()
# compute the output in numpy
# compute the output in numpy
v_out1
=
n
umpy
.
zeros
((
4
,))
v_out1
=
n
p
.
zeros
((
4
,))
v_out2
=
n
umpy
.
zeros
((
4
,),
dtype
=
'int64'
)
v_out2
=
n
p
.
zeros
((
4
,),
dtype
=
'int64'
)
v_out1
[
0
]
=
v_u
[
0
]
*
W_in
+
v_x0
*
W
v_out1
[
0
]
=
v_u
[
0
]
*
W_in
+
v_x0
*
W
v_out2
[
0
]
=
v_u
[
0
]
+
v_x0
v_out2
[
0
]
=
v_u
[
0
]
+
v_x0
for
step
in
xrange
(
1
,
4
):
for
step
in
xrange
(
1
,
4
):
v_out1
[
step
]
=
v_u
[
step
]
*
W_in
+
v_out1
[
step
-
1
]
*
W
v_out1
[
step
]
=
v_u
[
step
]
*
W_in
+
v_out1
[
step
-
1
]
*
W
v_out2
[
step
]
=
n
umpy
.
int64
(
v_u
[
step
]
+
v_out1
[
step
-
1
])
v_out2
[
step
]
=
n
p
.
int64
(
v_u
[
step
]
+
v_out1
[
step
-
1
])
theano_out1
,
theano_out2
=
f2
(
v_u
,
v_x0
,
W_in
,
W
)
theano_out1
,
theano_out2
=
f2
(
v_u
,
v_x0
,
W_in
,
W
)
utt
.
assert_allclose
(
theano_out1
,
v_out1
)
utt
.
assert_allclose
(
theano_out1
,
v_out1
)
...
@@ -212,8 +212,8 @@ class T_Scan(TestCase):
...
@@ -212,8 +212,8 @@ class T_Scan(TestCase):
for
node
in
scan_node_topo
])
for
node
in
scan_node_topo
])
def
test_gpu4_gibbs_chain
(
self
):
def
test_gpu4_gibbs_chain
(
self
):
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
v_vsample
=
n
umpy
.
array
(
rng
.
binomial
(
1
,
.
5
,
size
=
(
3
,
20
),),
v_vsample
=
n
p
.
array
(
rng
.
binomial
(
1
,
.
5
,
size
=
(
3
,
20
),),
dtype
=
'float32'
)
dtype
=
'float32'
)
vsample
=
theano
.
shared
(
v_vsample
)
vsample
=
theano
.
shared
(
v_vsample
)
trng
=
theano
.
sandbox
.
rng_mrg
.
MRG_RandomStreams
(
trng
=
theano
.
sandbox
.
rng_mrg
.
MRG_RandomStreams
(
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论