Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c7e96699
提交
c7e96699
authored
3月 19, 2009
作者:
Joseph Turian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polished Op
上级
f1394e20
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
79 行增加
和
67 行删除
+79
-67
op.txt
doc/advanced_tutorial/ex1/op.txt
+65
-62
graphstructures.txt
doc/advanced_tutorial/graphstructures.txt
+6
-5
numpy.txt
doc/sandbox/numpy.txt
+8
-0
没有找到文件。
doc/advanced_tutorial/ex1/op.txt
浏览文件 @
c7e96699
...
@@ -36,53 +36,75 @@ An Op is any object which defines the following methods:
...
@@ -36,53 +36,75 @@ An Op is any object which defines the following methods:
- **perform(node, inputs, output_storage)**
- **perform(node, inputs, output_storage)**
- This
function
computes the function associated to this Op. The
- This
method
computes the function associated to this Op. The
``node`` is an Apply node created by the Op's ``make_node``
``node`` is an Apply node created by the Op's ``make_node``
method, the inputs are a list of references to data to operate on
method, ``inputs`` is a list of references to data to operate on,
and output_storage is a list of storage cells where the results of
and ``output_storage`` is a list of storage cells where the results of
the computation must be put.
the computation must be put. More specifically:
- This function must be determined by the inputs. That is to say, if it is
- ``node``: This is a reference to an Apply node which was previously
obtained via ``mul``'s ``make_node`` method. It is typically not
used in simple Ops, but it contains symbolic information that
could be required for complex Ops.
- ``inputs``: This is a list of data.
- ``output_storage``: This is a list of storage cells.
A storage cell is a one-element list. It is forbidden to change
the length of the list(s) contained in output_storage. There is
one storage cell for each output of the Op.
The data you put in ``output_storage`` must match the type of the
symbolic output. This is a situation where the ``node`` argument
can come in handy.
- This method must be determined by the inputs. That is to say, if it is
evaluated once on inputs A and returned B, then if ever inputs C, equal to
evaluated once on inputs A and returned B, then if ever inputs C, equal to
A, are presented again, then outputs equal to B must be returned again.
A, are presented again, then outputs equal to B must be returned again.
- You must be careful about aliasing outputs to inputs, and making
- You must be careful about aliasing outputs to inputs, and making
modifications to any of the inputs.
See `Views and inplace operations`_
modifications to any of the inputs. See `Views and inplace operations`_
before writing a ``perform`` implementation that does either of these
before writing a ``perform`` implementation that does either of these
things.
things.
- **__eq__(self, other)**
- **__eq__(self, other)**
- Returning True here is a promise to the optimization system that the other
- ``other`` is also an Op.
- Returning ``True`` here is a promise to the optimization system that the other
Op will produce exactly the same graph effects (from perform) as this one,
Op will produce exactly the same graph effects (from perform) as this one,
given identical inputs.
This means it will produce the same output values,
given identical inputs. This means it will produce the same output values,
it will destroy the same inputs (same destroy_map), and will alias outputs
it will destroy the same inputs (same destroy_map), and will alias outputs
to the same inputs (same view_map).
to the same inputs (same view_map).
- **__hash__(self)**
- **__hash__(self)**
- If two Op instances compare equal, then they
MUST
return the same hash
- If two Op instances compare equal, then they
**must**
return the same hash
value.
value.
- Equally important, this hash value must not change during the lifetime of
- Equally important, this hash value must not change during the lifetime of
self.
self.
- **__ne__(self, other)**
- **__ne__(self, other)**
- Recommended, and default: define as (not (self==other))
- Recommended
- Default: ``(not (self==other))``
- **grad(inputs, output_gradients)**
- **grad(inputs, output_gradients)** *Optional*
- Optional.
- If the Op you are defining is differentiable, you can define its
- If the Op you are defining is differentiable, you can define its
gradient symbolically in this method.
gradient symbolically in this method.
- Both the
inputs and output_gradients will be Results. This function must
- Both the
``inputs`` and ``output_gradients`` will be Results. This
return a list containing one Result (or None) for each input.
method must return a list containing one Result (or None) for each
Each returned Result represents the gradient wrt that input given the
input. Each returned Result represents the gradient with respect to
symbolic gradients wrt
each output.
that input given the symbolic gradients with respect to
each output.
- If the output is not differentiable with respect to any inputs, then this
- If the output is not differentiable with respect to any inputs, then this
function
should be defined to return [None for i in inputs].
method
should be defined to return [None for i in inputs].
- If this method is not defined, then theano assumes it has been forgotten.
- If this method is not defined, then theano assumes it has been forgotten.
Symbolic differentiation will fail on a graph that includes this Op.
Symbolic differentiation will fail on a graph that includes this Op.
...
@@ -90,7 +112,9 @@ An Op is any object which defines the following methods:
...
@@ -90,7 +112,9 @@ An Op is any object which defines the following methods:
- For more information on the use of this method, see ``grad``.
- For more information on the use of this method, see ``grad``.
For each method, the *default* is what the Op class defines for you.
For each method, the *default* is what :api:`theano.gof.Op` defines
for you. At a bare minimum, a new Op must define ``make_node`` and
``perform``, which have no defaults.
For more details, including the interface for providing a C implementation of
For more details, including the interface for providing a C implementation of
perform(), refer to the documentation for :ref:`op`.
perform(), refer to the documentation for :ref:`op`.
...
@@ -136,9 +160,10 @@ Use this list to make sure that you defined everything you need for your Op:
...
@@ -136,9 +160,10 @@ Use this list to make sure that you defined everything you need for your Op:
Defining mul
Defining mul
============
============
We are going to redefine the two functions that are absolutely
We'll define multiplication as a *binary* operation, even though a
necessary to redefine: ``make_node`` and ``perform``. First, we'll
multiplication Op could take an arbitrary number of arguments.
instantiate a ``mul`` Op:
First, we'll instantiate a ``mul`` Op:
.. code-block:: python
.. code-block:: python
...
@@ -149,12 +174,13 @@ instantiate a ``mul`` Op:
...
@@ -149,12 +174,13 @@ instantiate a ``mul`` Op:
**make_node**
**make_node**
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 (we'll define multiplication as a binary operation here, even
two.
though a multiplication Op could technically take an arbitrary number
This function ensures that both inputs have the ``double``
of arguments). It should ensure that both inputs have the ``double``
type.
type and it should make an Apply node with an output Result of type
Since multiplying two doubles yields a double,
``double`` (since multiplying two doubles yields a double).
this function makes an Apply node with an output Result of type
``double``.
.. code-block:: python
.. code-block:: python
...
@@ -171,14 +197,8 @@ want to multiply two arbitrary types, it would not make much sense
...
@@ -171,14 +197,8 @@ want to multiply two arbitrary types, it would not make much sense
(and we'd be screwed when we implement this in C!)
(and we'd be screwed when we implement this in C!)
The last line is the meat of the definition. There we create an Apply
The last line is the meat of the definition. There we create an Apply
node representing the application of ``mul`` to ``x`` and ``y``. Apply
node representing the application of Op ``mul`` to inputs ``x`` and
takes three arguments: the first one is the Op we are applying. In
``y``, giving a Result instance of type ``double`` as the output.
this case, we are applying ``mul``. The second argument is a list of
input Results - here, ``x`` and ``y``. The third is a list of output
Results. Since the multiplication of two doubles ought to give us a
double again, we create a Result of type ``double`` and we place it in
a list. Since the list only has one element, ``mul`` only has one
output.
.. note::
.. note::
Theano relies on the fact that if you call the ``make_node`` method
Theano relies on the fact that if you call the ``make_node`` method
...
@@ -190,25 +210,11 @@ output.
...
@@ -190,25 +210,11 @@ output.
**perform**
**perform**
This code should actually compute the function. It is important to
This code actually computes the function.
understand the role of all three arguments of ``perform``:
In our example, the data in ``inputs`` will be instances of Python's
built-in type ``float`` because this is the type that ``double.filter()``
- *node*: This is a reference to an Apply node which was previously
will always return, per our own definition. ``output_storage`` will
obtained via ``mul``'s ``make_node`` method. It is not typically
contain a single storage cell for the multiplication's result.
useful, but it contains symbolic information that could be required
for complex Ops.
- *inputs*: This is a list of data. In this example, the data in
``inputs`` will be instances of Python's built-in type ``float``
because this is the type that ``double.filter()`` will always
return, per our own definition.
- *output_storage*: This is a list of storage cells. There is one
storage cell for each output of the Op. A storage cell is
a one-element list (note: it is forbidden to change the
length of the list(s) contained in output_storage). In this example,
output_storage will contain a single storage cell for the
multiplication's result.
.. code-block:: python
.. code-block:: python
...
@@ -230,12 +236,9 @@ Here, ``z`` is a list of one element. By default, ``z == [None]``.
...
@@ -230,12 +236,9 @@ Here, ``z`` is a list of one element. By default, ``z == [None]``.
:ref:`op` documentation.
:ref:`op` documentation.
.. warning::
.. warning::
The data you put in ``output_storage`` must match the type of the
We gave ``z`` the Theano type ``double`` in ``make_node``, which means
symbolic output. This is a situation where the ``node`` argument
that a Python ``float`` must be put there. You should not put, say, an
can come in handy. In this example, we gave ``z`` the Theano type
``int`` in ``z[0]`` because Theano assumes Ops handle typing properly.
``double`` in ``make_node``, which means that a Python ``float``
must be put there. You should not put, say, an ``int`` in ``z[0]``
because Theano assumes Ops handle typing properly.
Trying out our new Op
Trying out our new Op
...
@@ -280,7 +283,7 @@ by modifying ``make_node`` to accept Python ``int`` or ``float`` as
...
@@ -280,7 +283,7 @@ by modifying ``make_node`` to accept Python ``int`` or ``float`` as
mul.make_node = make_node
mul.make_node = make_node
Whenever we pass a Python int or float instead of a Result as ``x`` or
Whenever we pass a Python int or float instead of a Result as ``x`` or
``y``,
make_node
will convert it to :ref:`constant` for us. ``gof.Constant``
``y``,
``make_node``
will convert it to :ref:`constant` for us. ``gof.Constant``
is a :ref:`result` we statically know the value of.
is a :ref:`result` we statically know the value of.
>>> x = double('x')
>>> x = double('x')
...
...
doc/advanced_tutorial/graphstructures.txt
浏览文件 @
c7e96699
...
@@ -169,6 +169,10 @@ theano's version of a function definition.
...
@@ -169,6 +169,10 @@ theano's version of a function definition.
An Apply instance has three important fields:
An Apply instance has three important fields:
**op**
An :ref:`op` that determines the function/transformation being
applied here.
**inputs**
**inputs**
A list of :ref:`Results <result>` that represent the arguments of
A list of :ref:`Results <result>` that represent the arguments of
the function.
the function.
...
@@ -177,11 +181,8 @@ An Apply instance has three important fields:
...
@@ -177,11 +181,8 @@ An Apply instance has three important fields:
A list of :ref:`Results <result>` that represent the return values
A list of :ref:`Results <result>` that represent the return values
of the function.
of the function.
**op**
An Apply instance can be created by calling ``gof.Apply(op, inputs,
An :ref:`op` that determines the function/transformation being
outputs)``.
applied here.
.. index::
.. index::
...
...
doc/sandbox/numpy.txt
0 → 100644
浏览文件 @
c7e96699
.. _numpy::
===============
NumPy refresher
===============
Give summary of type(x) vs x.type vs x.dtype
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论