Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
bc2f50e5
提交
bc2f50e5
authored
1月 13, 2012
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #340 from pascanur/fix_tests_sandbox_scan
Fix tests sandbox scan
上级
5e10c1f1
38a8c842
全部展开
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
45 行增加
和
18 行删除
+45
-18
scan.py
theano/sandbox/scan_module/scan.py
+18
-5
scan_op.py
theano/sandbox/scan_module/scan_op.py
+2
-0
scan_utils.py
theano/sandbox/scan_module/scan_utils.py
+19
-7
test_scan.py
theano/sandbox/scan_module/tests/test_scan.py
+0
-0
test_utils.py
theano/sandbox/scan_module/tests/test_utils.py
+6
-6
没有找到文件。
theano/sandbox/scan_module/scan.py
浏览文件 @
bc2f50e5
...
...
@@ -49,7 +49,8 @@ import numpy
from
theano.compile
import
SharedVariable
,
function
from
theano
import
compile
from
theano
import
gof
from
theano.tensor
import
opt
from
theano.tensor
import
opt
,
TensorVariable
from
theano.tensor.sharedvar
import
TensorSharedVariable
from
theano
import
tensor
from
theano
import
config
from
theano.updates
import
Updates
...
...
@@ -435,10 +436,10 @@ def scan(fn,
pos
=
len
(
lengths
)
for
sv
in
shared_inputs
:
if
sv
in
update_d
:
if
isinstance
(
sv
,
TensorType
):
if
isinstance
(
sv
,
(
TensorVariable
,
TensorSharedVariable
)
):
# We can treat it as a sit sot
nw_state
=
scan_utils
.
expand
(
tensor
.
unbroadcast
(
tensor
.
shape_padleft
(
sv
,
0
),
T
)
)
tensor
.
unbroadcast
(
tensor
.
shape_padleft
(
sv
),
0
),
T
)
additional_lengths
.
append
(
scalar_shared
(
numpy
.
int64
(
0
),
name
=
'l
%
d'
%
pos
))
pos
=
pos
+
1
...
...
@@ -454,6 +455,17 @@ def scan(fn,
non_numeric_output_states
.
append
(
update_d
[
sv
])
original_non_numeric_shared_variables
.
append
(
sv
)
# Replace shared variables in the update
_additional_output_states
=
[]
replace
=
{}
for
sv
,
buf
in
zip
(
original_numeric_shared_variables
,
additional_input_states
):
replace
[
sv
]
=
buf
[
t
]
for
out
in
additional_output_states
:
_additional_output_states
.
append
(
scan_utils
.
clone
(
out
,
replace
=
replace
))
additional_output_states
=
_additional_output_states
# 5.2 Collect inputs/outputs of the inner function
inputs
=
[]
outputs
=
[]
...
...
@@ -515,7 +527,7 @@ def scan(fn,
for
pos
in
xrange
(
len
(
states_and_outputs
)):
out
=
scan_utils
.
ScanPermutation
(
mintaps
[
pos
])(
scan_outputs_update_rules
[
pos
],
t
)
scan_outputs
.
append
(
out
[
mintap
:])
scan_outputs
.
append
(
out
[
mintap
s
[
pos
]
:])
# 5.6 Construct updates dictionary
update_rules
=
scan_outputs_update_rules
[
len
(
states_and_outputs
):]
updates
=
{}
...
...
@@ -553,7 +565,8 @@ def one_step_scan(fn,
arg_info
)
# go through the taps
mintap
=
abs
(
numpy
.
min
(
arg_info
[
'taps'
]))
states_slices
.
append
(
arg_info
[
'initial'
][
k
+
mintap
])
states_slices
.
extend
(
[
arg_info
[
'initial'
][
k
+
mintap
]
for
k
in
arg_info
[
'taps'
]])
# Re-order args
args
=
(
inputs_slices
+
states_slices
+
parameters
)
...
...
theano/sandbox/scan_module/scan_op.py
浏览文件 @
bc2f50e5
...
...
@@ -277,6 +277,7 @@ class ScanOp(PureOp):
for
var
,
length
,
val
in
state_buffers
:
var
.
set_value
(
val
[
0
],
borrow
=
True
)
length
.
set_value
(
val
[
0
]
.
shape
[
0
],
borrow
=
True
)
self
.
index
.
set_value
(
numpy
.
int64
(
0
))
# grab fixed arguments
fix_args
=
[
x
[
0
]
for
x
in
non_tensor_buffers
]
while
cont
and
pos
<
node_input_storage
[
0
][
0
]:
...
...
@@ -320,6 +321,7 @@ class ScanOp(PureOp):
for
var
,
length
,
val
in
state_buffers
:
var
.
set_value
(
val
[
0
],
borrow
=
True
)
length
.
set_value
(
val
[
0
]
.
shape
[
0
],
borrow
=
True
)
self
.
index
.
set_value
(
numpy
.
int64
(
0
))
# grab fixed arguments
fix_args
=
[
x
[
0
]
for
x
in
non_tensor_buffers
]
for
dx
in
xrange
(
node_input_storage
[
0
][
0
]):
...
...
theano/sandbox/scan_module/scan_utils.py
浏览文件 @
bc2f50e5
...
...
@@ -220,17 +220,29 @@ def canonical_arguments(sequences,
# We cut the sequence such that seq[i] to correspond to
# seq[i-k]
if
maxtap
<
0
:
offset
=
abs
(
maxtap
)
offset
_max
=
abs
(
maxtap
)
else
:
offset
=
0
offset_max
=
0
if
mintap
<
0
:
offset_min
=
abs
(
mintap
)
else
:
offset_min
=
0
nw_input
=
orig_input
if
maxtap
==
mintap
and
maxtap
!=
0
:
nw_input
=
nw_input
[:
abs
(
maxtap
)]
elif
maxtap
-
k
!=
0
:
nw_input
=
nw_input
[
offset
+
k
-
mintap
:
\
-
(
maxtap
-
k
)]
if
maxtap
>
0
:
nw_input
=
nw_input
[
maxtap
:]
else
:
nw_input
=
nw_input
[:
maxtap
]
else
:
st
=
k
+
offset_min
if
maxtap
>
0
:
ed
=
-
(
maxtap
+
offset_min
-
st
)
else
:
ed
=
-
(
offset_min
-
st
)
if
ed
!=
0
:
nw_input
=
nw_input
[
st
:
ed
]
else
:
nw_input
=
nw_input
[
offset
+
k
-
mintap
:]
nw_input
=
nw_input
[
st
:]
inputs
.
append
(
nw_input
)
else
:
raise
ValueError
(
'Provided sequence makes no sense'
,
str
(
input
))
...
...
theano/sandbox/scan_module/tests/test_scan.py
浏览文件 @
bc2f50e5
差异被折叠。
点击展开。
theano/sandbox/scan_module/tests/test_utils.py
浏览文件 @
bc2f50e5
...
...
@@ -166,7 +166,7 @@ def grab_scan_node(output):
class
TestScanUtils
(
unittest
.
TestCase
):
def
test_cloning_no_replace_strict_copy_inputs
(
self
):
def
test
001
_cloning_no_replace_strict_copy_inputs
(
self
):
# This has nothing to do with scan, but it refers to the clone
# function that scan uses internally and that pfunc uses now and
# that users might want to use
...
...
@@ -185,7 +185,7 @@ class TestScanUtils(unittest.TestCase):
assert
x
in
f2_inp
assert
y
in
f2_inp
def
test_cloning_no_replace_strict_not_copy_inputs
(
self
):
def
test
002
_cloning_no_replace_strict_not_copy_inputs
(
self
):
# This has nothing to do with scan, but it refers to the clone
# function that scan uses internally and that pfunc uses now and
# that users might want to use
...
...
@@ -204,7 +204,7 @@ class TestScanUtils(unittest.TestCase):
assert
not
x
in
f2_inp
assert
not
y
in
f2_inp
def
test_cloning_replace_strict_copy_inputs
(
self
):
def
test
003
_cloning_replace_strict_copy_inputs
(
self
):
# This has nothing to do with scan, but it refers to the clone
# function that scan uses internally and that pfunc uses now and
# that users might want to use
...
...
@@ -223,7 +223,7 @@ class TestScanUtils(unittest.TestCase):
assert
x
in
f2_inp
assert
y2
in
f2_inp
def
test_cloning_replace_not_strict_copy_inputs
(
self
):
def
test
004
_cloning_replace_not_strict_copy_inputs
(
self
):
# This has nothing to do with scan, but it refers to the clone
# function that scan uses internally and that pfunc uses now and
# that users might want to use
...
...
@@ -242,7 +242,7 @@ class TestScanUtils(unittest.TestCase):
assert
x
in
f2_inp
assert
y2
in
f2_inp
def
test_cloning_replace_strict_not_copy_inputs
(
self
):
def
test
005
_cloning_replace_strict_not_copy_inputs
(
self
):
# This has nothing to do with scan, but it refers to the clone
# function that scan uses internally and that pfunc uses now and
# that users might want to use
...
...
@@ -261,7 +261,7 @@ class TestScanUtils(unittest.TestCase):
assert
not
x
in
f2_inp
assert
not
y2
in
f2_inp
def
test_cloning_replace_not_strict_not_copy_inputs
(
self
):
def
test
006
_cloning_replace_not_strict_not_copy_inputs
(
self
):
# This has nothing to do with scan, but it refers to the clone
# function that scan uses internally and that pfunc uses now and
# that users might want to use
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论