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:
...
@@ -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
that a python exception is set) if your C code needs to
raise an exception.
raise an exception.
``sub['
context
']``
``sub['
params
']``
(optional) The name of the variable which holds the context
(optional) The name of the variable which holds the context
for the node. This will only appear if the op has requested
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.
something other than None.
.. method:: c_code_cleanup(node, name, input_names, output_names, sub)
.. 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:
...
@@ -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
that a python exception is set) if your C code needs to
raise an exception.
raise an exception.
``sub['
context
']``
``sub['
params
']``
(optional) The name of the variable which holds the context
(optional) The name of the variable which holds the context
for the node. This will only appear if the op has requested
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.
something other than None.
.. method:: c_support_code()
.. method:: c_support_code()
...
@@ -223,18 +223,18 @@ There are less methods to define for an Op than for a Type:
...
@@ -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
is high or when theano compilation directory is shared by many
process (like on a network file server on a cluster).
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
(optional) If defined, should return the runtime
params
the op
needs. Th
is context
will be passed to the C code through the
needs. Th
ese parameters
will be passed to the C code through the
variable named in `sub['
context
']`. The variable is also
variable named in `sub['
params
']`. The variable is also
available for use in the code returned by
available for use in the code returned by
:meth:`c_init_code_struct`. If it returns `None` this is
:meth:`c_init_code_struct`. If it returns `None` this is
considered the same as if the method was not defined.
considered the same as if the method was not defined.
If this method is defined and does not return `None`, then the
If this method is defined and does not return `None`, then the
Op *must* have a `
context
_type` property with the Type to use
Op *must* have a `
params
_type` property with the Type to use
for the
context
variable.
for the
params
variable.
.. attribute:: _f16_ok
.. 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
...
@@ -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
You can add a semicolon after the macro if it makes your editor
happy.
happy.
* ``
CONTEXT`` : Name of the context
variable for this node. (only
* ``
PARAMS`` : Name of the params
variable for this node. (only
for Ops which have
a context
, which is discussed elsewhere)
for Ops which have
params
, which is discussed elsewhere)
Finally the tag ``code`` and ``code_cleanup`` have macros to
Finally the tag ``code`` and ``code_cleanup`` have macros to
pass the inputs and output names. These are name ``INPUT_{i}`` and
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):
...
@@ -574,22 +574,22 @@ class CLinker(link.Linker):
self
.
variables
=
[
var
for
var
in
self
.
inputs
if
not
len
(
var
.
clients
)]
self
.
variables
=
[
var
for
var
in
self
.
inputs
if
not
len
(
var
.
clients
)]
self
.
variables
+=
graph
.
variables
(
self
.
inputs
,
self
.
outputs
)
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
# that needs it
self
.
context
s
=
dict
()
self
.
node_param
s
=
dict
()
for
node
in
self
.
node_order
:
for
node
in
self
.
node_order
:
ctx
=
node
.
run_context
()
params
=
node
.
run_params
()
if
ctx
is
not
graph
.
NoContext
:
if
params
is
not
graph
.
NoParams
:
# try to avoid creating more than one variable for the
# try to avoid creating more than one variable for the
# same
context
.
# same
params
.
if
ctx
in
self
.
context
s
:
if
params
in
self
.
node_param
s
:
var
=
self
.
contexts
[
ctx
]
var
=
self
.
node_params
[
params
]
assert
var
.
type
==
node
.
context
_type
assert
var
.
type
==
node
.
params
_type
var
.
clients
.
append
((
node
,
'
context
'
))
var
.
clients
.
append
((
node
,
'
params
'
))
else
:
else
:
var
=
graph
.
Constant
(
node
.
context_type
,
ctx
)
var
=
graph
.
Constant
(
node
.
params_type
,
params
)
var
.
clients
=
[(
node
,
'
context
'
)]
var
.
clients
=
[(
node
,
'
params
'
)]
self
.
contexts
[
ctx
]
=
var
self
.
node_params
[
params
]
=
var
self
.
variables
.
append
(
var
)
self
.
variables
.
append
(
var
)
# The orphans field is listified to ensure a consistent order.
# The orphans field is listified to ensure a consistent order.
...
@@ -732,9 +732,9 @@ class CLinker(link.Linker):
...
@@ -732,9 +732,9 @@ class CLinker(link.Linker):
sub
=
dict
(
failure_var
=
failure_var
)
sub
=
dict
(
failure_var
=
failure_var
)
ctx
=
node
.
run_context
()
params
=
node
.
run_params
()
if
ctx
is
not
graph
.
NoContext
:
if
params
is
not
graph
.
NoParams
:
context_var
=
symbol
[
self
.
contexts
[
ctx
]]
params_var
=
symbol
[
self
.
node_params
[
params
]]
# The placeholder will be replaced by a hash of the entire
# The placeholder will be replaced by a hash of the entire
# code (module + support code) in DynamicModule.code.
# code (module + support code) in DynamicModule.code.
...
@@ -750,16 +750,16 @@ class CLinker(link.Linker):
...
@@ -750,16 +750,16 @@ class CLinker(link.Linker):
# Make the CodeBlock for c_code
# Make the CodeBlock for c_code
sub
[
'id'
]
=
id
sub
[
'id'
]
=
id
sub
[
'fail'
]
=
failure_code
(
sub
)
sub
[
'fail'
]
=
failure_code
(
sub
)
if
ctx
is
not
graph
.
NoContext
:
if
params
is
not
graph
.
NoParams
:
sub
[
'
context'
]
=
context
_var
sub
[
'
params'
]
=
params
_var
sub_struct
=
dict
()
sub_struct
=
dict
()
sub_struct
[
'id'
]
=
id
+
1
sub_struct
[
'id'
]
=
id
+
1
sub_struct
[
'fail'
]
=
failure_code_init
(
sub
)
sub_struct
[
'fail'
]
=
failure_code_init
(
sub
)
if
ctx
is
not
graph
.
NoContext
:
if
params
is
not
graph
.
NoParams
:
# Since
context
inputs are always constants they are
# Since
params
inputs are always constants they are
# guaranteed to be available in the struct init code.
# guaranteed to be available in the struct init code.
sub_struct
[
'
context'
]
=
context
_var
sub_struct
[
'
params'
]
=
params
_var
struct_support
=
""
struct_support
=
""
struct_init
=
""
struct_init
=
""
...
...
theano/gof/graph.py
浏览文件 @
51c981b0
...
@@ -22,7 +22,7 @@ __docformat__ = "restructuredtext en"
...
@@ -22,7 +22,7 @@ __docformat__ = "restructuredtext en"
is_same_graph_with_merge
=
None
is_same_graph_with_merge
=
None
equal_computations
=
None
equal_computations
=
None
No
Context
=
object
()
No
Params
=
object
()
class
Node
(
utils
.
object2
):
class
Node
(
utils
.
object2
):
...
@@ -123,14 +123,14 @@ class Apply(Node):
...
@@ -123,14 +123,14 @@ class Apply(Node):
else
:
else
:
raise
TypeError
(
"The 'outputs' argument to Apply must contain Variable instances with no owner, not
%
s"
%
output
)
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
'
):
if
hasattr
(
self
.
op
,
'get_
params
'
):
return
self
.
op
.
get_
context
(
self
)
return
self
.
op
.
get_
params
(
self
)
return
No
Context
return
No
Params
def
default_output
(
self
):
def
default_output
(
self
):
"""
"""
...
@@ -253,7 +253,7 @@ class Apply(Node):
...
@@ -253,7 +253,7 @@ class Apply(Node):
Property: Number of outputs.
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
):
class
Variable
(
Node
):
...
...
theano/gof/op.py
浏览文件 @
51c981b0
...
@@ -857,9 +857,9 @@ class Op(utils.object2, PureOp, CLinkerOp):
...
@@ -857,9 +857,9 @@ class Op(utils.object2, PureOp, CLinkerOp):
p
=
node
.
op
.
perform
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`
# default arguments are stored in the closure of `rval`
def
rval
(
p
=
p
,
i
=
node_input_storage
,
o
=
node_output_storage
,
n
=
node
):
def
rval
(
p
=
p
,
i
=
node_input_storage
,
o
=
node_output_storage
,
n
=
node
):
r
=
p
(
n
,
[
x
[
0
]
for
x
in
i
],
o
)
r
=
p
(
n
,
[
x
[
0
]
for
x
in
i
],
o
)
...
@@ -867,11 +867,11 @@ class Op(utils.object2, PureOp, CLinkerOp):
...
@@ -867,11 +867,11 @@ class Op(utils.object2, PureOp, CLinkerOp):
compute_map
[
o
][
0
]
=
True
compute_map
[
o
][
0
]
=
True
return
r
return
r
else
:
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
,
def
rval
(
p
=
p
,
i
=
node_input_storage
,
o
=
node_output_storage
,
n
=
node
,
ctx
=
ctx
_val
):
params
=
params
_val
):
r
=
p
(
n
,
[
x
[
0
]
for
x
in
i
],
o
,
ctx
)
r
=
p
(
n
,
[
x
[
0
]
for
x
in
i
],
o
,
params
)
for
o
in
node
.
outputs
:
for
o
in
node
.
outputs
:
compute_map
[
o
][
0
]
=
True
compute_map
[
o
][
0
]
=
True
return
r
return
r
...
@@ -1403,9 +1403,9 @@ class COp(Op):
...
@@ -1403,9 +1403,9 @@ class COp(Op):
define_macros
.
append
(
"#define FAIL
%
s"
%
(
define_macros
.
append
(
"#define FAIL
%
s"
%
(
self
.
_lquote_macro
(
sub
[
'fail'
]),))
self
.
_lquote_macro
(
sub
[
'fail'
]),))
undef_macros
.
append
(
"#undef FAIL"
)
undef_macros
.
append
(
"#undef FAIL"
)
if
'
context
'
in
sub
:
if
'
params
'
in
sub
:
define_macros
.
append
(
"#define
CONTEXT
%
s"
%
(
sub
[
'context
'
],))
define_macros
.
append
(
"#define
PARAMS
%
s"
%
(
sub
[
'params
'
],))
undef_macros
.
append
(
"#undef
CONTEXT
"
)
undef_macros
.
append
(
"#undef
PARAMS
"
)
return
os
.
linesep
.
join
(
define_macros
),
os
.
linesep
.
join
(
undef_macros
)
return
os
.
linesep
.
join
(
define_macros
),
os
.
linesep
.
join
(
undef_macros
)
...
@@ -1442,21 +1442,21 @@ class COp(Op):
...
@@ -1442,21 +1442,21 @@ class COp(Op):
define_macros
,
undef_macros
=
self
.
get_c_macros
(
node
,
name
,
define_macros
,
undef_macros
=
self
.
get_c_macros
(
node
,
name
,
check_input
=
False
)
check_input
=
False
)
ctx
=
""
params
=
""
if
'
context
'
in
sub
:
if
'
params
'
in
sub
:
ctx
=
",
%
s"
%
(
sub
[
'context
'
],)
params
=
",
%
s"
%
(
sub
[
'params
'
],)
# Generate the C code
# Generate the C code
return
"""
return
"""
%(define_macros)
s
%(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
%(fail)
s
}
}
}
}
%(undef_macros)
s
%(undef_macros)
s
"""
%
dict
(
func_name
=
self
.
func_name
,
"""
%
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
),
func_args
=
self
.
format_c_function_args
(
inp
,
out
),
define_macros
=
define_macros
,
define_macros
=
define_macros
,
undef_macros
=
undef_macros
)
undef_macros
=
undef_macros
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论