Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8129b741
提交
8129b741
authored
8月 14, 2015
作者:
Iban Harlouchet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
numpydoc for theano/compile/pfunc.py
上级
8feaa75a
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
132 行增加
和
142 行删除
+132
-142
pfunc.py
theano/compile/pfunc.py
+132
-142
没有找到文件。
theano/compile/pfunc.py
浏览文件 @
8129b741
"""Provide a simple user friendly API """
"""
Provide a simple user friendly API.
"""
from
theano
import
config
from
theano
import
config
from
six
import
iteritems
from
six
import
iteritems
from
theano.compile
import
orig_function
,
In
,
Out
from
theano.compile
import
orig_function
,
In
,
Out
...
@@ -22,41 +25,34 @@ def rebuild_collect_shared(outputs,
...
@@ -22,41 +25,34 @@ def rebuild_collect_shared(outputs,
no_default_updates
=
False
,
no_default_updates
=
False
,
):
):
"""
"""
Function that allows replacing subgraphs of a computational
Function that allows replacing subgraphs of a computational graph.
graph.
It returns a set of dictionaries and lists which collect (partial?)
It returns a set of dictionaries and lists which collect (partial?)
different information about shared variables. This info is required by
different information about shared variables. This info is required by
`pfunc`.
`pfunc`.
Parameters
:type outputs: list of Theano Variables ( or Theano expressions)
----------
:param outputs: list of Theano variables or expressions representing the
outputs : list of Theano Variables (or Theano expressions)
outputs of the computational graph
List of Theano variables or expressions representing the outputs of the
computational graph.
:type inputs: list of Theano Variables ( or Theano expressions)
inputs : list of Theano Variables (or Theano expressions)
:param inputs: list of Theano variables or expressions representing the
List of Theano variables or expressions representing the inputs of the
inputs of the computational graph (or None)
computational graph (or None).
:type replace: dict
replace : dict
:param replace: dictionary describing which subgraphs should be
Dictionary describing which subgraphs should be replaced by what.
replaced by what. orig_value => new_value
orig_value => new_value
updates : dict
:type updates: dict
Dictionary describing updates expressions for shared variables.
:param updates: dictionary describing updates expressions for shared
rebuild_strict : bool
variables
Flag, if true the type of all inputs should be the same as the one for
the current node.
:type rebuild_strict: bool
copy_inputs_over : bool
:param rebuild_strict: flag, if true the type of all inputs should be
Flag; if False it will clone inputs.
the same as the for the current node
no_default_updates : either bool or list of Variables
If True, do not perform any automatic update on Variables.
:type copy_inputs_over: bool
If False (default), perform them all.
:param copy_inputs_over: flag; if False it will clone inputs
Else, perform automatic updates on all Variables that are neither in
:type no_default_updates: either bool or list of Variables
:param no_default_updates: if True, do not perform any automatic update
on Variables. If False (default), perform
them all. Else, perform automatic updates
on all Variables that are neither in
"updates" nor in "no_default_updates".
"updates" nor in "no_default_updates".
"""
"""
...
@@ -73,15 +69,15 @@ def rebuild_collect_shared(outputs,
...
@@ -73,15 +69,15 @@ def rebuild_collect_shared(outputs,
shared_inputs
=
[]
shared_inputs
=
[]
def
clone_v_get_shared_updates
(
v
,
copy_inputs_over
):
def
clone_v_get_shared_updates
(
v
,
copy_inputs_over
):
'''
"""
Clones a variable and its inputs recursively until all are in
Clones a variable and its inputs recursively until all are in clone_d.
clone_d. Also appends all shared variables met along the way to
Also appends all shared variables met along the way to shared inputs,
shared inputs, and their default_update (if applicable) to update_d
and their default_update (if applicable) to update_d and update_expr.
and update_expr.
v can have an fgraph attached to it, case in which we want to clone
v can have an fgraph attached to it, case in which we want to clone
constants ( to avoid having a constant belonging to two fgraphs)
constants (to avoid having a constant belonging to two fgraphs).
'''
"""
# this co-recurses with clone_a
# this co-recurses with clone_a
assert
v
is
not
None
assert
v
is
not
None
if
v
in
clone_d
:
if
v
in
clone_d
:
...
@@ -119,10 +115,11 @@ def rebuild_collect_shared(outputs,
...
@@ -119,10 +115,11 @@ def rebuild_collect_shared(outputs,
return
clone_d
.
setdefault
(
v
,
v
)
return
clone_d
.
setdefault
(
v
,
v
)
def
clone_a
(
a
,
copy_inputs_over
):
def
clone_a
(
a
,
copy_inputs_over
):
'''
"""
Clones a variable and its inputs recursively until all are in
Clones a variable and its inputs recursively until all are in
clone_d. It occures with clone_v_get_shared_updates
clone_d. It occures with clone_v_get_shared_updates.
'''
"""
if
a
is
None
:
if
a
is
None
:
return
None
return
None
if
a
not
in
clone_d
:
if
a
not
in
clone_d
:
...
@@ -275,40 +272,43 @@ def rebuild_collect_shared(outputs,
...
@@ -275,40 +272,43 @@ def rebuild_collect_shared(outputs,
class
Param
(
object
):
class
Param
(
object
):
def
__init__
(
self
,
variable
,
default
=
None
,
name
=
None
,
mutable
=
False
,
strict
=
False
,
allow_downcast
=
None
,
implicit
=
None
,
borrow
=
None
):
"""
"""
:param variable: A variable in an expression graph to use as a
compiled-function parameter
:param default: The default value to use at call-time (can
Parameters
also be a Container where the function will find a value
----------
at call-time.)
variable
A variable in an expression graph to use as a compiled-function
:param name: A string to identify this parameter from function kwargs.
parameter.
default
:param mutable: True -> function is allowed to modify this argument.
The default value to use at call-time (can also be a Container where
the function will find a value at call-time).
:param borrow: Whether the function is allowed to alias some
name : str
output to this input. Using None (default) means we re-use
A string to identify this parameter from function kwargs.
the same value as the `mutable` flag.
mutable : bool
False: do not permit any output to be aliased to the input
True : function is allowed to modify this argument.
borrow
:param strict: False -> function arguments may be copied or
Whether the function is allowed to alias some output to this input.
cast to match the type required by the parameter
Using None (default) means we re-use the same value as the `mutable`
flag. False: do not permit any output to be aliased to the input.
strict : bool
False : function arguments may be copied or cast to match the type
required by the parameter `variable`.
True : function arguments must exactly match the type required by
`variable`.
`variable`.
True -> function arguments must exactly match the typ
e
allow_downcast : bool or Non
e
required by `variable`
.
Only applies if `strict` is False
.
True : allow assigned value to lose precision when cast during
:param allow_downcast: Only applies if `strict` is False
.
assignment
.
True -> allow assigned value to lose precision when cast
False : never allow precision loss.
during assignment
.
None : only allow downcasting of a Python float to a scalar floatX
.
False -> never allow precision loss.
implicit
None -> only allow downcasting of a Python float to a scalar floatX.
See help(theano.io.In)
:param implicit: see help(theano.io.In)
"""
"""
def
__init__
(
self
,
variable
,
default
=
None
,
name
=
None
,
mutable
=
False
,
strict
=
False
,
allow_downcast
=
None
,
implicit
=
None
,
borrow
=
None
):
self
.
variable
=
variable
self
.
variable
=
variable
self
.
default
=
default
self
.
default
=
default
self
.
name
=
name
self
.
name
=
name
...
@@ -340,75 +340,61 @@ def pfunc(params, outputs=None, mode=None, updates=None, givens=None,
...
@@ -340,75 +340,61 @@ def pfunc(params, outputs=None, mode=None, updates=None, givens=None,
no_default_updates
=
False
,
accept_inplace
=
False
,
name
=
None
,
no_default_updates
=
False
,
accept_inplace
=
False
,
name
=
None
,
rebuild_strict
=
True
,
allow_input_downcast
=
None
,
rebuild_strict
=
True
,
allow_input_downcast
=
None
,
profile
=
None
,
on_unused_input
=
None
,
output_keys
=
None
):
profile
=
None
,
on_unused_input
=
None
,
output_keys
=
None
):
"""Function-constructor for graphs with shared variables.
"""
Function-constructor for graphs with shared variables.
:type params: list of either Variable or Param instances.
:param params: function parameters, these are not allowed to be shared
Parameters
variables
----------
params : list of either Variable or Param instances
:type outputs: list of Variables or Out instances
Function parameters, these are not allowed to be shared variables.
:param outputs: expressions to compute
outputs : list of Variables or Out instances
Expressions to compute.
:type mode: string or `theano.compile.Mode` instance.
mode : string or `theano.compile.Mode` instance
:param mode: compilation mode
Compilation mode.
updates : iterable over pairs (shared_variable, new_expression). List, tuple or dict.
:type updates: iterable over pairs (shared_variable,
Update the values for SharedVariable inputs according to these
new_expression). List, tuple or dict.
expressions
:param updates: update the values for SharedVariable inputs
givens : iterable over pairs (Var1, Var2) of Variables. List, tuple or dict.
according to these expressions
The Var1 and Var2 in each pair must have the same Type. Specific
substitutions to make in the computation graph (Var2 replaces Var1).
:type givens: iterable over pairs (Var1, Var2) of Variables. List,
no_default_updates : either bool or list of Variables
tuple or dict. The Var1 and Var2 in each pair must have the
If True, do not perform any automatic update on Variables.
same Type.
If False (default), perform them all. Else, perform automatic updates
on all Variables that are neither in "updates" nor in
:param givens: specific substitutions to make in the computation
"no_default_updates".
graph (Var2 replaces Var1).
name : None or string
Attaches a name to the profiling result of this function.
:type no_default_updates: either bool or list of Variables
allow_input_downcast : bool
:param no_default_updates: if True, do not perform any automatic
True means that the values passed as inputs when calling the function
update on Variables. If False (default), perform them
can be silently downcasted to fit the dtype of the corresponding
all. Else, perform automatic updates on all Variables that are
Variable, which may lose precision. False means that it will only be cast to a more
neither in "updates" nor in "no_default_updates".
:type name: None or string
:param name: attaches a name to the profiling result of this function.
:type allow_input_downcast: Boolean
:param allow_input_downcast: True means that the values passed as
inputs when calling the function can be silently downcasted to
fit the dtype of the corresponding Variable, which may lose
precision. False means that it will only be cast to a more
general, or precise, type. None (default) is almost like
general, or precise, type. None (default) is almost like
False, but allows downcasting of Python float scalars to
False, but allows downcasting of Python float scalars to
floatX.
floatX.
profile : None, True, str, or ProfileStats instance
:type profile: None, True, str, or ProfileStats instance
Accumulate profiling information into a given ProfileStats instance.
:param profile: accumulate profiling information into a given ProfileStats
None is the default, and means to use the value of config.profile.
instance. None is the default, and means to use the value of
If argument is `True` then a new ProfileStats instance will be used.
config.profile.
If argument is a string, a new ProfileStats instance will be created
If argument is `True` then a new ProfileStats instance will be
with that string as its `message` attribute. This profiling object will
used. If argument is a string, a new ProfileStats instance will be created
be available via self.profile.
with that string as its `message` attribute. This profiling object will be
on_unused_input : {'raise', 'warn','ignore', None}
available via self.profile.
What to do if a variable in the 'inputs' list is not used in the graph.
:type on_unused_input: str
Returns
:param on_unused_input: What to do if a variable in the 'inputs' list
-------
is not used in the graph. Possible values are 'raise', 'warn',
theano.compile.Function
'ignore' and None.
A callable object that will compute the outputs (given the inputs) and
update the implicit function arguments according to the `updates`.
:rtype: theano.compile.Function
Notes
:returns: a callable object that will compute the outputs (given
-----
the inputs) and update the implicit function arguments
Regarding givens: Be careful to make sure that these substitutions are
according to the `updates`.
independent--behaviour when Var1 of one pair appears in the graph leading
to Var2 in another expression is undefined. Replacements specified with
givens are different from optimizations in that Var2 is not expected to be
:note: Regarding givens: Be careful to make sure that these
substitutions are independent--behaviour when Var1 of one pair
appears in the graph leading to Var2 in another expression is
undefined. Replacements specified with givens are different
from optimizations in that Var2 is not expected to be
equivalent to Var1.
equivalent to Var1.
"""
"""
#
#
# This function works by cloning the graph (except for the
# This function works by cloning the graph (except for the
...
@@ -547,13 +533,17 @@ def iter_over_pairs(pairs):
...
@@ -547,13 +533,17 @@ def iter_over_pairs(pairs):
"""
"""
Return an iterator over pairs present in the 'pairs' input.
Return an iterator over pairs present in the 'pairs' input.
:type pairs: dictionary or iterable
Parameters
:param pairs: The pairs to iterate upon. These may be stored either as
----------
(key, value) items in a dictionary, or directly as pairs in any kind of
pairs : dictionary or iterable
iterable structure
The pairs to iterate upon. These may be stored either as (key, value)
items in a dictionary, or directly as pairs in any kind of iterable
:rtype: iterable
structure.
:returns: an iterable yielding pairs
Returns
-------
iterable
An iterable yielding pairs.
"""
"""
if
isinstance
(
pairs
,
dict
):
if
isinstance
(
pairs
,
dict
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论