Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5548fee1
提交
5548fee1
authored
7月 19, 2011
作者:
Razvan Pascanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
removed tests for things that are going to get depricated; added name to
variables and some other cosmetic changes.
上级
97bd98fd
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
19 行增加
和
78 行删除
+19
-78
test_scan.py
theano/scan_module/tests/test_scan.py
+19
-78
没有找到文件。
theano/scan_module/tests/test_scan.py
浏览文件 @
5548fee1
...
@@ -383,9 +383,6 @@ class T_Scan(unittest.TestCase):
...
@@ -383,9 +383,6 @@ class T_Scan(unittest.TestCase):
assert
len
(
scan_node
)
==
1
assert
len
(
scan_node
)
==
1
scan_node
=
scan_node
[
0
]
scan_node
=
scan_node
[
0
]
scan_node_topo
=
scan_node
.
op
.
fn
.
maker
.
env
.
toposort
()
scan_node_topo
=
scan_node
.
op
.
fn
.
maker
.
env
.
toposort
()
#theano.printing.pydotprint(f2, outfile='out2.png', high_contrast=True)
#theano.printing.pydotprint(scan_node.op.fn,
# outfile='inner2.png', high_contrast=True)
# check that there is no gpu transfer in the inner loop.
# check that there is no gpu transfer in the inner loop.
assert
any
([
isinstance
(
node
.
op
,
theano
.
sandbox
.
cuda
.
GpuElemwise
)
for
node
in
scan_node_topo
])
assert
any
([
isinstance
(
node
.
op
,
theano
.
sandbox
.
cuda
.
GpuElemwise
)
for
node
in
scan_node_topo
])
...
@@ -1437,8 +1434,8 @@ class T_Scan(unittest.TestCase):
...
@@ -1437,8 +1434,8 @@ class T_Scan(unittest.TestCase):
assert
numpy
.
allclose
(
f
([
2
,
3
])
,
5
)
assert
numpy
.
allclose
(
f
([
2
,
3
])
,
5
)
def
test_computing_gradient
(
self
):
def
test_computing_gradient
(
self
):
x1
=
theano
.
tensor
.
scalar
()
x1
=
theano
.
tensor
.
scalar
(
'x1'
)
x2
=
theano
.
shared
(
numpy
.
array
([
1
,
2
,
3
,
4
,
5
]))
x2
=
theano
.
shared
(
numpy
.
array
([
1
,
2
,
3
,
4
,
5
])
,
name
=
'x2'
)
K
=
x2
*
x1
K
=
x2
*
x1
out
,
updates
=
theano
.
scan
(
lambda
i
,
v
:
theano
.
tensor
.
grad
(
K
[
i
],
v
),
out
,
updates
=
theano
.
scan
(
lambda
i
,
v
:
theano
.
tensor
.
grad
(
K
[
i
],
v
),
...
@@ -1494,6 +1491,9 @@ class T_Scan(unittest.TestCase):
...
@@ -1494,6 +1491,9 @@ class T_Scan(unittest.TestCase):
iteration.
iteration.
This unit test addresses the bug fix of changeset ba7157e95cb1.
This unit test addresses the bug fix of changeset ba7157e95cb1.
!!! test lost some of its meaning because return_steps has been
depricated !!!
"""
"""
a
=
theano
.
tensor
.
vector
()
a
=
theano
.
tensor
.
vector
()
init_a
=
theano
.
tensor
.
vector
()
init_a
=
theano
.
tensor
.
vector
()
...
@@ -1503,8 +1503,9 @@ class T_Scan(unittest.TestCase):
...
@@ -1503,8 +1503,9 @@ class T_Scan(unittest.TestCase):
return
a
+
1
,
{
b
:
2
*
b
}
return
a
+
1
,
{
b
:
2
*
b
}
out
,
updates
=
theano
.
scan
(
inner_func
,
out
,
updates
=
theano
.
scan
(
inner_func
,
outputs_info
=
[{
'initial'
:
init_a
,
'return_steps'
:
1
}],
outputs_info
=
[{
'initial'
:
init_a
}],
n_steps
=
1
)
n_steps
=
1
)
out
=
out
[
-
1
]
assert
out
.
type
.
ndim
==
a
.
type
.
ndim
assert
out
.
type
.
ndim
==
a
.
type
.
ndim
assert
updates
[
b
]
.
type
.
ndim
==
b
.
type
.
ndim
assert
updates
[
b
]
.
type
.
ndim
==
b
.
type
.
ndim
...
@@ -1717,69 +1718,6 @@ class T_Scan(unittest.TestCase):
...
@@ -1717,69 +1718,6 @@ class T_Scan(unittest.TestCase):
assert
numpy
.
allclose
(
theano_y
,
v_y
)
assert
numpy
.
allclose
(
theano_y
,
v_y
)
### TEST store steps / return steps
def
test_return_steps
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
vW_in2
=
asarrayX
(
rng
.
uniform
(
size
=
(
2
,),
low
=
-
5.
,
high
=
5.
))
vW
=
asarrayX
(
rng
.
uniform
(
size
=
(
2
,
2
),
low
=
-
5.
,
high
=
5.
))
vWout
=
asarrayX
(
rng
.
uniform
(
size
=
(
2
,),
low
=
-
5.
,
high
=
5.
))
vW_in1
=
asarrayX
(
rng
.
uniform
(
size
=
(
2
,
2
),
low
=
-
5.
,
high
=
5.
))
v_u1
=
asarrayX
(
rng
.
uniform
(
size
=
(
8
,
2
),
low
=
-
5.
,
high
=
5.
))
v_u2
=
asarrayX
(
rng
.
uniform
(
size
=
(
8
,),
low
=
-
5.
,
high
=
5.
))
v_x0
=
asarrayX
(
rng
.
uniform
(
size
=
(
2
,),
low
=
-
5.
,
high
=
5.
))
v_y0
=
asarrayX
(
rng
.
uniform
(
size
=
(
3
,)))
W_in2
=
theano
.
shared
(
vW_in2
,
name
=
'win2'
)
W
=
theano
.
shared
(
vW
,
name
=
'w'
)
W_out
=
theano
.
shared
(
vWout
,
name
=
'wout'
)
W_in1
=
theano
.
tensor
.
matrix
(
'win'
)
u1
=
theano
.
tensor
.
matrix
(
'u1'
)
u2
=
theano
.
tensor
.
vector
(
'u2'
)
x0
=
theano
.
tensor
.
vector
(
'x0'
)
y0
=
theano
.
tensor
.
vector
(
'y0'
)
def
f_rnn_cmpl
(
u1_t
,
u2_t
,
x_tm1
,
y_tm1
,
y_tm3
,
W_in1
):
return
[
y_tm3
+
1
,
theano
.
dot
(
u1_t
,
W_in1
)
+
u2_t
*
W_in2
+
\
theano
.
dot
(
x_tm1
,
W
),
y_tm1
+
theano
.
dot
(
x_tm1
,
W_out
)]
outputs
,
updates
=
theano
.
scan
(
f_rnn_cmpl
,
[
u1
,
u2
]
,
[
dict
(
store_steps
=
3
)
,
dict
(
initial
=
x0
,
return_steps
=
2
)
,
dict
(
initial
=
y0
,
taps
=
[
-
1
,
-
3
],
return_steps
=
4
)]
,
W_in1
,
n_steps
=
None
,
truncate_gradient
=
-
1
,
go_backwards
=
False
)
f4
=
theano
.
function
([
u1
,
u2
,
x0
,
y0
,
W_in1
],
outputs
,
updates
=
updates
,
allow_input_downcast
=
True
)
# compute the values in numpy
v_x
=
numpy
.
zeros
((
8
,
2
),
dtype
=
theano
.
config
.
floatX
)
v_y
=
numpy
.
zeros
((
8
,),
dtype
=
theano
.
config
.
floatX
)
v_x
[
0
]
=
numpy
.
dot
(
v_u1
[
0
],
vW_in1
)
+
v_u2
[
0
]
*
vW_in2
+
\
numpy
.
dot
(
v_x0
,
vW
)
v_y
[
0
]
=
numpy
.
dot
(
v_x0
,
vWout
)
+
v_y0
[
2
]
for
i
in
xrange
(
1
,
8
):
v_x
[
i
]
=
numpy
.
dot
(
v_u1
[
i
],
vW_in1
)
+
v_u2
[
i
]
*
vW_in2
+
\
numpy
.
dot
(
v_x
[
i
-
1
],
vW
)
v_y
[
i
]
=
numpy
.
dot
(
v_x
[
i
-
1
],
vWout
)
+
v_y
[
i
-
1
]
(
theano_dump
,
theano_x
,
theano_y
)
=
f4
(
v_u1
,
v_u2
,
v_x0
,
v_y0
,
vW_in1
)
assert
numpy
.
allclose
(
theano_x
,
v_x
[
-
2
:])
assert
numpy
.
allclose
(
theano_y
,
v_y
[
-
4
:])
def
test_scan_as_tensor_on_gradients
(
self
):
def
test_scan_as_tensor_on_gradients
(
self
):
...
@@ -1832,19 +1770,20 @@ class T_Scan(unittest.TestCase):
...
@@ -1832,19 +1770,20 @@ class T_Scan(unittest.TestCase):
theano
.
dot
(
x_tm1
,
W
),
theano
.
dot
(
x_tm1
,
W
),
y_tm1
+
theano
.
dot
(
x_tm1
,
W_out
)]
y_tm1
+
theano
.
dot
(
x_tm1
,
W_out
)]
outputs
,
updates
=
theano
.
scan
(
f_rnn_cmpl
_
outputs
,
updates
=
theano
.
scan
(
f_rnn_cmpl
,
[
u1
,
[
u1
,
u2
]
,
u2
]
,
[
dict
(
return_steps
=
1
)
,
[
None
,
dict
(
initial
=
x0
,
dict
(
initial
=
x0
)
,
return_steps
=
1
)
,
dict
(
initial
=
y0
,
taps
=
[
-
1
,
-
3
])]
,
dict
(
initial
=
y0
,
taps
=
[
-
1
,
-
3
],
return_steps
=
1
)]
,
W_in1
,
W_in1
,
n_steps
=
None
,
n_steps
=
None
,
truncate_gradient
=
-
1
,
truncate_gradient
=
-
1
,
go_backwards
=
False
)
,
go_backwards
=
False
)
outputs
=
[
\
_outputs
[
0
][
-
1
],
_outputs
[
1
][
-
1
],
_outputs
[
2
][
-
1
]
]
f4
=
theano
.
function
([
u1
,
u2
,
x0
,
y0
,
W_in1
],
outputs
f4
=
theano
.
function
([
u1
,
u2
,
x0
,
y0
,
W_in1
],
outputs
,
updates
=
updates
,
updates
=
updates
,
allow_input_downcast
=
True
,
allow_input_downcast
=
True
...
@@ -1989,7 +1928,7 @@ class T_Scan(unittest.TestCase):
...
@@ -1989,7 +1928,7 @@ class T_Scan(unittest.TestCase):
# The following test will fail in DebugMode if there are
# The following test will fail in DebugMode if there are
# some problems in Scan.infer_shape
# some problems in Scan.infer_shape
def
test_remove_stuff
(
self
):
def
test_remove_stuff
(
self
):
x
=
theano
.
tensor
.
vector
()
x
=
theano
.
tensor
.
vector
(
'x'
)
def
lm
(
m
):
def
lm
(
m
):
trng
=
theano
.
tensor
.
shared_randomstreams
.
RandomStreams
(
trng
=
theano
.
tensor
.
shared_randomstreams
.
RandomStreams
(
...
@@ -2002,6 +1941,7 @@ class T_Scan(unittest.TestCase):
...
@@ -2002,6 +1941,7 @@ class T_Scan(unittest.TestCase):
sequences
=
x
,
sequences
=
x
,
n_steps
=
None
,
n_steps
=
None
,
truncate_gradient
=
-
1
,
truncate_gradient
=
-
1
,
name
=
'forward'
,
go_backwards
=
False
)
go_backwards
=
False
)
go1
=
theano
.
tensor
.
grad
(
o1
.
mean
(),
wrt
=
x
)
go1
=
theano
.
tensor
.
grad
(
o1
.
mean
(),
wrt
=
x
)
f
=
theano
.
function
([
x
],
go1
,
updates
=
updates
,
f
=
theano
.
function
([
x
],
go1
,
updates
=
updates
,
...
@@ -2010,9 +1950,10 @@ class T_Scan(unittest.TestCase):
...
@@ -2010,9 +1950,10 @@ class T_Scan(unittest.TestCase):
#theano.printing.debugprint(f, print_type=True)
#theano.printing.debugprint(f, print_type=True)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
# this new assert is here to test if scan_merging works ..
nb_scan
=
len
([
n
for
n
in
topo
nb_scan
=
len
([
n
for
n
in
topo
if
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)])
if
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)])
self
.
assertTrue
(
nb_scan
==
2
)
self
.
assertTrue
(
nb_scan
==
1
)
nb_shape_i
=
len
([
n
for
n
in
topo
nb_shape_i
=
len
([
n
for
n
in
topo
if
isinstance
(
n
.
op
,
theano
.
tensor
.
opt
.
Shape_i
)])
if
isinstance
(
n
.
op
,
theano
.
tensor
.
opt
.
Shape_i
)])
if
theano
.
config
.
mode
!=
'FAST_COMPILE'
:
if
theano
.
config
.
mode
!=
'FAST_COMPILE'
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论