Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
54b0b796
提交
54b0b796
authored
7月 20, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adding code-generation docs to gof/type
上级
148168f6
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
54 行增加
和
14 行删除
+54
-14
type.py
theano/gof/type.py
+54
-14
没有找到文件。
theano/gof/type.py
浏览文件 @
54b0b796
...
@@ -50,13 +50,28 @@ class CLinkerType(object):
...
@@ -50,13 +50,28 @@ class CLinkerType(object):
"""Required: Return c code to declare variables that will be
"""Required: Return c code to declare variables that will be
instantiated by `c_extract`.
instantiated by `c_extract`.
Example: WRITEME
Example:
.. code-block: python
:Parameters:
return "PyObject ** addr_of_
%(name)
s;"
- `name`: WRITEME
WRITEME
:param name: the name of the ``PyObject *`` pointer that will the value for this Type
- `sub`: WRITEME
WRITEME
:type name: string
:param sub: a dictionary of special codes. Most importantly sub['fail']. See CLinker
for more info on `sub` and ``fail``.
:type sub: dict string -> string
:note: It is important to include the `name` inside of variables which are declared
here, so that name collisions do not occur in the source file that is generated.
:note: The variable called ``name`` is not necessarily defined yet where this code is
inserted. This code might be inserted to create class variables for example, whereas
the variable ``name`` might only exist inside certain functions in that class.
:todo: Why should variable declaration fail? Is it even allowed to?
:Exceptions:
:Exceptions:
- `MethodNotDefined`: Subclass does not implement this method
- `MethodNotDefined`: Subclass does not implement this method
...
@@ -64,29 +79,54 @@ class CLinkerType(object):
...
@@ -64,29 +79,54 @@ class CLinkerType(object):
raise
MethodNotDefined
()
raise
MethodNotDefined
()
def
c_init
(
self
,
name
,
sub
):
def
c_init
(
self
,
name
,
sub
):
"""Required: Return c code to initialize the variables that were declared by
self.c_declare()
Example:
.. code-block: python
return "addr_of_
%(name)
s = NULL;"
:note: The variable called ``name`` is not necessarily defined yet where this code is
inserted. This code might be inserted in a class constructor for example, whereas
the variable ``name`` might only exist inside certain functions in that class.
:todo: Why should variable initialization fail? Is it even allowed to?
"""
raise
MethodNotDefined
(
"c_init"
,
type
(
self
),
self
.
__class__
.
__name__
)
raise
MethodNotDefined
(
"c_init"
,
type
(
self
),
self
.
__class__
.
__name__
)
def
c_extract
(
self
,
name
,
sub
):
def
c_extract
(
self
,
name
,
sub
):
"""Required: Return c code to extract a PyObject * instance.
"""Required: Return c code to extract a PyObject * instance.
The code returned from this function must be templated using
The code returned from this function must be templated using
"
%(name)
s"
, representing the name that the caller wants to
``
%(name)
s``
, representing the name that the caller wants to
call this `Variable`. The Python object self.data is in a
call this `Variable`. The Python object self.data is in a
variable called "py_
%(name)
s" and this code must set the
variable called "py_
%(name)
s" and this code must set the
variables declared by c_declare to something representative
variables declared by c_declare to something representative
of py_
%(name)
s. If the data is improper, set an appropriate
of py_
%(name)
s. If the data is improper, set an appropriate
exception and insert "
%(fail)
s".
exception and insert "
%(fail)
s".
@
todo: Point out that template filling (via sub) is now performed
:
todo: Point out that template filling (via sub) is now performed
by this function. --jpt
by this function. --jpt
WRITEME
:Parameters:
Example:
- `name`: WRITEME
.. code-block: python
WRITEME
- `sub`: WRITEME
return "if (py_
%(name)
s == Py_None)" +
\\\
WRITEME
addr_of_
%(name)
s = &py_
%(name)
s;" +
\\\
"else" +
\\\
{ PyErr_SetString(PyExc_ValueError, 'was expecting None');
%(fail)
s;}"
:param name: the name of the ``PyObject *`` pointer that will the value for this Type
:type name: string
:param sub: a dictionary of special codes. Most importantly sub['fail']. See CLinker
for more info on `sub` and ``fail``.
:type sub: dict string -> string
:Exceptions:
:Exceptions:
- `MethodNotDefined`: Subclass does not implement this method
- `MethodNotDefined`: Subclass does not implement this method
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论