Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b15fadcc
提交
b15fadcc
authored
10月 14, 2010
作者:
Razvan Pascanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[scan][doc][coding-style] revamped foldl foldr and remove some old
comment of James'
上级
0e14d351
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
60 行增加
和
49 行删除
+60
-49
scan.py
theano/scan.py
+60
-49
没有找到文件。
theano/scan.py
浏览文件 @
b15fadcc
...
...
@@ -184,68 +184,79 @@ def reduce( fn
,
mode
=
mode
,
name
=
name
)
def
foldl
(
fn
,
sequences
,
outputs_info
,
non_sequences
=
[],
mode
=
None
,
name
=
None
):
""" Similar behaviour as haskell foldl
:param fn: the function to be applied over the elements in
sequences ( see scan `fn` for more info)
# The ``foldl`` view of Scan Op.
def
foldl
(
fn
,
sequences
,
outputs_info
,
non_sequences
=
None
,
mode
=
None
,
name
=
None
):
"""
Similar behaviour as haskell's foldl
:param
sequences: list of arrays over which foldl should
iterate (see scan for more info)
:param
fn: The function that ``foldl`` applies at each iteration step
(see ``scan`` for more info).
:param outputs_info: information about outputs (mainly the initial state
of each )
:param
non_sequences: list of other arguments of `fn` over which
foldl shouldn't iterate (see scan
for more info)
:param
sequences: List of sequences over which ``foldl`` iterates
(see ``scan``
for more info)
:param mode: see scan
:param name: see scan
:param outputs_info: List of dictionaries describing the outputs of
reduce (see ``scan`` for more info).
:param non_sequences: List of arguments passed to `fn`. ``foldl`` will
not iterate over these arguments (see ``scan`` for
more info).
:param mode: See ``scan``.
:param name: See ``scan``.
"""
return
reduce
(
fn
=
fn
,
sequences
=
sequences
,
outputs_info
=
outputs_info
,
non_sequences
=
non_sequences
,
go_backwards
=
False
,
mode
=
mode
,
name
=
name
)
# The ``foldl`` view of Scan Op.
def
foldr
(
fn
,
sequences
,
outputs_info
,
non_sequences
=
None
,
mode
=
None
,
name
=
None
):
"""
return
reduce
(
fn
=
fn
,
sequences
=
sequences
,
outputs_info
=
outputs_info
,
non_sequences
=
non_sequences
,
go_backwards
=
False
,
mode
=
mode
,
name
=
name
)
def
foldr
(
fn
,
sequences
,
outputs_info
,
non_sequences
=
[],
mode
=
None
):
""" Similar behaviour as haskell foldr
Similar behaviour as haskell' foldr
:param fn:
the function to be applied over the elements in
sequences ( see scan `fn` for more info)
:param fn:
The function that ``foldr`` applies at each iteration step
(see ``scan`` for more info).
:param sequences: list of arrays over which foldr should
iterate (see scan for more info)
:param
outputs_info: information about outputs (mainly the initial state
of each
)
:param
sequences: List of sequences over which ``foldr`` iterates
(see ``scan`` for more info
)
:param
non_sequences: list of other arguments of `fn` over which
foldr shouldn't iterate (see scan for more info)
:param
outputs_info: List of dictionaries describing the outputs of
reduce (see ``scan`` for more info).
:param truncate_gradient: see scan for more info
:param non_sequences: List of arguments passed to `fn`. ``foldr`` will
not iterate over these arguments (see ``scan`` for
more info).
:param mode: see scan
:param name: see scan
"""
return
reduce
(
fn
=
fn
,
sequences
=
sequences
,
outputs_info
=
outputs_info
,
non_sequences
=
non_sequences
,
go_backwards
=
True
,
mode
=
mode
,
name
=
name
)
# CONSIDER ALTERNATE CALLING CONVENTIONS:
# simple:
# scan(fn, [a,b], [c])
# complex:
# scan(fn, [dict(input=a, taps=[0,-1,-2]), b], [dict(initial=c, taps=[-1,-3], inplace=a)])
#
#
# So for example, if we wanted a scan that took a window of 3 inputs, and produced
# x - a sequence that we need one previous value of, and only need to return the last value;
# y - a sequence that we need no previous values of;
# z - a sequence that we need two previous values of
# and we want z to be computed inplace using the storage of 'a'.
#
# scan(fn, [dict(input=a, taps=[-1,0,1])],
# [dict(initial=x_init, taps=[-1], ????????),
# None
# dict(initial=z_init, taps=[-2,-1], inplace=a,)])
:param mode: See ``scan``.
:param name: See ``scan``.
"""
return
reduce
(
fn
=
fn
,
sequences
=
sequences
,
outputs_info
=
outputs_info
,
non_sequences
=
non_sequences
,
go_backwards
=
True
,
mode
=
mode
,
name
=
name
)
#
# QUESTION:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论