Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
57bec52f
提交
57bec52f
authored
1月 13, 2012
作者:
Razvan Pascanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mostly intendention
上级
d200d034
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
62 行增加
和
21 行删除
+62
-21
test_scan.py
theano/sandbox/scan_module/tests/test_scan.py
+62
-21
没有找到文件。
theano/sandbox/scan_module/tests/test_scan.py
浏览文件 @
57bec52f
...
@@ -247,30 +247,48 @@ class TestScan(unittest.TestCase):
...
@@ -247,30 +247,48 @@ class TestScan(unittest.TestCase):
allow_input_downcast
=
True
)
allow_input_downcast
=
True
)
if
n_steps
is
not
None
and
abs
(
n_steps
)
==
1
:
if
n_steps
is
not
None
and
abs
(
n_steps
)
==
1
:
assert
len
([
x
for
x
in
my_f
.
maker
.
env
.
toposort
()
all_nodes
=
my_f
.
maker
.
env
.
toposort
()
if
isinstance
(
x
.
op
,
scan_module
.
scan_op
.
ScanOp
)])
==
0
assert
len
([
x
for
x
in
all_nodes
if
isinstance
(
x
.
op
,
ScanOp
)])
==
0
print
>>
sys
.
stderr
,
' n_steps'
,
n_steps
print
>>
sys
.
stderr
,
' go_backwards'
,
go_backwards
print
>>
sys
.
stderr
,
' Scenario 1. Correct shape'
if
n_steps
is
not
None
:
_n_steps
=
n_steps
else
:
_n_steps
=
8
# Generating data
# Generating data
# Scenario 1 : Good fit shapes
# Scenario 1 : Good fit shapes
inputs
_values
=
[]
input
_values
=
[]
for
info
in
inputs_info
:
for
info
in
inputs_info
:
taps
=
[
x
[
'tap'
]
for
x
in
info
]
taps
=
[
x
[
'tap'
]
for
x
in
info
]
offset
=
abs
(
numpy
.
min
([
x
for
x
in
taps
if
x
<
0
]))
offset
=
0
if
len
([
x
for
x
in
taps
if
x
<
0
])
>
0
:
offset
+=
abs
(
numpy
.
min
([
x
for
x
in
taps
if
x
<
0
]))
if
len
([
x
for
x
in
taps
if
x
>
0
])
>
0
:
offset
+=
numpy
.
max
([
x
for
x
in
taps
if
x
>
0
])
offset
+=
numpy
.
max
([
x
for
x
in
taps
if
x
>
0
])
data
=
rng
.
uniform
(
size
=
(
n_steps
+
offset
,
4
))
data
=
rng
.
uniform
(
size
=
(
abs
(
_n_steps
)
+
offset
,
4
))
inputs
_values
.
append
(
data
)
input
_values
.
append
(
data
)
state_values
=
[]
state_values
=
[]
for
info
in
states_info
:
for
info
in
states_info
:
taps
=
[
x
[
'tap'
]
for
x
in
info
]
taps
=
[
x
[
'tap'
]
for
x
in
info
]
offset
=
abs
(
numpy
.
min
(
taps
))
offset
=
abs
(
numpy
.
min
(
taps
))
if
offset
>
1
:
data
=
rng
.
uniform
(
size
=
(
offset
,
4
))
data
=
rng
.
uniform
(
size
=
(
offset
,
4
))
else
:
data
=
rng
.
uniform
(
size
=
(
4
,))
data
=
numpy
.
arange
(
4
)
state_values
.
append
(
data
)
state_values
.
append
(
data
)
param_values
=
[
rng
.
uniform
(
size
=
(
4
,))
for
k
in
param_values
=
[
rng
.
uniform
(
size
=
(
4
,))
for
k
in
xrange
(
n_parameters
)]
xrange
(
n_parameters
)]
param_values
=
[
numpy
.
arange
(
4
)
for
k
in
xrange
(
n_parameters
)]
for
var
,
val
in
zip
(
shared_vars
,
original_shared_values
):
for
var
,
val
in
zip
(
shared_vars
,
original_shared_values
):
var
.
set_value
(
val
)
var
.
set_value
(
val
)
theano_outs
=
my_f
(
*
(
inputs
_values
+
state_values
+
theano_outs
=
my_f
(
*
(
input
_values
+
state_values
+
param_values
))
param_values
))
args
=
([
n_steps
,
go_backwards
]
+
args
=
([
_
n_steps
,
go_backwards
]
+
input_values
+
input_values
+
state_values
+
state_values
+
param_values
)
param_values
)
...
@@ -279,30 +297,48 @@ class TestScan(unittest.TestCase):
...
@@ -279,30 +297,48 @@ class TestScan(unittest.TestCase):
assert
len
(
numpy_outs
)
==
len
(
theano_outs
)
assert
len
(
numpy_outs
)
==
len
(
theano_outs
)
assert
len
(
numpy_shared
)
==
len
(
shared_vars
)
assert
len
(
numpy_shared
)
==
len
(
shared_vars
)
for
th_out
,
num_out
in
zip
(
theano_outs
,
numpy_outs
):
for
th_out
,
num_out
in
zip
(
theano_outs
,
numpy_outs
):
try
:
assert
numpy
.
allclose
(
th_out
,
num_out
)
assert
numpy
.
allclose
(
th_out
,
num_out
)
for
th_out
,
num_out
in
zip
(
shared_outs
,
numpy_shared
):
except
:
import
ipdb
;
ipdb
.
set_trace
()
for
th_out
,
num_out
in
zip
(
shared_vars
,
numpy_shared
):
try
:
assert
numpy
.
allclose
(
th_out
.
get_value
(),
num_out
)
assert
numpy
.
allclose
(
th_out
.
get_value
(),
num_out
)
except
:
import
ipdb
;
ipdb
.
set_trace
()
# Scenario 2 : Loose fit (sequences longer then required)
# Scenario 2 : Loose fit (sequences longer then required)
inputs_values
=
[]
print
>>
sys
.
stderr
,
' Scenario 2. Loose shapes'
input_values
=
[]
for
pos
,
info
in
enumerate
(
inputs_info
):
for
pos
,
info
in
enumerate
(
inputs_info
):
taps
=
[
x
[
'tap'
]
for
x
in
info
]
taps
=
[
x
[
'tap'
]
for
x
in
info
]
offset
=
abs
(
numpy
.
min
([
x
for
x
in
taps
if
x
<
0
]))
offset
=
0
if
len
([
x
for
x
in
taps
if
x
<
0
])
>
0
:
offset
+=
abs
(
numpy
.
min
([
x
for
x
in
taps
if
x
<
0
]))
if
len
([
x
for
x
in
taps
if
x
>
0
])
>
0
:
offset
+=
numpy
.
max
([
x
for
x
in
taps
if
x
>
0
])
offset
+=
numpy
.
max
([
x
for
x
in
taps
if
x
>
0
])
data
=
rng
.
uniform
(
size
=
(
n_steps
+
offset
+
pos
+
1
,
4
))
if
n_steps
is
not
None
:
inputs_values
.
append
(
data
)
# loose inputs make sense only when n_steps is
# defined
data
=
rng
.
uniform
(
size
=
(
abs
(
_n_steps
)
+
offset
+
pos
+
1
,
4
))
else
:
data
=
rng
.
uniform
(
size
=
(
abs
(
_n_steps
)
+
offset
,
4
))
input_values
.
append
(
data
)
state_values
=
[]
state_values
=
[]
for
pos
,
info
in
enumerate
(
states_info
):
for
pos
,
info
in
enumerate
(
states_info
):
taps
=
[
x
[
'tap'
]
for
x
in
info
]
taps
=
[
x
[
'tap'
]
for
x
in
info
]
offset
=
abs
(
numpy
.
min
(
taps
))
offset
=
abs
(
numpy
.
min
(
taps
))
if
offset
>
1
:
data
=
rng
.
uniform
(
size
=
(
offset
+
pos
+
1
,
4
))
data
=
rng
.
uniform
(
size
=
(
offset
+
pos
+
1
,
4
))
else
:
data
=
rng
.
uniform
(
size
=
(
4
,))
state_values
.
append
(
data
)
state_values
.
append
(
data
)
param_values
=
[
rng
.
uniform
(
size
=
(
4
,))
for
k
in
param_values
=
[
rng
.
uniform
(
size
=
(
4
,))
for
k
in
xrange
(
n_parameters
)]
xrange
(
n_parameters
)]
for
var
,
val
in
zip
(
shared_vars
,
original_shared_values
):
for
var
,
val
in
zip
(
shared_vars
,
original_shared_values
):
var
.
set_value
(
val
)
var
.
set_value
(
val
)
theano_outs
=
my_f
(
*
(
inputs
_values
+
state_values
+
theano_outs
=
my_f
(
*
(
input
_values
+
state_values
+
param_values
))
param_values
))
args
=
([
n_steps
,
go_backwards
]
+
args
=
([
_
n_steps
,
go_backwards
]
+
input_values
+
input_values
+
state_values
+
state_values
+
param_values
)
param_values
)
...
@@ -310,18 +346,23 @@ class TestScan(unittest.TestCase):
...
@@ -310,18 +346,23 @@ class TestScan(unittest.TestCase):
numpy_outs
,
numpy_shared
=
rvals
numpy_outs
,
numpy_shared
=
rvals
assert
len
(
numpy_outs
)
==
len
(
theano_outs
)
assert
len
(
numpy_outs
)
==
len
(
theano_outs
)
assert
len
(
numpy_shared
)
==
len
(
shared_vars
)
assert
len
(
numpy_shared
)
==
len
(
shared_vars
)
for
th_out
,
num_out
in
zip
(
theano_outs
,
numpy_outs
):
for
th_out
,
num_out
in
zip
(
theano_outs
,
numpy_outs
):
assert
numpy
.
allclose
(
th_out
,
num_out
)
assert
numpy
.
allclose
(
th_out
,
num_out
)
for
th_out
,
num_out
in
zip
(
shared_out
s
,
numpy_shared
):
for
th_out
,
num_out
in
zip
(
shared_var
s
,
numpy_shared
):
assert
numpy
.
allclose
(
th_out
.
get_value
(),
num_out
)
assert
numpy
.
allclose
(
th_out
.
get_value
(),
num_out
)
# Scenario 3 : Less data then required
# Scenario 3 : Less data then required
inputs_values
=
[]
print
>>
sys
.
stderr
,
' Scenario 2. Wrong shapes'
input_values
=
[]
for
pos
,
info
in
enumerate
(
inputs_info
):
for
pos
,
info
in
enumerate
(
inputs_info
):
taps
=
[
x
[
'tap'
]
for
x
in
info
]
taps
=
[
x
[
'tap'
]
for
x
in
info
]
offset
=
abs
(
numpy
.
min
([
x
for
x
in
taps
if
x
<
0
]))
offset
=
0
if
len
([
x
for
x
in
taps
if
x
<
0
])
>
0
:
offset
+=
abs
(
numpy
.
min
([
x
for
x
in
taps
if
x
<
0
]))
if
len
([
x
for
x
in
taps
if
x
>
0
])
>
0
:
offset
+=
numpy
.
max
([
x
for
x
in
taps
if
x
>
0
])
offset
+=
numpy
.
max
([
x
for
x
in
taps
if
x
>
0
])
data
=
rng
.
uniform
(
size
=
(
n_steps
+
offset
-
1
,
4
))
data
=
rng
.
uniform
(
size
=
(
abs
(
_n_steps
)
+
offset
-
1
,
4
))
inputs
_values
.
append
(
data
)
input
_values
.
append
(
data
)
state_values
=
[]
state_values
=
[]
for
pos
,
info
in
enumerate
(
states_info
):
for
pos
,
info
in
enumerate
(
states_info
):
taps
=
[
x
[
'tap'
]
for
x
in
info
]
taps
=
[
x
[
'tap'
]
for
x
in
info
]
...
@@ -335,7 +376,7 @@ class TestScan(unittest.TestCase):
...
@@ -335,7 +376,7 @@ class TestScan(unittest.TestCase):
self
.
assertRaises
(
Exception
,
my_f
,
self
.
assertRaises
(
Exception
,
my_f
,
inputs
+
state_values
+
param_values
)
inputs
+
state_values
+
param_values
)
def
test00
0
_generate_tests
(
self
):
def
test00
1
_generate_tests
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
all_inputs_info
=
[[]]
all_inputs_info
=
[[]]
possible_taps_use_pairs
=
[[
dict
(
tap
=
0
,
use
=
True
)],
possible_taps_use_pairs
=
[[
dict
(
tap
=
0
,
use
=
True
)],
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论