Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b4d3b368
提交
b4d3b368
authored
12月 30, 2011
作者:
Razvan Pascanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make thunk function for scan
上级
8de65286
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
102 行增加
和
3 行删除
+102
-3
scan_op.py
theano/sandbox/scan_module/scan_op.py
+102
-3
没有找到文件。
theano/sandbox/scan_module/scan_op.py
浏览文件 @
b4d3b368
...
@@ -161,10 +161,109 @@ class ScanOp(PureOp):
...
@@ -161,10 +161,109 @@ class ScanOp(PureOp):
return
input_shapes
[
1
:
n_outs
+
1
]
return
input_shapes
[
1
:
n_outs
+
1
]
def
make_thunk
(
self
,
node
,
storage_map
,
compute_map
,
no_recycling
):
def
make_thunk
(
self
,
node
,
storage_map
,
compute_map
,
no_recycling
):
pass
"""
:param node: the Apply node returned by the ``make_node`` function
of the scan op class
def
infer_shape
(
self
,
node
,
input_shapes
):
:param storage_map: dict variable -> one-element-list where a computed
pass
value for this variable may be found.
:param compute_map: dict variable -> one-element-list where a boolean
value will be found. The boolean indicates whether the
variable's storage_map container contains a valid value (True)
or if it has not been computed yet (False).
:param no_recycling: list of variables for which it is forbidden to
reuse memory allocated by a previous call.
:note: If the thunk consults the storage_map on every call, it is safe
for it to ignore the no_recycling argument, because elements of the
no_recycling list will have a value of None in the storage map. If
the thunk can potentially cache return values (like CLinker does),
then it must not do so for variables in the no_recycling list.
"""
# 1. Collect all memory buffers
node_input_storage
=
[
storage_map
[
r
]
for
r
in
node
.
inputs
]
node_output_storage
=
[
storage_map
[
r
]
for
r
in
node
.
outputs
]
node_input_compute
=
[
compute_map
[
r
]
for
r
in
node
.
inputs
]
node_output_compute
=
[
compute_map
[
r
]
for
r
in
node
.
outputs
]
# 2. If the op is not inplace we need to copy over the initial values
if
not
self
.
inplace
:
for
membuf1
,
membuf2
in
izip
(
node_output_storage
,
node_input_storage
[
1
:
1
+
len
(
node_output_storage
)]):
membuf1
[
0
][:]
=
membuf2
[
0
]
# 3. Construct fake shared variables around every argument of scan
givens
=
{}
base_inputs
=
self
.
inputs
[:
len
(
self
.
outputs
)]
aux_inputs
=
self
.
inputs
[
len
(
self
.
outputs
):]
# 3.1 First the auxiliary arguments, those that are parameters or
# input
for
mem_buf
,
var
in
izip
(
ndoe_input_storage
[
1
+
len
(
base_inputs
):],
aux_inputs
):
givens
[
var
]
=
theano
.
shared
(
mem_buf
[
0
],
name
=
var
.
name
,
borrow
=
True
)
# 3.2. Next the states (numeric or not) and the outputs
updates
=
{}
n_numeric_values
=
len
(
self
.
lengths
)
for
pos
,
(
mem_buf
,
var
,
expr
)
in
enumerate
(
izip
(
node_output_storage
,
base_inputs
,
self
.
outputs
)):
givens
[
var
]
=
theano
.
shared
(
mem_buf
[
0
],
name
=
var
.
name
,
borrow
=
True
)
updates
[
givens
[
var
]]
=
expr
if
pos
<
n_numeric_values
:
self
.
lengths
[
pos
]
.
set_value
(
mem_buf
[
0
]
.
shape
[
0
])
givens
[
self
.
lengths
[
pos
]]
=
\
tensor
.
constant
(
mem_buf
[
0
]
.
shape
[
0
])
# 3.3 Add the update for the index of scan
updates
[
self
.
t
]
=
self
.
t
+
numpy
.
int64
(
1
)
# 4.1 Construct the inner function of scan
fn_outs
=
[]
if
self
.
as_repeatUntil
is
not
None
:
fn_outs
=
self
.
as_repeatUntil
self
.
fn
=
theano
.
function
([],
fn_outs
,
givens
=
givens
,
updates
=
updates
,
mode
=
self
.
mode_instance
,
name
=
self
.
name
,
profile
=
self
.
profile
)
# Construct the perform
if
self
.
as_repeatUntil
is
not
None
:
def
p
(
node
,
args
,
outs
):
pos
=
0
cont
=
1
# reset all switches if any
for
sw
in
self
.
swithces
:
sw
.
set_value
(
numpy
.
int8
(
0
),
borrow
=
True
)
while
cont
and
pos
<
node_input_storage
[
0
][
0
]:
cont
=
self
.
fn
()
pos
=
pos
+
1
# We need to trim the outputs if they are longer
for
pos
,
membuf
in
enumerate
(
node_output_storage
[:
n_numeric_values
]):
if
membuf
[
0
]
.
shape
[
0
]
>
pos
+
self
.
mintaps
[
pos
]:
membuf
[
0
]
=
membuf
[
0
][:
pos
+
self
.
mintaps
[
pos
]]
else
:
def
p
(
node
,
args
,
outs
):
for
sw
in
self
.
switches
:
sw
.
set_value
(
numpy
.
int8
(
0
),
borrow
=
True
)
self
.
fn
.
fn
(
n_calls
=
node_input_storage
[
0
][
0
])
def
rval
(
p
=
p
,
i
=
node_input_storage
,
o
=
node_output_storage
,
n
=
node
):
r
=
perform
(
n
,
[
x
[
0
]
for
x
in
i
],
o
)
for
o
in
node
.
outputs
:
compute_map
[
o
][
0
]
=
True
return
r
rval
.
inputs
=
node_input_storage
rval
.
outputs
=
node_output_storage
rval
.
perform
=
p
rval
.
lazy
=
False
return
rval
def
grad
(
self
,
args
,
g_outs
):
def
grad
(
self
,
args
,
g_outs
):
pass
pass
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论