Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5cc0a63e
提交
5cc0a63e
authored
9月 22, 2008
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
updated doc
上级
0d5b33a3
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
12 行增加
和
22 行删除
+12
-22
op.py
gof/op.py
+12
-22
没有找到文件。
gof/op.py
浏览文件 @
5cc0a63e
"""
Defines base clases `Op` and `Op_clinker`.
"""
Defines base classes `Op`, `PureOp`, and `CLinkerOp`
The `Op` class is the base interface for all operations
compatible with `gof`'s :doc:`graph` routines.
...
...
@@ -11,20 +11,20 @@ import utils
import
traceback
class
Op_clinker
(
utils
.
object2
):
class
CLinkerOp
(
object
):
"""
Interface definition for `Op` subclasses compiled by `CLinker`.
A subclass should implement
A subclass should implement
WRITEME.
WRITEME: structure of automatically generated C code.
WRITEME: structure of automatically generated C code.
Put this in doc/code_structure.txt
"""
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}
,
Returns C code that does the computation associated to this
`Op`
,
given names for the inputs and outputs.
:Parameters:
...
...
@@ -137,15 +137,7 @@ class Op_clinker(utils.object2):
"""
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
):
class
PureOp
(
object
):
"""
An :term:`Op` is a type of operation.
...
...
@@ -161,9 +153,6 @@ class Op(Op_clinker):
- performing the calculation of outputs from given inputs (via the `perform`),
- producing c code to perform calculation of outputs from inputs (via `c_code`,
`c_code_cleanup`, `c_support_code`, `c_headers`, `c_libraries`, `c_compile_args`)
- [optionally] building gradient-calculating graphs (via `grad`).
...
...
@@ -186,7 +175,7 @@ class Op(Op_clinker):
def
make_node
(
self
,
*
inputs
):
"""
Contract
: return an Apply instance representing the
Required
: return an Apply instance representing the
application of this Op to the provided inputs.
All subclasses should over-ride this function.
...
...
@@ -198,8 +187,7 @@ class Op(Op_clinker):
raise
utils
.
AbstractFunctionError
(
self
)
def
__call__
(
self
,
*
inputs
):
"""
Return some or all output[s] of `make_node`.
"""Optional: Return some or all output[s] of `make_node`.
It is called by code such as:
...
...
@@ -232,7 +220,7 @@ class Op(Op_clinker):
def
perform
(
self
,
node
,
inputs
,
output_storage
):
"""
Contract
: Calculate the function on the inputs and put the results in the
Required
: Calculate the function on the inputs and put the results in the
output storage. Return None.
:Parameters:
...
...
@@ -254,4 +242,6 @@ class Op(Op_clinker):
"""
raise
utils
.
AbstractFunctionError
(
self
)
class
Op
(
utils
.
object2
,
PureOp
,
CLinkerOp
):
"""Convenience class to bundle `PureOp` and `CLinkerOp`"""
pass
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论