Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
13d6527e
提交
13d6527e
authored
3月 03, 2009
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more advanced tutorial
上级
315c2e86
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
86 行增加
和
5 行删除
+86
-5
index.txt
doc/index.txt
+1
-2
index.txt
doc/tutorials/advanced/ex1/index.txt
+3
-0
type.txt
doc/tutorials/advanced/ex1/type.txt
+81
-1
adding.txt
doc/tutorials/basic/adding.txt
+1
-2
没有找到文件。
doc/index.txt
浏览文件 @
13d6527e
...
@@ -69,8 +69,7 @@ Contents
...
@@ -69,8 +69,7 @@ Contents
theano
theano
install
install
tutorials/basic/index
tutorials/index
tutorials/advanced/index
advanced/index
advanced/index
indexes/index
indexes/index
examples/index
examples/index
...
...
doc/tutorials/advanced/ex1/index.txt
浏览文件 @
13d6527e
...
@@ -10,5 +10,8 @@ Example 1
...
@@ -10,5 +10,8 @@ Example 1
:maxdepth: 2
:maxdepth: 2
type
type
op
ctype
cop
doc/tutorials/advanced/ex1/type.txt
浏览文件 @
13d6527e
...
@@ -4,4 +4,84 @@
...
@@ -4,4 +4,84 @@
Making the ``double`` type
Making the ``double`` type
==========================
==========================
WRITEME
We will piggyback this type on Python's "float" type. Note that a
Theano :ref:`type` is not equivalent to a Python type or
class. Indeed, in Theano, :ref:`dmatrix` an :ref:`ivector` both use
``numpy.ndarray`` as the working data type, yet they are different
Types. The Python and C implementations may also use different types
as long as a way to convert back and forth between them is provided.
A :ref:`type` in Theano is any object which defines the following
methods:
* **filter(value, strict [= False])**: this casts or wraps a value to
match the Type and returns the casted/wrapped value. If the value is
incompatible with the type, it must raise an exception. If strict is
True, filter must return a reference to ``value`` (i.e. casting
prohibited)
* **is_valid_value(value)**: returns True iff the value is exactly
compatible with the Type.
*Default*: defined in terms of ``filter(value, strict = True)``
* **values_eq(a, b)**: returns True iff ``a`` and ``b`` are valid
values of this Type and are equal.
*Default*: a == b
* **values_eq_approx(a, b)**: returns True iff ``a`` and ``b`` are
valid values of this Type and are approximately equal, for a
definition of approximately which varies from Type to Type.
*Default*: same as values_eq
* **make_result(name = None)**: makes a :term:`Result` of this Type
with the specified name. The Result will have its ``type`` field set
to the Type object.
*Default*: there is a generic definition of this in Type.
* **__call__()**:
Syntactic shortcut to make_result.
*Default*: this is done for you by Type.
For each method, the *default* is what Type defines for you. This
means you will rarely need to define all of these methods.
In the past, some confusion has arised on what an instance of Type is
versus a subclass of Type or an instance of Result. Some of this
confusion is syntactic. A Type is any object which has fields
corresponding to the functions defined above. The Type class provides
sensible defaults for most of them but the most important one
(filter), which means that in most cases all you have to do is:
.. code-block:: python
def filter(x, strict = False):
...
mytype = theano.gof.Type()
mytype.filter = filter
Another way to make a new Type is to subclass Type:
.. code-block:: python
class MyType(theano.gof.Type):
def filter(self, x, strict = False):
...
mytype = MyType()
The issue with defining a new Type like this is that all instances of
MyType are technically the same Type since they filter in the same
way. This is relevant because Theano often compares Types using ``==``
to see if they are the same - for example, if the inputs of two
different :ref:`applications <apply>` have the same Types and that the
operation applied on them is the same, they can be :term:`merged
<merge>`. The workarounds are to define ``MyType.__eq__`` so that all
instances of MyType are equal *or* to override ``MyType.__new__`` to
always return the same instance *or* to hide MyType and only publish a
single instance of it.
doc/tutorials/basic/adding.txt
浏览文件 @
13d6527e
...
@@ -125,7 +125,7 @@ array([[ 2., 2., 2., 2., 2.],
...
@@ -125,7 +125,7 @@ array([[ 2., 2., 2., 2., 2.],
It is possible to add scalars to matrices, vectors to matrices,
It is possible to add scalars to matrices, vectors to matrices,
scalars to vectors, etc. The behavior of these operations is defined
scalars to vectors, etc. The behavior of these operations is defined
by
broadcasting_
.
by
:term:`broadcasting`
.
The following types are readily available:
The following types are readily available:
...
@@ -153,5 +153,4 @@ types compatible with numpy arrays may be found :ref:`here
...
@@ -153,5 +153,4 @@ types compatible with numpy arrays may be found :ref:`here
**Next:** `More examples`_
**Next:** `More examples`_
.. _broadcasting: ../concepts/broadcasting.html
.. _More examples: examples.html
.. _More examples: examples.html
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论