Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6137418f
提交
6137418f
authored
3月 22, 2017
作者:
notoraptor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Mention Wrapper into `Using Op Params` tutorial.
Update Wrapper doc.
上级
f46b2c0d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
29 行增加
和
17 行删除
+29
-17
using_params.txt
doc/extending/using_params.txt
+4
-2
wrapper.py
theano/gof/wrapper.py
+25
-15
没有找到文件。
doc/extending/using_params.txt
浏览文件 @
6137418f
...
...
@@ -73,8 +73,10 @@ attribute :attr:`params_type` to an instance of your params Type.
.. note::
If you want to have multiple parameters you have to bundle those
inside a single object and use that as the params type.
If you want to have multiple parameters, Theano provides the convenient class
:class:`theano.gof.wrapper.Wrapper` that allows to bundle many parameters into
one object that will be available in both Python (as a Python object) and C code (as a struct).
See :ref:`Wrapper tutorial and API documentation <libdoc_gof_wrapper>` for more infos.
For example if we decide to use an int as the params the following
would be appropriate:
...
...
theano/gof/wrapper.py
浏览文件 @
6137418f
"""
Module for wrapping many
Theano variables into one C struct for op params
.
Module for wrapping many
Op parameters into one object available in both Python and C code
.
This module contains two classes:
The module provides the main public class :class:`Wrapper` that allows to bundle many Theano types
into one parameter type, and an internal convenient class :class:`Wrap` which will be automatically
used to create a Wrap object that is compatible with the Wrapper-defined type.
- :class:`Wrapper`: main class to define the op params type.
- :class:`Wrap`: internal convenient class to create an object that is compatible with Wrapper-defined op params.
The Wrap object will be available in both Python code (as a standard Python object) and C code
(as a specific struct with parameters as struct fields). To be fully-available in C code, Theano
types wrapped into Wrapper must provide a C interface (e.g. TensorType, Scalar, GpuArrayType,
or your own type. See :ref:`extending_op_params` for more details).
Example of usage
----------------
...
...
@@ -13,23 +17,29 @@ Importation:
.. code-block:: python
# Import wrapper class.
from theano.gof import Wrapper
# If you want to use a tensor and a scalar as parameters,
# you should import required Theano types.
from theano.tensor import TensorType
from theano.scalar import Scalar
In an op you create:
.. code-block:: python
from theano.tensor import TensorType, dmatrix
params_type = Wrapper(attr1=TensorType('int32', (False, False)), attr2=dmatrix)
params_type = Wrapper(attr1=TensorType('int32', (False, False)), attr2=Scalar('float64'))
If your op contains props ``attr1`` *and* ``attr2``, the default ``op.get_params()`` implementation
will automatically try to look for it and generate an appropriate wrapped struct.
Props must be compatible with the corresponding types defined into the Wrapper
(we will try to convert and downcast if needed).
If your op contains attributes ``attr1`` **and** ``attr2``, the default ``op.get_params()``
implementation will automatically try to look for it and generate an appropriate Wrap object.
Attributes must be compatible with the corresponding types defined into the Wrapper
(we will try to convert and downcast if needed). For example, ``your_op.attr1``
should be a matrix of integers, and ``your_op.attr2``
should be a real number (integer or floating value).
.. code-block:: python
__props__ = ('attr1', 'attr2')
def __init__(value_attr1, value_attr2):
self.attr1 = value_attr1
self.attr2 = value_attr2
...
...
@@ -38,15 +48,15 @@ In ``perform()`` implementation (with params named ``param``):
.. code-block:: python
var1
= param.attr1
var2
= param.attr2
matrix_param
= param.attr1
number_param
= param.attr2
In ``c_code()`` implementation (with ``param = sub['params']``):
.. code-block:: c
PyArrayObject*
attr1
= param->attr1;
PyArrayObject* attr2
= param->attr2;
PyArrayObject*
matrix
= param->attr1;
npy_float64 number
= param->attr2;
/* You won't need to free them or whatever else. */
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论