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 个修改的文件
包含
131 行增加
和
90 行删除
+131
-90
test_scan.py
theano/sandbox/scan_module/tests/test_scan.py
+131
-90
没有找到文件。
theano/sandbox/scan_module/tests/test_scan.py
浏览文件 @
57bec52f
...
...
@@ -246,96 +246,137 @@ class TestScan(unittest.TestCase):
updates
=
updates
,
allow_input_downcast
=
True
)
if
n_steps
is
not
None
and
abs
(
n_steps
)
==
1
:
assert
len
([
x
for
x
in
my_f
.
maker
.
env
.
toposort
()
if
isinstance
(
x
.
op
,
scan_module
.
scan_op
.
ScanOp
)])
==
0
# Generating data
# Scenario 1 : Good fit shapes
inputs_values
=
[]
for
info
in
inputs_info
:
taps
=
[
x
[
'tap'
]
for
x
in
info
]
offset
=
abs
(
numpy
.
min
([
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
))
inputs_values
.
append
(
data
)
state_values
=
[]
for
info
in
states_info
:
taps
=
[
x
[
'tap'
]
for
x
in
info
]
offset
=
abs
(
numpy
.
min
(
taps
))
data
=
rng
.
uniform
(
size
=
(
offset
,
4
))
state_values
.
append
(
data
)
param_values
=
[
rng
.
uniform
(
size
=
(
4
,))
for
k
in
xrange
(
n_parameters
)]
for
var
,
val
in
zip
(
shared_vars
,
original_shared_values
):
var
.
set_value
(
val
)
theano_outs
=
my_f
(
*
(
inputs_values
+
state_values
+
param_values
))
args
=
([
n_steps
,
go_backwards
]
+
input_values
+
state_values
+
param_values
)
rvals
=
execute_inner_graph
(
*
args
)
numpy_outs
,
numpy_shared
=
rvals
assert
len
(
numpy_outs
)
==
len
(
theano_outs
)
assert
len
(
numpy_shared
)
==
len
(
shared_vars
)
for
th_out
,
num_out
in
zip
(
theano_outs
,
numpy_outs
):
assert
numpy
.
allclose
(
th_out
,
num_out
)
for
th_out
,
num_out
in
zip
(
shared_outs
,
numpy_shared
):
assert
numpy
.
allclose
(
th_out
.
get_value
(),
num_out
)
# Scenario 2 : Loose fit (sequences longer then required)
inputs_values
=
[]
for
pos
,
info
in
enumerate
(
inputs_info
):
taps
=
[
x
[
'tap'
]
for
x
in
info
]
offset
=
abs
(
numpy
.
min
([
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
))
inputs_values
.
append
(
data
)
state_values
=
[]
for
pos
,
info
in
enumerate
(
states_info
):
taps
=
[
x
[
'tap'
]
for
x
in
info
]
offset
=
abs
(
numpy
.
min
(
taps
))
data
=
rng
.
uniform
(
size
=
(
offset
+
pos
+
1
,
4
))
state_values
.
append
(
data
)
param_values
=
[
rng
.
uniform
(
size
=
(
4
,))
for
k
in
xrange
(
n_parameters
)]
for
var
,
val
in
zip
(
shared_vars
,
original_shared_values
):
var
.
set_value
(
val
)
theano_outs
=
my_f
(
*
(
inputs_values
+
state_values
+
param_values
))
args
=
([
n_steps
,
go_backwards
]
+
input_values
+
state_values
+
param_values
)
rvals
=
execute_inner_graph
(
*
args
)
numpy_outs
,
numpy_shared
=
rvals
assert
len
(
numpy_outs
)
==
len
(
theano_outs
)
assert
len
(
numpy_shared
)
==
len
(
shared_vars
)
for
th_out
,
num_out
in
zip
(
theano_outs
,
numpy_outs
):
assert
numpy
.
allclose
(
th_out
,
num_out
)
for
th_out
,
num_out
in
zip
(
shared_outs
,
numpy_shared
):
assert
numpy
.
allclose
(
th_out
.
get_value
(),
num_out
)
# Scenario 3 : Less data then required
inputs_values
=
[]
for
pos
,
info
in
enumerate
(
inputs_info
):
taps
=
[
x
[
'tap'
]
for
x
in
info
]
offset
=
abs
(
numpy
.
min
([
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
))
inputs_values
.
append
(
data
)
state_values
=
[]
for
pos
,
info
in
enumerate
(
states_info
):
taps
=
[
x
[
'tap'
]
for
x
in
info
]
offset
=
abs
(
numpy
.
min
(
taps
))
data
=
rng
.
uniform
(
size
=
(
offset
-
1
,
4
))
state_values
.
append
(
data
)
param_values
=
[
rng
.
uniform
(
size
=
(
4
,))
for
k
in
xrange
(
n_parameters
)]
for
var
,
val
in
zip
(
shared_vars
,
original_shared_values
):
var
.
set_value
(
val
)
self
.
assertRaises
(
Exception
,
my_f
,
inputs
+
state_values
+
param_values
)
def
test000_generate_tests
(
self
):
if
n_steps
is
not
None
and
abs
(
n_steps
)
==
1
:
all_nodes
=
my_f
.
maker
.
env
.
toposort
()
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
# Scenario 1 : Good fit shapes
input_values
=
[]
for
info
in
inputs_info
:
taps
=
[
x
[
'tap'
]
for
x
in
info
]
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
])
data
=
rng
.
uniform
(
size
=
(
abs
(
_n_steps
)
+
offset
,
4
))
input_values
.
append
(
data
)
state_values
=
[]
for
info
in
states_info
:
taps
=
[
x
[
'tap'
]
for
x
in
info
]
offset
=
abs
(
numpy
.
min
(
taps
))
if
offset
>
1
:
data
=
rng
.
uniform
(
size
=
(
offset
,
4
))
else
:
data
=
rng
.
uniform
(
size
=
(
4
,))
data
=
numpy
.
arange
(
4
)
state_values
.
append
(
data
)
param_values
=
[
rng
.
uniform
(
size
=
(
4
,))
for
k
in
xrange
(
n_parameters
)]
param_values
=
[
numpy
.
arange
(
4
)
for
k
in
xrange
(
n_parameters
)]
for
var
,
val
in
zip
(
shared_vars
,
original_shared_values
):
var
.
set_value
(
val
)
theano_outs
=
my_f
(
*
(
input_values
+
state_values
+
param_values
))
args
=
([
_n_steps
,
go_backwards
]
+
input_values
+
state_values
+
param_values
)
rvals
=
execute_inner_graph
(
*
args
)
numpy_outs
,
numpy_shared
=
rvals
assert
len
(
numpy_outs
)
==
len
(
theano_outs
)
assert
len
(
numpy_shared
)
==
len
(
shared_vars
)
for
th_out
,
num_out
in
zip
(
theano_outs
,
numpy_outs
):
try
:
assert
numpy
.
allclose
(
th_out
,
num_out
)
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
)
except
:
import
ipdb
;
ipdb
.
set_trace
()
# Scenario 2 : Loose fit (sequences longer then required)
print
>>
sys
.
stderr
,
' Scenario 2. Loose shapes'
input_values
=
[]
for
pos
,
info
in
enumerate
(
inputs_info
):
taps
=
[
x
[
'tap'
]
for
x
in
info
]
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
])
if
n_steps
is
not
None
:
# 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
=
[]
for
pos
,
info
in
enumerate
(
states_info
):
taps
=
[
x
[
'tap'
]
for
x
in
info
]
offset
=
abs
(
numpy
.
min
(
taps
))
if
offset
>
1
:
data
=
rng
.
uniform
(
size
=
(
offset
+
pos
+
1
,
4
))
else
:
data
=
rng
.
uniform
(
size
=
(
4
,))
state_values
.
append
(
data
)
param_values
=
[
rng
.
uniform
(
size
=
(
4
,))
for
k
in
xrange
(
n_parameters
)]
for
var
,
val
in
zip
(
shared_vars
,
original_shared_values
):
var
.
set_value
(
val
)
theano_outs
=
my_f
(
*
(
input_values
+
state_values
+
param_values
))
args
=
([
_n_steps
,
go_backwards
]
+
input_values
+
state_values
+
param_values
)
rvals
=
execute_inner_graph
(
*
args
)
numpy_outs
,
numpy_shared
=
rvals
assert
len
(
numpy_outs
)
==
len
(
theano_outs
)
assert
len
(
numpy_shared
)
==
len
(
shared_vars
)
for
th_out
,
num_out
in
zip
(
theano_outs
,
numpy_outs
):
assert
numpy
.
allclose
(
th_out
,
num_out
)
for
th_out
,
num_out
in
zip
(
shared_vars
,
numpy_shared
):
assert
numpy
.
allclose
(
th_out
.
get_value
(),
num_out
)
# Scenario 3 : Less data then required
print
>>
sys
.
stderr
,
' Scenario 2. Wrong shapes'
input_values
=
[]
for
pos
,
info
in
enumerate
(
inputs_info
):
taps
=
[
x
[
'tap'
]
for
x
in
info
]
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
])
data
=
rng
.
uniform
(
size
=
(
abs
(
_n_steps
)
+
offset
-
1
,
4
))
input_values
.
append
(
data
)
state_values
=
[]
for
pos
,
info
in
enumerate
(
states_info
):
taps
=
[
x
[
'tap'
]
for
x
in
info
]
offset
=
abs
(
numpy
.
min
(
taps
))
data
=
rng
.
uniform
(
size
=
(
offset
-
1
,
4
))
state_values
.
append
(
data
)
param_values
=
[
rng
.
uniform
(
size
=
(
4
,))
for
k
in
xrange
(
n_parameters
)]
for
var
,
val
in
zip
(
shared_vars
,
original_shared_values
):
var
.
set_value
(
val
)
self
.
assertRaises
(
Exception
,
my_f
,
inputs
+
state_values
+
param_values
)
def
test001_generate_tests
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
all_inputs_info
=
[[]]
possible_taps_use_pairs
=
[[
dict
(
tap
=
0
,
use
=
True
)],
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论