Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
79d539f6
提交
79d539f6
authored
9月 22, 2008
作者:
james@crane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more docs, factored Op class
上级
c607868a
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
140 行增加
和
76 行删除
+140
-76
op.py
gof/op.py
+140
-76
没有找到文件。
gof/op.py
浏览文件 @
79d539f6
"""
""" Defines base clases `Op` and `Op_clinker`.
Contains the `Op` class, which is the base interface for all operations
compatible with `gof`'s :doc:`graph` manipulation routines.
The `Op` class is the base interface for all operations
compatible with `gof`'s :doc:`graph` routines.
"""
"""
__docformat__
=
"restructuredtext en"
__docformat__
=
"restructuredtext en"
...
@@ -9,7 +11,141 @@ import utils
...
@@ -9,7 +11,141 @@ import utils
import
traceback
import
traceback
class
Op
(
utils
.
object2
):
class
Op_clinker
(
utils
.
object2
):
"""
Interface definition for `Op` subclasses compiled by `CLinker`.
A subclass should implement
WRITEME: structure of automatically generated C code.
"""
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
"""Required: Return the C implementation of an Op.
Returns C code that does the computation associated to this L{Op},
given names for the inputs and outputs.
:Parameters:
`node`: Apply instance
WRITEME
`name`: WRITEME
WRITEME
`inputs`: list of strings
There is a string for each input of the function, and the string is the name of a C
`PyObject` variable pointing to that input.
`outputs`: list of strings
Each string is the name of a `PyObject` pointer where the Op should store its
results. The `CLinker` guarantees that on entry to this code block, each pointer
is either NULL or is unchanged from the end of the previous execution.
`sub`: dict of strings
extra symbols defined in `CLinker` sub symbols (such as 'fail').
WRITEME
:Exceptions:
- `AbstractFunctionError`: the subclass does not override this method
"""
raise
utils
.
AbstractFunctionError
(
'
%
s.c_code is not defined'
\
%
self
.
__class__
.
__name__
)
def
c_code_cleanup
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
"""Optional: Return C code to run after c_code, whether it failed or not.
QUESTION: is this function optional?
This is a convenient place to clean up things allocated by c_code().
:Parameters:
`node`: Apply instance
WRITEME
`name`: WRITEME
WRITEME
`inputs`: list of strings
There is a string for each input of the function, and the string is the name of a C
`PyObject` variable pointing to that input.
`outputs`: list of strings
Each string is the name of a `PyObject` pointer where the Op should store its
results. The `CLinker` guarantees that on entry to this code block, each pointer
is either NULL or is unchanged from the end of the previous execution.
`sub`: dict of strings
extra symbols defined in `CLinker` sub symbols (such as 'fail').
WRITEME
WRITEME
:Exceptions:
- `AbstractFunctionError`: the subclass does not override this method
"""
raise
utils
.
AbstractFunctionError
()
def
c_compile_args
(
self
):
"""Optional: Return a list of recommended gcc compiler arguments.
QUESTION: is this function optional?
This is only a hint.
EXAMPLE
WRITEME
"""
raise
utils
.
AbstractFunctionError
()
def
c_headers
(
self
):
"""Optional: Return a list of header files that must be included to compile the C code.
A subclass should override this method.
EXAMPLE
WRITEME
:Exceptions:
- `AbstractFunctionError`: the subclass does not override this method
"""
raise
utils
.
AbstractFunctionError
()
def
c_libraries
(
self
):
"""Optional: Return a list of libraries to link against to manipulate this `Op`.
A subclass should override this method.
WRITEME
:Exceptions:
- `AbstractFunctionError`: the subclass does not override this method
"""
raise
utils
.
AbstractFunctionError
()
def
c_support_code
(
self
):
"""Optional: Return support code for use by the code that is returned by `c_code`.
Support code is inserted into the C code at global scope.
A subclass should override this method.
WRITEME
:Exceptions:
- `AbstractFunctionError`: the subclass does not override this method
"""
raise
utils
.
AbstractFunctionError
()
#TODO:
# This is a somewhat ugly use of inheritance because Op is an abstract interface that has
# nothing to do with code generation.
#
# Better would be for Op subclasses wanting to work with the CLinker to have a second
# inheritance from Op_clinker.
class
Op
(
Op_clinker
):
"""
"""
An :term:`Op` is a type of operation.
An :term:`Op` is a type of operation.
...
@@ -118,76 +254,4 @@ class Op(utils.object2):
...
@@ -118,76 +254,4 @@ class Op(utils.object2):
"""
"""
raise
utils
.
AbstractFunctionError
(
self
)
raise
utils
.
AbstractFunctionError
(
self
)
#####################
# C code generation #
#####################
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
"""Contract: Return the C implementation of an Op.
Returns C code that does the computation associated to this L{Op},
given names for the inputs and outputs.
:Parameters:
`node`: Apply instance
WRITEME
`name`: WRITEME
WRITEME
`inputs`: list of strings
There is a string for each input of the function, and the string is the name of a C
`PyObject` variable pointing to that input.
`outputs`: list of strings
Each string is the name of a `PyObject` pointer where the Op should store its
results. The `CLinker` guarantees that on entry to this code block, each pointer
is either NULL or is unchanged from the end of the previous execution.
`sub`: dict of strings
extra symbols defined in `CLinker` sub symbols (such as 'fail').
WRITEME
"""
raise
utils
.
AbstractFunctionError
(
'
%
s.c_code is not defined'
\
%
self
.
__class__
.
__name__
)
def
c_code_cleanup
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
"""Code to be run after c_code, whether it failed or not.
This is a convenient place to clean up things allocated by c_code().
WRITEME
"""
raise
utils
.
AbstractFunctionError
()
def
c_compile_args
(
self
):
"""
Return a list of compile args recommended to manipulate this L{Op}.
WRITEME
"""
raise
utils
.
AbstractFunctionError
()
def
c_headers
(
self
):
"""
Return a list of header files that must be included from C to manipulate
this L{Op}.
WRITEME
"""
raise
utils
.
AbstractFunctionError
()
def
c_libraries
(
self
):
"""
Return a list of libraries to link against to manipulate this L{Op}.
WRITEME
"""
raise
utils
.
AbstractFunctionError
()
def
c_support_code
(
self
):
"""
Return utility code for use by this L{Op}. It may refer to support code
defined for its input L{Result}s.
WRITEME
"""
raise
utils
.
AbstractFunctionError
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论