Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0d04e12b
提交
0d04e12b
authored
12月 15, 2014
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove struct_id and use the node name.
It is suitably unique and, more importantly, shared with the rest of the methods.
上级
7d70c3a4
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
29 行增加
和
47 行删除
+29
-47
cop.txt
doc/extending/cop.txt
+7
-19
cc.py
theano/gof/cc.py
+3
-4
graph.py
theano/gof/graph.py
+2
-1
op.py
theano/gof/op.py
+9
-15
test_op.py
theano/gof/tests/test_op.py
+8
-8
没有找到文件。
doc/extending/cop.txt
浏览文件 @
0d04e12b
...
...
@@ -43,9 +43,6 @@ 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['struct_id']``
The integer id passed to the various _struct methods.
.. method:: c_code_cleanup(node, name, input_names, output_names, sub)
...
...
@@ -99,15 +96,12 @@ There are less methods to define for an Op than for a Type:
module is initialized, before anything else is executed and is
specialized for a particular apply of an :ref:`op`.
.. method:: c_init_code_struct(node,
struct_id
, sub)
.. method:: c_init_code_struct(node,
name
, sub)
Allows you to specify code that will be inserted in the struct
constructor of the Op. This is for code which should be
executed once per thunk (Apply node, more or less).
`struct_id` is an integer guaranteed to be unique inside the
struct.
`sub` is a dictionary of extras parameters to the
c_code_init_code_struct method. It contains the following
values:
...
...
@@ -131,31 +125,25 @@ There are less methods to define for an Op than for a Type:
if the code is the same for each apply of an op. It will be
inserted at global scope.
.. method:: c_support_code_struct(node,
struct_id
)
.. method:: c_support_code_struct(node,
name
)
Allows you to specify helper functions of variables that will
be specific to one particular thunk. These are inserted at
struct scope.
`struct_id` is an integer guaranteed to be unique inside the
struct.
:note:
You cannot specify
kernels in the code returned by this since
that isn't supported by CUDA. You should place your kernels
in :meth:`c_support_code()` or :meth:`c_support_code_apply()`
and call them from this code.
You cannot specify
CUDA kernels in the code returned by this
since that isn't supported by CUDA. You should place your
kernels in :meth:`c_support_code()` or
:meth:`c_support_code_apply()`
and call them from this code.
.. method:: c_cleanup_code_struct(node,
struct_id
)
.. method:: c_cleanup_code_struct(node,
name
)
Allows you to specify code that will be inserted in the struct
destructor of the Op. This is for cleaninp up allocations and
stuff like this when the thunk is released (when you "free" a
compiled function using this op).
`struct_id` is an integer guaranteed to be unique inside the
struct.
.. method:: infer_shape(node, (i0_shapes,i1_shapes,...))
Allow optimizations to lift the Shape op over this op. An
...
...
theano/gof/cc.py
浏览文件 @
0d04e12b
...
...
@@ -658,7 +658,6 @@ class CLinker(link.Linker):
# Make the CodeBlock for c_code
sub
[
'id'
]
=
id
sub
[
'struct_id'
]
=
id
+
1
sub
[
'fail'
]
=
failure_code
(
sub
)
sub_struct
=
dict
()
...
...
@@ -692,7 +691,7 @@ class CLinker(link.Linker):
" didn't return a string for c_init_code_apply"
)
try
:
struct_init
=
op
.
c_init_code_struct
(
node
,
id
+
1
,
sub_struct
)
struct_init
=
op
.
c_init_code_struct
(
node
,
name
,
sub_struct
)
assert
isinstance
(
struct_init
,
basestring
),
(
str
(
node
.
op
)
+
" didn't return a string for c_init_code_struct"
)
...
...
@@ -700,7 +699,7 @@ class CLinker(link.Linker):
pass
try
:
struct_support
=
op
.
c_support_code_struct
(
node
,
id
+
1
)
struct_support
=
op
.
c_support_code_struct
(
node
,
name
)
assert
isinstance
(
struct_support
,
basestring
),
(
str
(
node
.
op
)
+
" didn't return a string for c_support_code_struct"
)
...
...
@@ -708,7 +707,7 @@ class CLinker(link.Linker):
pass
try
:
struct_cleanup
=
op
.
c_cleanup_code_struct
(
node
,
id
+
1
)
struct_cleanup
=
op
.
c_cleanup_code_struct
(
node
,
name
)
assert
isinstance
(
struct_cleanup
,
basestring
),
(
str
(
node
.
op
)
+
" didn't return a string for c_cleanup_code_struct"
)
...
...
theano/gof/graph.py
浏览文件 @
0d04e12b
...
...
@@ -184,7 +184,8 @@ class Apply(Node):
:note:
tags are copied from self to the returned instance.
"""
cp
=
self
.
__class__
(
self
.
op
,
self
.
inputs
,
[
output
.
clone
()
for
output
in
self
.
outputs
])
cp
=
self
.
__class__
(
self
.
op
,
self
.
inputs
,
[
output
.
clone
()
for
output
in
self
.
outputs
])
cp
.
tag
=
copy
(
self
.
tag
)
return
cp
...
...
theano/gof/op.py
浏览文件 @
0d04e12b
...
...
@@ -322,17 +322,15 @@ class CLinkerOp(CLinkerObject):
raise
utils
.
MethodNotDefined
(
"c_init_code_apply"
,
type
(
self
),
self
.
__class__
.
__name__
)
def
c_init_code_struct
(
self
,
node
,
struct_id
,
sub
):
def
c_init_code_struct
(
self
,
node
,
name
,
sub
):
"""
Optional: return a code string specific to the apply
to be inserted in the struct initialization code.
:param node: an Apply instance in the graph being compiled
:param struct_id: a number that serves to uniquely identify
this code. The c_code will receive another
sub parameter named struct_id that will
contain this name.
:param name: a unique name to distinguish you variables from
those of other nodes.
:param sub: a dictionary of values to substitute in the code.
Most notably it contains a 'fail' entry that you
...
...
@@ -345,17 +343,15 @@ class CLinkerOp(CLinkerObject):
raise
utils
.
MethodNotDefined
(
"c_init_code_apply"
,
type
(
self
),
self
.
__class__
.
__name__
)
def
c_support_code_struct
(
self
,
node
,
struct_id
):
def
c_support_code_struct
(
self
,
node
,
name
):
"""Optional: Return utility code for use by an `Op` that will be
inserted at struct scope, that can be specialized for the
support of a particular `Apply` node.
:param node: an Apply instance in the graph being compiled
:param struct_id: a number that serves to uniquely identify
this code. The c_code will receive another
sub parameter named struct_id that will
contain this name.
:param name: a unique name to distinguish you variables from
those of other nodes.
:Exceptions:
- `MethodNotDefined`: Subclass does not implement this method
...
...
@@ -364,17 +360,15 @@ class CLinkerOp(CLinkerObject):
raise
utils
.
MethodNotDefined
(
"c_support_code_struct"
,
type
(
self
),
self
.
__class__
.
__name__
)
def
c_cleanup_code_struct
(
self
,
node
,
struct_id
):
def
c_cleanup_code_struct
(
self
,
node
,
name
):
"""
Optional: return a code string specific to the apply to be
inserted in the struct cleanup code.
:param node: an Apply instance in the graph being compiled
:param struct_id: a number that serves to uniquely identify
this code. The c_code will receive another
sub parameter named struct_id that will
contain this name.
:param name: a unique name to distinguish you variables from
those of other nodes.
:Exceptions:
- `MethodNotDefined`: the subclass does not override this method
...
...
theano/gof/tests/test_op.py
浏览文件 @
0d04e12b
...
...
@@ -94,20 +94,20 @@ class StructOp(Op):
def
make_node
(
self
,
i
):
return
Apply
(
self
,
[
i
],
[
scalar
.
uint64
()])
def
c_support_code_struct
(
self
,
node
,
struct_id
):
return
"npy_uint64 counter
%
d;"
%
(
struct_id
,)
def
c_support_code_struct
(
self
,
node
,
name
):
return
"npy_uint64 counter
%
s;"
%
(
name
,)
def
c_init_code_struct
(
self
,
node
,
struct_id
,
sub
):
return
"counter
%
d = 0;"
%
(
struct_id
,)
def
c_init_code_struct
(
self
,
node
,
name
,
sub
):
return
"counter
%
s = 0;"
%
(
name
,)
def
c_code
(
self
,
node
,
name
,
input_names
,
outputs_names
,
sub
):
return
"""
%(out)
s = counter
%(
sid
)
s;
counter
%(
sid
)
s++;
"""
%
dict
(
out
=
outputs_names
[
0
],
sid
=
sub
[
'struct_id'
]
)
%(out)
s = counter
%(
name
)
s;
counter
%(
name
)
s++;
"""
%
dict
(
out
=
outputs_names
[
0
],
name
=
name
)
def
c_code_cache_version
(
self
):
return
(
0
,)
return
(
1
,)
class
TestOp
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论