Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1e997826
提交
1e997826
authored
4月 03, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
a little more documentation for the module.register_wrapper mechanism
上级
9b9602c6
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
30 行增加
和
10 行删除
+30
-10
module.txt
doc/advanced/module.txt
+9
-7
module.py
theano/compile/module.py
+21
-3
没有找到文件。
doc/advanced/module.txt
浏览文件 @
1e997826
...
@@ -54,6 +54,7 @@ non-symbolic thing.
...
@@ -54,6 +54,7 @@ non-symbolic thing.
Compiling with make
Compiling with make
-------------------
-------------------
Conversion from a Component graph to a ComponentInstance graph is performed by `Component.make`.
Conversion from a Component graph to a ComponentInstance graph is performed by `Component.make`.
This method traverses the Component graph in multiple passes.
This method traverses the Component graph in multiple passes.
...
@@ -77,7 +78,6 @@ allocated in phase 1 with sensible values.
...
@@ -77,7 +78,6 @@ allocated in phase 1 with sensible values.
single: component; External
single: component; External
.. _external:
.. _external:
--------
--------
External
External
--------
--------
...
@@ -91,7 +91,6 @@ WRITEME
...
@@ -91,7 +91,6 @@ WRITEME
single: component; Member
single: component; Member
.. _member:
.. _member:
------
------
Member
Member
------
------
...
@@ -104,7 +103,6 @@ WRITEME
...
@@ -104,7 +103,6 @@ WRITEME
single: component; Method
single: component; Method
.. _method:
.. _method:
------
------
Method
Method
------
------
...
@@ -117,13 +115,17 @@ WRITEME
...
@@ -117,13 +115,17 @@ WRITEME
single: component; Module
single: component; Module
.. _module:
.. _module:
------
------
Module
Module
------
------
WRITEME
A Module instance can contain objects as attributes.
This makes it something like a class in the way that Method is
analogous to a function.
A Module is meant to contain Components.
Attributes which are not Components themselves must at least be transform-able
into Components by :api:`compile.module.wrap`. If a Module contains something
that is not convertible into a Component, then it is not possible to compile
that Module with ``make``.
theano/compile/module.py
浏览文件 @
1e997826
...
@@ -771,7 +771,10 @@ class ComponentDict(Composite):
...
@@ -771,7 +771,10 @@ class ComponentDict(Composite):
def
set
(
self
,
item
,
value
):
def
set
(
self
,
item
,
value
):
if
not
isinstance
(
value
,
Component
):
if
not
isinstance
(
value
,
Component
):
raise
TypeError
(
'ComponentDict may only contain Components.'
,
value
,
type
(
value
))
msg
=
"""
ComponentDict may only contain Components.
(Hint: maybe value here needs to be wrapped, see theano.compile.module.register_wrapper.)"""
raise
TypeError
(
msg
,
value
,
type
(
value
))
#value = value.bind(self, item)
#value = value.bind(self, item)
value
.
name
=
name_join
(
self
.
name
,
str
(
item
))
value
.
name
=
name_join
(
self
.
name
,
str
(
item
))
self
.
_components
[
item
]
=
value
self
.
_components
[
item
]
=
value
...
@@ -803,6 +806,16 @@ class ComponentDict(Composite):
...
@@ -803,6 +806,16 @@ class ComponentDict(Composite):
__autowrappers
=
[]
__autowrappers
=
[]
def
register_wrapper
(
condition
,
wrapper
):
def
register_wrapper
(
condition
,
wrapper
):
"""
:type condition: function x -> bool
:param condition: this function should return True iff `wrapper` can sensibly turn x into a
Component.
:type wrapper: function x -> Component
:param wrapper: this function should convert `x` into an instance of a Component subclass.
"""
__autowrappers
.
append
((
condition
,
wrapper
))
__autowrappers
.
append
((
condition
,
wrapper
))
def
wrapper
(
x
):
def
wrapper
(
x
):
...
@@ -816,8 +829,13 @@ def wrapper(x):
...
@@ -816,8 +829,13 @@ def wrapper(x):
def
wrap
(
x
):
def
wrap
(
x
):
"""
"""
Wraps x in a Component. Wrappers can be registered using
Wraps `x` in a `Component`. Wrappers can be registered using
register_wrapper to allow wrapping more types.
`register_wrapper` to allow wrapping more types.
It is necessary for Module attributes to be wrappable.
A Module with an attribute that is not wrappable as a Component, will cause
`Component.make` to fail.
"""
"""
w
=
wrapper
(
x
)
w
=
wrapper
(
x
)
if
w
is
not
None
:
if
w
is
not
None
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论