Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cdddc7da
提交
cdddc7da
authored
8月 14, 2015
作者:
Iban Harlouchet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
numpydoc for theano/compile/mode.py
上级
3ca1e9ab
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
40 行增加
和
22 行删除
+40
-22
mode.py
theano/compile/mode.py
+40
-22
没有找到文件。
theano/compile/mode.py
浏览文件 @
cdddc7da
"""WRITEME
"""
WRITEME
"""
"""
from
__future__
import
print_function
from
__future__
import
print_function
import
logging
import
logging
...
@@ -34,8 +36,9 @@ AddConfigVar('optimizer_requiring',
...
@@ -34,8 +36,9 @@ AddConfigVar('optimizer_requiring',
def
check_equal
(
x
,
y
):
def
check_equal
(
x
,
y
):
"""
"""
Returns True iff x[0] and y[0] are equal (checks the dtype and
Returns True iff x[0] and y[0] are equal (checks the dtype and shape if x
shape if x and y are numpy.ndarray instances). Used internally.
and y are numpy.ndarray instances). Used internally.
"""
"""
# I put the import here to allow using theano without scipy.
# I put the import here to allow using theano without scipy.
import
scipy.sparse
as
sp
import
scipy.sparse
as
sp
...
@@ -125,17 +128,19 @@ def register_optimizer(name, opt):
...
@@ -125,17 +128,19 @@ def register_optimizer(name, opt):
class
AddDestroyHandler
(
gof
.
Optimizer
):
class
AddDestroyHandler
(
gof
.
Optimizer
):
"""This optimizer performs two important functions:
"""
This optimizer performs two important functions:
1) It has a 'requirement' of the destroyhandler. This means that the fgraph
1) It has a 'requirement' of the destroyhandler. This means that the fgraph
will include it as a feature for this optimization, and keep this feature
will include it as a feature for this optimization, and keep this feature
enabled for subsequent optimizations.
All optimizations that work inplace
enabled for subsequent optimizations. All optimizations that work inplace
on any of their inputs must run *after* this optimization to ensure that
on any of their inputs must run *after* this optimization to ensure that
the DestroyHandler has been included in the fgraph.
the DestroyHandler has been included in the fgraph.
2) It tries to replace each output with an Op that purports to destroy it
2) It tries to replace each output with an Op that purports to destroy it
(but it won't I promise). If this replacement succeeds it means that
(but it won't I promise). If this replacement succeeds it means that
there is a bug in theano. It should not be possible to destroy outputs.
there is a bug in theano. It should not be possible to destroy outputs.
"""
"""
def
apply
(
self
,
fgraph
):
def
apply
(
self
,
fgraph
):
for
o
in
fgraph
.
outputs
:
for
o
in
fgraph
.
outputs
:
...
@@ -157,11 +162,13 @@ class AddDestroyHandler(gof.Optimizer):
...
@@ -157,11 +162,13 @@ class AddDestroyHandler(gof.Optimizer):
class
AddNoOutputFromInplace
(
gof
.
Optimizer
):
class
AddNoOutputFromInplace
(
gof
.
Optimizer
):
"""This optimizer adds to the fgraph a feature that will prevent outputs
"""
This optimizer adds to the fgraph a feature that will prevent outputs
of a fgraph to be created by performing inplace operations on intermediary
of a fgraph to be created by performing inplace operations on intermediary
variables. This is useful when the outputs of the fgraph are preallocated
variables. This is useful when the outputs of the fgraph are preallocated
to prevent useless copying of the data. Currently, scan preallocates its
to prevent useless copying of the data. Currently, scan preallocates its
outputs
outputs
"""
"""
def
add_requirements
(
self
,
fgraph
):
def
add_requirements
(
self
,
fgraph
):
super
(
AddNoOutputFromInplace
,
self
)
.
add_requirements
(
fgraph
)
super
(
AddNoOutputFromInplace
,
self
)
.
add_requirements
(
fgraph
)
...
@@ -169,10 +176,12 @@ class AddNoOutputFromInplace(gof.Optimizer):
...
@@ -169,10 +176,12 @@ class AddNoOutputFromInplace(gof.Optimizer):
class
PrintCurrentFunctionGraph
(
gof
.
Optimizer
):
class
PrintCurrentFunctionGraph
(
gof
.
Optimizer
):
"""This optimizer is for debugging.
"""
This optimizer is for debugging.
Toss it into the optimization pipeline to see the state of things at any
Toss it into the optimization pipeline to see the state of things at any
given point.
given point.
"""
"""
def
__init__
(
self
,
header
):
def
__init__
(
self
,
header
):
self
.
header
=
header
self
.
header
=
header
...
@@ -233,18 +242,23 @@ optdb.register('merge3', gof.MergeOptimizer(),
...
@@ -233,18 +242,23 @@ optdb.register('merge3', gof.MergeOptimizer(),
class
Mode
(
object
):
class
Mode
(
object
):
"""
"""
The Mode represents a way to optimize and then link a computation
The Mode represents a way to optimize and then link a computation graph.
graph.
Parameters
* optimizer -> a structure of type Optimizer. An Optimizer may
----------
simplify the math, put similar computations together, improve
optimizer : a structure of type Optimizer
numerical stability and various other improvements.
An Optimizer may simplify the math, put similar computations together,
* linker -> a structure of type Linker. A Linker decides which
improve numerical stability and various other improvements.
implementations to use (C or Python, for example) and how to
linker : a structure of type Linker
string them together to perform the computation.
A Linker decides which implementations to use (C or Python, for example)
and how to string them together to perform the computation.
See predefined_linkers, predefined_optimizers and also
predefined_modes.
See Also
--------
predefined_linkers
predefined_optimizers
predefined_modes
"""
"""
def
__init__
(
self
,
linker
=
None
,
optimizer
=
'default'
):
def
__init__
(
self
,
linker
=
None
,
optimizer
=
'default'
):
...
@@ -326,6 +340,7 @@ class Mode(object):
...
@@ -326,6 +340,7 @@ class Mode(object):
Keyword arguments can be provided for the linker,
Keyword arguments can be provided for the linker,
in which case its `clone` method will be called with these
in which case its `clone` method will be called with these
arguments.
arguments.
"""
"""
new_linker
=
self
.
linker
.
clone
(
**
link_kwargs
)
new_linker
=
self
.
linker
.
clone
(
**
link_kwargs
)
new_optimizer
=
self
.
provided_optimizer
new_optimizer
=
self
.
provided_optimizer
...
@@ -412,7 +427,10 @@ def get_default_mode():
...
@@ -412,7 +427,10 @@ def get_default_mode():
def
register_mode
(
name
,
mode
):
def
register_mode
(
name
,
mode
):
"""Add a `Mode` which can be referred to by `name` in `function`."""
"""
Add a `Mode` which can be referred to by `name` in `function`.
"""
if
name
in
predefined_modes
:
if
name
in
predefined_modes
:
raise
ValueError
(
'Mode name already taken:
%
s'
%
name
)
raise
ValueError
(
'Mode name already taken:
%
s'
%
name
)
predefined_modes
[
name
]
=
mode
predefined_modes
[
name
]
=
mode
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论