Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
51c981b0
提交
51c981b0
authored
10月 26, 2015
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename context to params.
上级
8d3a67b7
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
52 行增加
和
52 行删除
+52
-52
cop.txt
doc/extending/cop.txt
+10
-10
extending_theano_c.txt
doc/tutorial/extending_theano_c.txt
+2
-2
cc.py
theano/gof/cc.py
+20
-20
graph.py
theano/gof/graph.py
+7
-7
op.py
theano/gof/op.py
+13
-13
没有找到文件。
doc/extending/cop.txt
浏览文件 @
51c981b0
...
...
@@ -43,11 +43,11 @@ There are less methods to define for an Op than for a Type:
that a python exception is set) if your C code needs to
raise an exception.
``sub['
context
']``
``sub['
params
']``
(optional) The name of the variable which holds the context
for the node. This will only appear if the op has requested
a context by having a :meth:`get_
context
()` method that return
a context by having a :meth:`get_
params
()` method that return
something other than None.
.. method:: c_code_cleanup(node, name, input_names, output_names, sub)
...
...
@@ -142,11 +142,11 @@ There are less methods to define for an Op than for a Type:
that a python exception is set) if your C code needs to
raise an exception.
``sub['
context
']``
``sub['
params
']``
(optional) The name of the variable which holds the context
for the node. This will only appear if the op has requested
a context by having a :meth:`get_
context
()` method that return
a context by having a :meth:`get_
params
()` method that return
something other than None.
.. method:: c_support_code()
...
...
@@ -223,18 +223,18 @@ There are less methods to define for an Op than for a Type:
is high or when theano compilation directory is shared by many
process (like on a network file server on a cluster).
.. method:: get_
context
(node)
.. method:: get_
params
(node)
(optional) If defined, should return the runtime
context
the op
needs. Th
is context
will be passed to the C code through the
variable named in `sub['
context
']`. The variable is also
(optional) If defined, should return the runtime
params
the op
needs. Th
ese parameters
will be passed to the C code through the
variable named in `sub['
params
']`. The variable is also
available for use in the code returned by
:meth:`c_init_code_struct`. If it returns `None` this is
considered the same as if the method was not defined.
If this method is defined and does not return `None`, then the
Op *must* have a `
context
_type` property with the Type to use
for the
context
variable.
Op *must* have a `
params
_type` property with the Type to use
for the
params
variable.
.. attribute:: _f16_ok
...
...
doc/tutorial/extending_theano_c.txt
浏览文件 @
51c981b0
...
...
@@ -924,8 +924,8 @@ In addition to these macros, the ``init_code_struct``, ``code``, and
You can add a semicolon after the macro if it makes your editor
happy.
* ``
CONTEXT`` : Name of the context
variable for this node. (only
for Ops which have
a context
, which is discussed elsewhere)
* ``
PARAMS`` : Name of the params
variable for this node. (only
for Ops which have
params
, which is discussed elsewhere)
Finally the tag ``code`` and ``code_cleanup`` have macros to
pass the inputs and output names. These are name ``INPUT_{i}`` and
...
...
theano/gof/cc.py
浏览文件 @
51c981b0
...
...
@@ -574,22 +574,22 @@ class CLinker(link.Linker):
self
.
variables
=
[
var
for
var
in
self
.
inputs
if
not
len
(
var
.
clients
)]
self
.
variables
+=
graph
.
variables
(
self
.
inputs
,
self
.
outputs
)
# This adds a hidden input which is the
context
for each node
# This adds a hidden input which is the
params
for each node
# that needs it
self
.
context
s
=
dict
()
self
.
node_param
s
=
dict
()
for
node
in
self
.
node_order
:
ctx
=
node
.
run_context
()
if
ctx
is
not
graph
.
NoContext
:
params
=
node
.
run_params
()
if
params
is
not
graph
.
NoParams
:
# try to avoid creating more than one variable for the
# same
context
.
if
ctx
in
self
.
context
s
:
var
=
self
.
contexts
[
ctx
]
assert
var
.
type
==
node
.
context
_type
var
.
clients
.
append
((
node
,
'
context
'
))
# same
params
.
if
params
in
self
.
node_param
s
:
var
=
self
.
node_params
[
params
]
assert
var
.
type
==
node
.
params
_type
var
.
clients
.
append
((
node
,
'
params
'
))
else
:
var
=
graph
.
Constant
(
node
.
context_type
,
ctx
)
var
.
clients
=
[(
node
,
'
context
'
)]
self
.
contexts
[
ctx
]
=
var
var
=
graph
.
Constant
(
node
.
params_type
,
params
)
var
.
clients
=
[(
node
,
'
params
'
)]
self
.
node_params
[
params
]
=
var
self
.
variables
.
append
(
var
)
# The orphans field is listified to ensure a consistent order.
...
...
@@ -732,9 +732,9 @@ class CLinker(link.Linker):
sub
=
dict
(
failure_var
=
failure_var
)
ctx
=
node
.
run_context
()
if
ctx
is
not
graph
.
NoContext
:
context_var
=
symbol
[
self
.
contexts
[
ctx
]]
params
=
node
.
run_params
()
if
params
is
not
graph
.
NoParams
:
params_var
=
symbol
[
self
.
node_params
[
params
]]
# The placeholder will be replaced by a hash of the entire
# code (module + support code) in DynamicModule.code.
...
...
@@ -750,16 +750,16 @@ class CLinker(link.Linker):
# Make the CodeBlock for c_code
sub
[
'id'
]
=
id
sub
[
'fail'
]
=
failure_code
(
sub
)
if
ctx
is
not
graph
.
NoContext
:
sub
[
'
context'
]
=
context
_var
if
params
is
not
graph
.
NoParams
:
sub
[
'
params'
]
=
params
_var
sub_struct
=
dict
()
sub_struct
[
'id'
]
=
id
+
1
sub_struct
[
'fail'
]
=
failure_code_init
(
sub
)
if
ctx
is
not
graph
.
NoContext
:
# Since
context
inputs are always constants they are
if
params
is
not
graph
.
NoParams
:
# Since
params
inputs are always constants they are
# guaranteed to be available in the struct init code.
sub_struct
[
'
context'
]
=
context
_var
sub_struct
[
'
params'
]
=
params
_var
struct_support
=
""
struct_init
=
""
...
...
theano/gof/graph.py
浏览文件 @
51c981b0
...
...
@@ -22,7 +22,7 @@ __docformat__ = "restructuredtext en"
is_same_graph_with_merge
=
None
equal_computations
=
None
No
Context
=
object
()
No
Params
=
object
()
class
Node
(
utils
.
object2
):
...
...
@@ -123,14 +123,14 @@ class Apply(Node):
else
:
raise
TypeError
(
"The 'outputs' argument to Apply must contain Variable instances with no owner, not
%
s"
%
output
)
def
run_
context
(
self
):
def
run_
params
(
self
):
"""
Returns the
context for the node, or NoContext if no context
is set.
Returns the
params for the node, or NoParams if no params
is set.
"""
if
hasattr
(
self
.
op
,
'get_
context
'
):
return
self
.
op
.
get_
context
(
self
)
return
No
Context
if
hasattr
(
self
.
op
,
'get_
params
'
):
return
self
.
op
.
get_
params
(
self
)
return
No
Params
def
default_output
(
self
):
"""
...
...
@@ -253,7 +253,7 @@ class Apply(Node):
Property: Number of outputs.
"""
context_type
=
property
(
lambda
self
:
self
.
op
.
context_type
,
doc
=
'type to use for the context
'
)
params_type
=
property
(
lambda
self
:
self
.
op
.
params_type
,
doc
=
'type to use for the params
'
)
class
Variable
(
Node
):
...
...
theano/gof/op.py
浏览文件 @
51c981b0
...
...
@@ -857,9 +857,9 @@ class Op(utils.object2, PureOp, CLinkerOp):
p
=
node
.
op
.
perform
ctx
=
node
.
run_context
()
params
=
node
.
run_params
()
if
ctx
is
graph
.
NoContext
:
if
params
is
graph
.
NoParams
:
# default arguments are stored in the closure of `rval`
def
rval
(
p
=
p
,
i
=
node_input_storage
,
o
=
node_output_storage
,
n
=
node
):
r
=
p
(
n
,
[
x
[
0
]
for
x
in
i
],
o
)
...
...
@@ -867,11 +867,11 @@ class Op(utils.object2, PureOp, CLinkerOp):
compute_map
[
o
][
0
]
=
True
return
r
else
:
ctx_val
=
node
.
context_type
.
filter
(
ctx
)
params_val
=
node
.
params_type
.
filter
(
params
)
def
rval
(
p
=
p
,
i
=
node_input_storage
,
o
=
node_output_storage
,
n
=
node
,
ctx
=
ctx
_val
):
r
=
p
(
n
,
[
x
[
0
]
for
x
in
i
],
o
,
ctx
)
params
=
params
_val
):
r
=
p
(
n
,
[
x
[
0
]
for
x
in
i
],
o
,
params
)
for
o
in
node
.
outputs
:
compute_map
[
o
][
0
]
=
True
return
r
...
...
@@ -1403,9 +1403,9 @@ class COp(Op):
define_macros
.
append
(
"#define FAIL
%
s"
%
(
self
.
_lquote_macro
(
sub
[
'fail'
]),))
undef_macros
.
append
(
"#undef FAIL"
)
if
'
context
'
in
sub
:
define_macros
.
append
(
"#define
CONTEXT
%
s"
%
(
sub
[
'context
'
],))
undef_macros
.
append
(
"#undef
CONTEXT
"
)
if
'
params
'
in
sub
:
define_macros
.
append
(
"#define
PARAMS
%
s"
%
(
sub
[
'params
'
],))
undef_macros
.
append
(
"#undef
PARAMS
"
)
return
os
.
linesep
.
join
(
define_macros
),
os
.
linesep
.
join
(
undef_macros
)
...
...
@@ -1442,21 +1442,21 @@ class COp(Op):
define_macros
,
undef_macros
=
self
.
get_c_macros
(
node
,
name
,
check_input
=
False
)
ctx
=
""
if
'
context
'
in
sub
:
ctx
=
",
%
s"
%
(
sub
[
'context
'
],)
params
=
""
if
'
params
'
in
sub
:
params
=
",
%
s"
%
(
sub
[
'params
'
],)
# Generate the C code
return
"""
%(define_macros)
s
{
if (
%(func_name)
s(
%(func_args)
s
%(
ctx
)
s) != 0) {
if (
%(func_name)
s(
%(func_args)
s
%(
params
)
s) != 0) {
%(fail)
s
}
}
%(undef_macros)
s
"""
%
dict
(
func_name
=
self
.
func_name
,
fail
=
sub
[
'fail'
],
ctx
=
ctx
,
fail
=
sub
[
'fail'
],
params
=
params
,
func_args
=
self
.
format_c_function_args
(
inp
,
out
),
define_macros
=
define_macros
,
undef_macros
=
undef_macros
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论