Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b7f5a2dd
提交
b7f5a2dd
authored
8月 29, 2014
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Changes following review.
上级
603bc454
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
30 行增加
和
24 行删除
+30
-24
op.txt
doc/extending/op.txt
+21
-19
extending_theano.txt
doc/tutorial/extending_theano.txt
+9
-5
没有找到文件。
doc/extending/op.txt
浏览文件 @
b7f5a2dd
...
@@ -36,9 +36,9 @@ define the following methods.
...
@@ -36,9 +36,9 @@ define the following methods.
This method computes the function associated to this Op. ``node`` is
This method computes the function associated to this Op. ``node`` is
an Apply node created by the Op's ``make_node`` method. ``inputs``
an Apply node created by the Op's ``make_node`` method. ``inputs``
is a list of references to data to operate on using non-symbolic
is a list of references to data to operate on using non-symbolic
statements, (i.e., statements in Python, Numpy
and C
statements, (i.e., statements in Python, Numpy
). ``output_storage``
languages). ``output_storage`` is a list of storage cells where the
is a list of storage cells where the variables of the computation
variables of the computation
must be put.
must be put.
More specifically:
More specifically:
...
@@ -125,6 +125,8 @@ Optional methods or attributes
...
@@ -125,6 +125,8 @@ Optional methods or attributes
Should be set to `()` if you have no attributes that are relevant to
Should be set to `()` if you have no attributes that are relevant to
the computation to generate the methods.
the computation to generate the methods.
.. versionadded:: 0.7
.. attribute:: default_output
.. attribute:: default_output
*Default:* None
*Default:* None
...
@@ -133,7 +135,8 @@ Optional methods or attributes
...
@@ -133,7 +135,8 @@ Optional methods or attributes
implementation of ``__call__`` will return
implementation of ``__call__`` will return
``node.outputs[self.default_output]``, where ``node`` was returned
``node.outputs[self.default_output]``, where ``node`` was returned
by ``make_node``. Otherwise, the entire list of outputs will be
by ``make_node``. Otherwise, the entire list of outputs will be
returned.
returned, unless it is of length 1, where the single element will be
returned by itself.
.. function:: make_thunk(node, storage_map, compute_map, no_recycling)
.. function:: make_thunk(node, storage_map, compute_map, no_recycling)
...
@@ -160,20 +163,22 @@ Optional methods or attributes
...
@@ -160,20 +163,22 @@ Optional methods or attributes
The returned function must ensure that is sets the computed
The returned function must ensure that is sets the computed
variables as computed in the `compute_map`.
variables as computed in the `compute_map`.
If you make your op class inherit from :class:`gof.Op`, then you
Defining this function removes the requirement for :meth:`perform`
can use the much easier :ref:`perform_meth` method below.
or C code, as you will define the thunk for the computation
yourself.
.. function:: __call__(*inputs, **kwargs)
.. function:: __call__(*inputs, **kwargs)
By default this is a conv
i
nience function which calls
By default this is a conv
e
nience function which calls
:meth:`make_node` with the supplied arguments and returns the
:meth:`make_node` with the supplied arguments and returns the
result indexed by `default_output`. This can be overridden by
result indexed by `default_output`. This can be overridden by
subclasses to do anything else, but must return
an Apply node
subclasses to do anything else, but must return
either a theano
representing the computation to be performed
.
Variable or a list of Variables
.
In cases where the returned graph may differ based on the arguments
If you feel the need to override `__call__` to change the graph
or their types, it is recommended to create a helper function
based on the arguments, you should instead create a function that
rather than overriding `__call__` on an Op.
will use your Op and build the graphs that you want and call that
instead of the Op instance directly.
.. function:: infer_shape(node, shapes)
.. function:: infer_shape(node, shapes)
...
@@ -228,7 +233,7 @@ Optional methods or attributes
...
@@ -228,7 +233,7 @@ Optional methods or attributes
As done in the Alloc op, you can return False only in some cases by
As done in the Alloc op, you can return False only in some cases by
analyzing the graph from the node parameter.
analyzing the graph from the node parameter.
If you want you op to work with gradient.grad() you also need to
If you want you
r
op to work with gradient.grad() you also need to
implement the functions described below.
implement the functions described below.
Gradient
Gradient
...
@@ -516,12 +521,9 @@ First, we'll instantiate a ``mul`` Op:
...
@@ -516,12 +521,9 @@ First, we'll instantiate a ``mul`` Op:
This function must take as many arguments as the operation we are
This function must take as many arguments as the operation we are
defining is supposed to take as inputs---in this example that would be
defining is supposed to take as inputs---in this example that would be
two.
two. This function ensures that both inputs have the ``double`` type.
This function ensures that both inputs have the ``double``
Since multiplying two doubles yields a double, this function makes an
type.
Apply node with an output Variable of type ``double``.
Since multiplying two doubles yields a double,
this function makes an Apply node with an output Variable of type
``double``.
.. If you modify this code, also change :
.. If you modify this code, also change :
.. theano/tests/test_tutorial.py:T_extending.test_extending_1
.. theano/tests/test_tutorial.py:T_extending.test_extending_1
...
...
doc/tutorial/extending_theano.txt
浏览文件 @
b7f5a2dd
...
@@ -105,12 +105,13 @@ computations. This is useful if you want to generate code and compile
...
@@ -105,12 +105,13 @@ computations. This is useful if you want to generate code and compile
it yourself. For example, this allows you to use PyCUDA to compile GPU
it yourself. For example, this allows you to use PyCUDA to compile GPU
code.
code.
The :attr:`__props__` attribute serves to make Op generate an
appropriate
The :attr:`__props__` attribute serves to make Op generate an
:func:`__eq__` and :func:`__hash__` for your Op. It must be a tuple
appropriate :func:`__eq__` and :func:`__hash__` for your Op. It must
that lists the properties that influence how the computation is
be a tuple that lists the properties that influence how the
performed (Ususally these are those that you set in
computation is
performed (Ususally these are those that you set in
:func:`__init__`). If you don't have any properties, then you should
:func:`__init__`). If you don't have any properties, then you should
set this attribute to the emtpy tuple `()`.
set this attribute to the emtpy tuple `()`. This requires development
version after September 1st, 2014 or version 0.7.
:func:`__eq__` and :func:`__hash__` will be used by the optimization
:func:`__eq__` and :func:`__hash__` will be used by the optimization
phase to merge nodes that are doing a equivalent compuation (same
phase to merge nodes that are doing a equivalent compuation (same
...
@@ -150,7 +151,10 @@ Op Example
...
@@ -150,7 +151,10 @@ Op Example
class DoubleOp(theano.Op):
class DoubleOp(theano.Op):
__props__ = ()
__props__ = ()
def make_node(self, x):
def make_node(self, x):
# check that the theano version has support for __props__
assert hasattr(self, '_props')
x = theano.tensor.as_tensor_variable(x)
x = theano.tensor.as_tensor_variable(x)
return theano.Apply(self, [x], [x.type()])
return theano.Apply(self, [x], [x.type()])
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论