Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c78a626a
提交
c78a626a
authored
8月 11, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
8月 12, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update formatting for ExternalCOp in creating_a_c_op.rst
上级
fe15cbbb
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
18 行增加
和
15 行删除
+18
-15
creating_a_c_op.rst
doc/extending/creating_a_c_op.rst
+18
-15
没有找到文件。
doc/extending/creating_a_c_op.rst
浏览文件 @
c78a626a
...
@@ -408,6 +408,9 @@ commonly used.
...
@@ -408,6 +408,9 @@ commonly used.
this function should return a tuple of integers as previously
this function should return a tuple of integers as previously
described.
described.
Also, do not use the built-in ``hash``; it will produce different values
between Python sessions and confound the caching process.
Important restrictions when implementing a :class:`COp`
Important restrictions when implementing a :class:`COp`
=======================================================
=======================================================
...
@@ -719,8 +722,8 @@ simple but it still involves defining many methods as well as mixing, in the
...
@@ -719,8 +722,8 @@ simple but it still involves defining many methods as well as mixing, in the
same file, both Python and C code which tends to make the result less
same file, both Python and C code which tends to make the result less
readable.
readable.
To help with this, Aesara defines a class, `
`ExternalCOp`
`, from which new C :class:`Op`\s
To help with this, Aesara defines a class, `
ExternalCOp
`, from which new C :class:`Op`\s
can inherit. The class `
`ExternalCOp`
` aims to simplify the process of implementing
can inherit. The class `
ExternalCOp
` aims to simplify the process of implementing
C :class:`Op`\s by doing the following :
C :class:`Op`\s by doing the following :
* It allows you to define the C implementation of your :class:`Op` in a distinct
* It allows you to define the C implementation of your :class:`Op` in a distinct
...
@@ -728,15 +731,15 @@ C :class:`Op`\s by doing the following :
...
@@ -728,15 +731,15 @@ C :class:`Op`\s by doing the following :
readable and well indented.
readable and well indented.
* It can automatically handle all the methods that return C code,
* It can automatically handle all the methods that return C code,
in addition to :meth:`Op.c_code_cache_version
()
` based on the
in addition to :meth:`Op.c_code_cache_version` based on the
provided external C implementation.
provided external C implementation.
To illustrate how much simpler the class `
`ExternalCOp`
` makes the process of defining
To illustrate how much simpler the class `
ExternalCOp
` makes the process of defining
a new :class:`Op` with a C implementation, let's revisit the second example of this
a new :class:`Op` with a C implementation, let's revisit the second example of this
tutorial, the `
`VectorTimesVector``
:class:`Op`. In that example, we implemented an :class:`Op`
tutorial, the `
VectorTimesVector`\
:class:`Op`. In that example, we implemented an :class:`Op`
to perform the task of element-wise vector-vector multiplication. The two
to perform the task of element-wise vector-vector multiplication. The two
following blocks of code illustrate what the :class:`Op` would look like if it was
following blocks of code illustrate what the :class:`Op` would look like if it was
implemented using the `
`ExternalCOp`
` class.
implemented using the `
ExternalCOp
` class.
The new :class:`Op` is defined inside a Python file with the following code :
The new :class:`Op` is defined inside a Python file with the following code :
...
@@ -850,23 +853,23 @@ in the same file and the C code contained string formatting markers.
...
@@ -850,23 +853,23 @@ in the same file and the C code contained string formatting markers.
Now that we have motivated the `ExternalCOp` class, we can have a more precise look at
Now that we have motivated the `ExternalCOp` class, we can have a more precise look at
what it does for us. For this, we go through the various elements that make up
what it does for us. For this, we go through the various elements that make up
this new version of the `
`VectorTimesVector``
`Op` :
this new version of the `
VectorTimesVector`\
`Op` :
* Parent class : instead of inheriting from the class :class:`Op`,
* Parent class : instead of inheriting from the class :class:`Op`,
VectorTimesVector inherits from the class `
`ExternalCOp`
`.
VectorTimesVector inherits from the class `
ExternalCOp
`.
* Constructor : in our new `COp`, the
``__init__()`
` method has an
* Constructor : in our new `COp`, the
:meth:`COp.__init__
` method has an
important use; to inform the constructor of the `
`ExternalCOp`
` class
important use; to inform the constructor of the `
ExternalCOp
` class
of the location, on the filesystem of the C implementation of
of the location, on the filesystem of the C implementation of
this `COp`. To do this, it gives a list of file paths containing
this `COp`. To do this, it gives a list of file paths containing
the C code for this `COp`. To auto-generate the c_code method
the C code for this `COp`. To auto-generate the c_code method
with a function call you can specify the function name as the
with a function call you can specify the function name as the
second parameter. The paths should be given as a relative
second parameter. The paths should be given as a relative
path from the folder where the descendant of the `
`ExternalCOp`
` class
path from the folder where the descendant of the `
ExternalCOp
` class
is defined.
is defined.
*
``make_node()`` : the ``make_node()``
method is absolutely
*
:meth:`ExternalCOp.make_node` : this
method is absolutely
identical to the one in our old example. Using the `
`ExternalCOp`
`
identical to the one in our old example. Using the `
ExternalCOp
`
class doesn't change anything here.
class doesn't change anything here.
* External C code : the external C code implements the various
* External C code : the external C code implements the various
...
@@ -877,8 +880,8 @@ this new version of the ``VectorTimesVector`` `Op` :
...
@@ -877,8 +880,8 @@ this new version of the ``VectorTimesVector`` `Op` :
Main function
Main function
-------------
-------------
If you pass a function name to
the ``__init__()`` method of the
If you pass a function name to
:meth:`ExternalCOp.__init___`, it must respect
``ExternalCOp`` class, it must respect
the following constraints:
the following constraints:
* It must return an int. The value of that int indicates whether
* It must return an int. The value of that int indicates whether
the `Op` could perform its task or not. A value of 0 indicates
the `Op` could perform its task or not. A value of 0 indicates
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论