Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
97bd98fd
提交
97bd98fd
authored
7月 19, 2011
作者:
Razvan Pascanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new tests to scan
上级
80cb32e6
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
269 行增加
和
0 行删除
+269
-0
test_scan.py
theano/scan_module/tests/test_scan.py
+269
-0
没有找到文件。
theano/scan_module/tests/test_scan.py
浏览文件 @
97bd98fd
...
...
@@ -2025,6 +2025,59 @@ class T_Scan(unittest.TestCase):
m2
=
theano
.
tensor
.
matrix
()
conv
=
theano
.
tensor
.
signal
.
conv
.
conv2d
(
m1
,
m2
)
def
test_merge
(
self
):
x
=
theano
.
tensor
.
vector
()
y
=
theano
.
tensor
.
vector
()
def
sum
(
s
):
return
s
+
1
sx
,
upx
=
theano
.
scan
(
sum
,
sequences
=
[
x
])
sy
,
upy
=
theano
.
scan
(
sum
,
sequences
=
[
y
])
f
=
theano
.
function
([
x
,
y
],
[
sx
,
sy
])
topo
=
f
.
maker
.
env
.
toposort
()
scans
=
filter
(
lambda
n
:
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
),
topo
)
self
.
assertTrue
(
len
(
scans
)
==
2
)
sx
,
upx
=
theano
.
scan
(
sum
,
sequences
=
[
x
],
n_steps
=
2
)
sy
,
upy
=
theano
.
scan
(
sum
,
sequences
=
[
y
],
n_steps
=
3
)
f
=
theano
.
function
([
x
,
y
],
[
sx
,
sy
])
topo
=
f
.
maker
.
env
.
toposort
()
scans
=
filter
(
lambda
n
:
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
),
topo
)
self
.
assertTrue
(
len
(
scans
)
==
2
)
sx
,
upx
=
theano
.
scan
(
sum
,
sequences
=
[
x
],
n_steps
=
4
)
sy
,
upy
=
theano
.
scan
(
sum
,
sequences
=
[
y
],
n_steps
=
4
)
f
=
theano
.
function
([
x
,
y
],
[
sx
,
sy
])
topo
=
f
.
maker
.
env
.
toposort
()
scans
=
filter
(
lambda
n
:
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
),
topo
)
self
.
assertTrue
(
len
(
scans
)
==
1
)
sx
,
upx
=
theano
.
scan
(
sum
,
sequences
=
[
x
])
sy
,
upy
=
theano
.
scan
(
sum
,
sequences
=
[
x
])
f
=
theano
.
function
([
x
,
y
],
[
sx
,
sy
])
topo
=
f
.
maker
.
env
.
toposort
()
scans
=
filter
(
lambda
n
:
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
),
topo
)
self
.
assertTrue
(
len
(
scans
)
==
1
)
sx
,
upx
=
theano
.
scan
(
sum
,
sequences
=
[
x
])
sy
,
upy
=
theano
.
scan
(
sum
,
sequences
=
[
x
],
mode
=
'FAST_COMPILE'
)
f
=
theano
.
function
([
x
,
y
],
[
sx
,
sy
])
topo
=
f
.
maker
.
env
.
toposort
()
scans
=
filter
(
lambda
n
:
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
),
topo
)
self
.
assertTrue
(
len
(
scans
)
==
2
)
sx
,
upx
=
theano
.
scan
(
sum
,
sequences
=
[
x
])
sy
,
upy
=
theano
.
scan
(
sum
,
sequences
=
[
x
],
truncate_gradient
=
1
)
f
=
theano
.
function
([
x
,
y
],
[
sx
,
sy
])
topo
=
f
.
maker
.
env
.
toposort
()
scans
=
filter
(
lambda
n
:
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
),
topo
)
self
.
assertTrue
(
len
(
scans
)
==
2
)
def
test_hash
(
self
):
x
=
theano
.
tensor
.
vector
()
...
...
@@ -2130,6 +2183,222 @@ class T_Scan(unittest.TestCase):
f2
=
theano
.
function
([],
gx
)
assert
numpy
.
allclose
(
f2
(),
numpy
.
ones
((
10
,)))
def
test_rop
(
self
):
seed
=
utt
.
fetch_seed
()
rng
=
numpy
.
random
.
RandomState
(
seed
)
floatX
=
theano
.
config
.
floatX
v_u
=
numpy
.
array
(
rng
.
uniform
(
size
=
(
20
,
5
)),
dtype
=
floatX
)
v_W
=
numpy
.
array
(
rng
.
uniform
(
size
=
(
5
,
5
)),
dtype
=
floatX
)
v_h0
=
numpy
.
array
(
rng
.
uniform
(
size
=
(
5
,)),
dtype
=
floatX
)
v_eu
=
numpy
.
array
(
rng
.
uniform
(
size
=
(
20
,
5
)),
dtype
=
floatX
)
v_eW
=
numpy
.
array
(
rng
.
uniform
(
size
=
(
5
,
5
)),
dtype
=
floatX
)
v_eh0
=
numpy
.
array
(
rng
.
uniform
(
size
=
(
5
,)),
dtype
=
floatX
)
def
rnn_fn
(
_u
,
_y
,
_W
):
sl_o
=
theano
.
tensor
.
tanh
(
theano
.
tensor
.
dot
(
_W
,
(
_u
+
_y
)))
return
sl_o
u
=
theano
.
tensor
.
matrix
(
'U'
)
h0
=
theano
.
tensor
.
vector
(
'h0'
)
W
=
theano
.
tensor
.
matrix
(
'W'
)
_u
=
theano
.
tensor
.
specify_shape
(
u
,
v_u
.
shape
)
_u
.
name
=
'_U'
_h0
=
theano
.
tensor
.
specify_shape
(
h0
,
v_h0
.
shape
)
_h0
.
name
=
'_h0'
_W
=
theano
.
tensor
.
specify_shape
(
W
,
v_W
.
shape
)
_W
.
name
=
'_W'
o
,
_
=
theano
.
scan
(
rnn_fn
,
sequences
=
_u
,
outputs_info
=
_h0
,
non_sequences
=
_W
,
name
=
'rnn_fn'
)
o
=
o
[
-
1
]
eu
=
theano
.
tensor
.
matrix
(
'eu'
)
eh0
=
theano
.
tensor
.
vector
(
'eh0'
)
eW
=
theano
.
tensor
.
matrix
(
'eW'
)
nwo_u
=
theano
.
tensor
.
Rop
(
o
,
_u
,
eu
)
nwo_h0
=
theano
.
tensor
.
Rop
(
o
,
_h0
,
eh0
)
nwo_W
=
theano
.
tensor
.
Rop
(
o
,
_W
,
eW
)
fn_rop
=
theano
.
function
([
u
,
h0
,
W
,
eu
,
eh0
,
eW
],
[
nwo_u
,
nwo_h0
,
nwo_W
])
n2o_u
,
_
=
theano
.
scan
(
lambda
i
,
o
,
u
,
h0
,
W
,
eu
:
(
theano
.
tensor
.
grad
(
o
[
i
],
u
)
*
eu
)
.
sum
(),
sequences
=
tensor
.
arange
(
o
.
shape
[
0
]),
non_sequences
=
[
o
,
u
,
h0
,
W
,
eu
])
n2o_h0
,
_
=
theano
.
scan
(
lambda
i
,
o
,
u
,
h0
,
W
,
eh0
:
(
theano
.
tensor
.
grad
(
o
[
i
],
h0
)
*
eh0
)
.
sum
(),
sequences
=
tensor
.
arange
(
o
.
shape
[
0
]),
non_sequences
=
[
o
,
u
,
h0
,
W
,
eh0
])
n2o_W
,
_
=
theano
.
scan
(
lambda
i
,
o
,
u
,
h0
,
W
,
eW
:
(
theano
.
tensor
.
grad
(
o
[
i
],
W
)
*
eW
)
.
sum
(),
sequences
=
tensor
.
arange
(
o
.
shape
[
0
]),
non_sequences
=
[
o
,
u
,
h0
,
W
,
eW
])
fn_test
=
theano
.
function
([
u
,
h0
,
W
,
eu
,
eh0
,
eW
],
[
n2o_u
,
n2o_h0
,
n2o_W
])
vnu
,
vnh0
,
vnW
=
fn_rop
(
v_u
,
v_h0
,
v_W
,
v_eu
,
v_eh0
,
v_eW
)
tnu
,
tnh0
,
tnW
=
fn_test
(
v_u
,
v_h0
,
v_W
,
v_eu
,
v_eh0
,
v_eW
)
assert
numpy
.
allclose
(
vnu
,
tnu
)
assert
numpy
.
allclose
(
vnh0
,
tnh0
)
assert
numpy
.
allclose
(
vnW
,
tnW
)
def
test_pushout
(
self
):
W1
=
TT
.
matrix
(
'W1'
)
W2
=
TT
.
matrix
(
'W2'
)
h0
=
TT
.
vector
(
'h0'
)
def
lambda_fn
(
h
,
W1
,
W2
):
return
TT
.
dot
(
h
,
W1
+
W2
)
o
,
_
=
theano
.
scan
(
lambda_fn
,
outputs_info
=
h0
,
non_sequences
=
[
W1
,
W2
],
n_steps
=
5
)
f
=
theano
.
function
([
h0
,
W1
,
W2
],
o
)
scan_node
=
[
x
for
x
in
f
.
maker
.
env
.
toposort
()
if
isinstance
(
x
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)][
0
]
assert
len
([
x
for
x
in
scan_node
.
op
.
fn
.
maker
.
env
.
toposort
()
if
isinstance
(
x
.
op
,
theano
.
tensor
.
Elemwise
)])
==
0
def
test_alloc_inputs1
(
self
):
W1
=
TT
.
matrix
(
'W1'
)
W2
=
TT
.
matrix
(
'W2'
)
h0
=
TT
.
vector
(
'h0'
)
def
lambda_fn
(
h
,
W1
,
W2
):
return
TT
.
dot
(
h
,
W1
*
W2
)
o
,
_
=
theano
.
scan
(
lambda_fn
,
outputs_info
=
h0
,
non_sequences
=
[
W1
,
TT
.
zeros_like
(
W2
)],
n_steps
=
5
)
f
=
theano
.
function
([
h0
,
W1
,
W2
],
o
)
scan_node
=
[
x
for
x
in
f
.
maker
.
env
.
toposort
()
if
isinstance
(
x
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)][
0
]
assert
len
([
x
for
x
in
scan_node
.
op
.
fn
.
maker
.
env
.
toposort
()
if
isinstance
(
x
.
op
,
theano
.
tensor
.
Elemwise
)])
==
0
def
test_alloc_inputs2
(
self
):
W1
=
TT
.
matrix
()
W2
=
TT
.
matrix
()
h0
=
TT
.
vector
()
def
lambda_fn
(
W1
,
h
,
W2
):
return
W1
*
TT
.
dot
(
h
,
W2
)
o
,
_
=
theano
.
scan
(
lambda_fn
,
sequences
=
TT
.
zeros_like
(
W1
),
outputs_info
=
h0
,
non_sequences
=
[
TT
.
zeros_like
(
W2
)],
n_steps
=
5
)
f
=
theano
.
function
([
h0
,
W1
,
W2
],
o
)
scan_node
=
[
x
for
x
in
f
.
maker
.
env
.
toposort
()
if
isinstance
(
x
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)][
0
]
assert
len
([
x
for
x
in
scan_node
.
op
.
fn
.
maker
.
env
.
toposort
()
if
isinstance
(
x
.
op
,
theano
.
tensor
.
Elemwise
)])
==
0
def
test_alloc_inputs3
(
self
):
_W1
=
TT
.
matrix
()
_W2
=
TT
.
matrix
()
_h0
=
TT
.
vector
()
W1
=
TT
.
specify_shape
(
_W1
,
(
3
,
3
))
W2
=
TT
.
specify_shape
(
_W2
,
(
3
,
3
))
h0
=
TT
.
specify_shape
(
_h0
,
(
3
,))
def
lambda_fn
(
W1
,
h
,
W2
):
return
W1
*
TT
.
dot
(
h
,
W2
)
o
,
_
=
theano
.
scan
(
lambda_fn
,
sequences
=
TT
.
zeros_like
(
W1
),
outputs_info
=
h0
,
non_sequences
=
[
TT
.
zeros_like
(
W2
)],
n_steps
=
5
)
f
=
theano
.
function
([
_h0
,
_W1
,
_W2
],
o
)
scan_node
=
[
x
for
x
in
f
.
maker
.
env
.
toposort
()
if
isinstance
(
x
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)][
0
]
assert
len
(
scan_node
.
op
.
inputs
)
==
1
def
test_while0
(
self
):
x
=
TT
.
vector
(
'x'
)
def
lambda_fn
(
x_t
):
return
x_t
+
1
,
theano
.
until
(
x_t
>
3
)
o
,
_
=
theano
.
scan
(
lambda_fn
,
x
)
f
=
theano
.
function
([
x
],
o
)
vx
=
numpy
.
zeros
((
50
,))
vx
[
23
]
=
4
out
=
f
(
vx
)
assert
numpy
.
sum
(
out
[
24
:])
==
0
def
test_while1
(
self
):
x
=
TT
.
vector
(
'x'
)
def
lambda_fn
(
x_t
):
return
x_t
+
1
,
theano
.
until
(
x_t
>
3
)
o
,
_
=
theano
.
scan
(
lambda_fn
,
x
)
o2
,
_
=
theano
.
scan
(
lambda
x_t
:
x_t
+
2
,
x
)
f
=
theano
.
function
([
x
],
[
o
,
o2
])
vx
=
numpy
.
zeros
((
50
,))
vx
[
23
]
=
4
out
,
out2
=
f
(
vx
)
assert
numpy
.
sum
(
out
[
24
:])
==
0
assert
numpy
.
all
(
out2
==
vx
+
2
)
lssc
=
[
x
for
x
in
f
.
maker
.
env
.
toposort
()
if
isinstance
(
x
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)]
assert
len
(
lssc
)
==
2
def
test_while2
(
self
):
x
=
TT
.
vector
(
'x'
)
def
lambda_fn
(
x_t
):
return
x_t
+
1
,
theano
.
until
(
x_t
>
3
)
o
,
_
=
theano
.
scan
(
lambda_fn
,
x
)
o2
,
_
=
theano
.
scan
(
lambda
x_t
:(
x_t
+
2
,
theano
.
until
(
x_t
>
3
)),
x
)
f
=
theano
.
function
([
x
],
[
o
,
o2
])
vx
=
numpy
.
zeros
((
50
,))
vx
[
23
]
=
4
out
,
out2
=
f
(
vx
)
assert
numpy
.
sum
(
out
[
24
:])
==
0
assert
numpy
.
sum
(
out2
[
24
:])
==
0
lssc
=
[
x
for
x
in
f
.
maker
.
env
.
toposort
()
if
isinstance
(
x
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)]
assert
len
(
lssc
)
==
1
def
test_speed
():
#
# This function prints out the speed of very simple recurrent
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论