Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
01967609
提交
01967609
authored
3月 03, 2010
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix indentation, tabs and trailing spaces
上级
24a4cfc1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
26 行增加
和
26 行删除
+26
-26
module.py
theano/compile/module.py
+26
-26
没有找到文件。
theano/compile/module.py
浏览文件 @
01967609
...
@@ -253,7 +253,7 @@ class Method(Component):
...
@@ -253,7 +253,7 @@ class Method(Component):
If this method should update the shared storage value for a Module member, then the
If this method should update the shared storage value for a Module member, then the
update expression must be given in this dictionary.
update expression must be given in this dictionary.
Keys in this dictionary must be members of the module graph--variables for which this Method
Keys in this dictionary must be members of the module graph--variables for which this Method
will use the shared storage.
will use the shared storage.
...
@@ -261,7 +261,7 @@ class Method(Component):
...
@@ -261,7 +261,7 @@ class Method(Component):
The value associated with each key should be a Variable (or a string that can be resolved to
The value associated with each key should be a Variable (or a string that can be resolved to
a Variable) representing the computation of a new value for this shared storage after
a Variable) representing the computation of a new value for this shared storage after
each function call.
each function call.
"""
"""
mode
=
None
mode
=
None
...
@@ -320,10 +320,10 @@ class Method(Component):
...
@@ -320,10 +320,10 @@ class Method(Component):
if
isinstance
(
self
.
outputs
,
(
io
.
Out
,
gof
.
Variable
,
str
,
type
(
None
))):
if
isinstance
(
self
.
outputs
,
(
io
.
Out
,
gof
.
Variable
,
str
,
type
(
None
))):
output
=
self
.
outputs
output
=
self
.
outputs
self
.
outputs
=
resolve_variable
(
output
,
self
.
outputs
=
resolve_variable
(
output
,
passthrough
=
(
gof
.
Variable
,
io
.
Out
,
type
(
None
)))
passthrough
=
(
gof
.
Variable
,
io
.
Out
,
type
(
None
)))
else
:
else
:
outputs
=
list
(
self
.
outputs
)
outputs
=
list
(
self
.
outputs
)
self
.
outputs
=
[
resolve_variable
(
output
,
self
.
outputs
=
[
resolve_variable
(
output
,
passthrough
=
(
gof
.
Variable
,
io
.
Out
))
for
output
in
outputs
]
passthrough
=
(
gof
.
Variable
,
io
.
Out
))
for
output
in
outputs
]
def
resolve_updates
():
def
resolve_updates
():
...
@@ -370,10 +370,10 @@ class Method(Component):
...
@@ -370,10 +370,10 @@ class Method(Component):
' Verify that it is indeed a Member of the'
' Verify that it is indeed a Member of the'
' enclosing module or of one of its submodules.'
%
(
r
,
self
.
name
,
self
))
' enclosing module or of one of its submodules.'
%
(
r
,
self
.
name
,
self
))
else
:
else
:
return
io
.
In
(
variable
=
r
,
return
io
.
In
(
variable
=
r
,
value
=
gof
.
Container
(
r
,
value
=
gof
.
Container
(
r
,
storage
=
[
getattr
(
r
,
'data'
,
None
)],
storage
=
[
getattr
(
r
,
'data'
,
None
)],
readonly
=
(
isinstance
(
r
,
gof
.
Constant
))),
readonly
=
(
isinstance
(
r
,
gof
.
Constant
))),
mutable
=
False
)
mutable
=
False
)
inputs
=
self
.
inputs
inputs
=
self
.
inputs
...
@@ -432,9 +432,9 @@ class Method(Component):
...
@@ -432,9 +432,9 @@ class Method(Component):
else
:
else
:
outputs_list
=
[
outputs
]
outputs_list
=
[
outputs
]
#backport
#backport
#outputs_list = [] if outputs is None else (list(outputs) if isinstance(outputs, (list, tuple)) else [outputs])
#outputs_list = [] if outputs is None else (list(outputs) if isinstance(outputs, (list, tuple)) else [outputs])
outputs_variable_list
=
[]
outputs_variable_list
=
[]
for
o
in
outputs_list
:
for
o
in
outputs_list
:
if
isinstance
(
o
,
io
.
Out
):
if
isinstance
(
o
,
io
.
Out
):
...
@@ -459,7 +459,7 @@ class Method(Component):
...
@@ -459,7 +459,7 @@ class Method(Component):
#the user is allowed to change this value between function calls if it isn't a constant
#the user is allowed to change this value between function calls if it isn't a constant
assert
container
.
readonly
==
(
isinstance
(
input
,
gof
.
Constant
))
assert
container
.
readonly
==
(
isinstance
(
input
,
gof
.
Constant
))
#the function is not allowed to change this value
#the function is not allowed to change this value
assert
storage
.
mutable
==
False
assert
storage
.
mutable
==
False
else
:
else
:
storage
=
get_storage
(
input
,
not
allocate_all
)
storage
=
get_storage
(
input
,
not
allocate_all
)
...
@@ -490,13 +490,13 @@ class Method(Component):
...
@@ -490,13 +490,13 @@ class Method(Component):
else
:
else
:
rval
=
''
rval
=
''
if
isinstance
(
self
.
outputs
,
(
list
,
tuple
)):
if
isinstance
(
self
.
outputs
,
(
list
,
tuple
)):
inputs
,
outputs
,
updates
=
self
.
inputs
,
self
.
outputs
inputs
,
outputs
,
updates
=
self
.
inputs
,
self
.
outputs
else
:
else
:
inputs
,
outputs
,
updates
=
[
self
.
outputs
],
self
.
updates
inputs
,
outputs
,
updates
=
[
self
.
outputs
],
self
.
updates
#backport
#backport
#inputs, outputs, updates = self.inputs, self.outputs if isinstance(self.outputs, (list, tuple)) else [self.outputs], self.updates
#inputs, outputs, updates = self.inputs, self.outputs if isinstance(self.outputs, (list, tuple)) else [self.outputs], self.updates
# If mode is in kwargs, prints the optimized version of the method
# If mode is in kwargs, prints the optimized version of the method
mode
=
kwargs
.
pop
(
'mode'
,
None
)
mode
=
kwargs
.
pop
(
'mode'
,
None
)
if
mode
:
if
mode
:
...
@@ -599,7 +599,7 @@ class Composite(Component):
...
@@ -599,7 +599,7 @@ class Composite(Component):
hierarchy of composites and components, where path is a
hierarchy of composites and components, where path is a
sequence of keys such that
sequence of keys such that
component is self[path[0]][path[1]]...
component is self[path[0]][path[1]]...
If include_self is True, the list will include the Composite
If include_self is True, the list will include the Composite
instances, else it will only yield the list of leaves.
instances, else it will only yield the list of leaves.
"""
"""
...
@@ -625,7 +625,7 @@ class Composite(Component):
...
@@ -625,7 +625,7 @@ class Composite(Component):
Get the Component associated to the key.
Get the Component associated to the key.
"""
"""
raise
NotImplementedError
raise
NotImplementedError
def
set
(
self
,
item
,
value
):
def
set
(
self
,
item
,
value
):
"""
"""
Set the Component associated to the key.
Set the Component associated to the key.
...
@@ -639,7 +639,7 @@ class Composite(Component):
...
@@ -639,7 +639,7 @@ class Composite(Component):
if
isinstance
(
x
,
(
External
,
Member
)):
if
isinstance
(
x
,
(
External
,
Member
)):
return
x
.
r
return
x
.
r
return
x
return
x
def
__setitem__
(
self
,
item
,
value
):
def
__setitem__
(
self
,
item
,
value
):
# Uses set() internally
# Uses set() internally
self
.
set
(
item
,
value
)
self
.
set
(
item
,
value
)
...
@@ -648,11 +648,11 @@ class Composite(Component):
...
@@ -648,11 +648,11 @@ class Composite(Component):
retval
=
[]
retval
=
[]
for
c
in
self
.
components
():
for
c
in
self
.
components
():
if
isinstance
(
c
,
(
External
,
Member
)):
if
isinstance
(
c
,
(
External
,
Member
)):
retval
+=
[
c
.
r
]
retval
+=
[
c
.
r
]
else
:
else
:
retval
+=
[
c
]
retval
+=
[
c
]
return
retval
return
retval
#backport
#backport
#return (c.r if isinstance(c, (External, Member)) else c for c in self.components())
#return (c.r if isinstance(c, (External, Member)) else c for c in self.components())
...
@@ -774,7 +774,7 @@ class ComponentDictInstanceNoInit(CompositeInstance):
...
@@ -774,7 +774,7 @@ class ComponentDictInstanceNoInit(CompositeInstance):
self
.
__items__
[
item
]
=
value
self
.
__items__
[
item
]
=
value
else
:
else
:
super
(
ComponentDictInstanceNoInit
,
self
)
.
__setitem__
(
item
,
value
)
super
(
ComponentDictInstanceNoInit
,
self
)
.
__setitem__
(
item
,
value
)
def
__str__
(
self
):
def
__str__
(
self
):
strings
=
[]
strings
=
[]
for
k
,
v
in
sorted
(
self
.
__items__
.
iteritems
()):
for
k
,
v
in
sorted
(
self
.
__items__
.
iteritems
()):
...
@@ -832,7 +832,7 @@ class ComponentDict(Composite):
...
@@ -832,7 +832,7 @@ class ComponentDict(Composite):
def
set
(
self
,
item
,
value
):
def
set
(
self
,
item
,
value
):
if
not
isinstance
(
value
,
Component
):
if
not
isinstance
(
value
,
Component
):
msg
=
"""
msg
=
"""
ComponentDict may only contain Components.
ComponentDict may only contain Components.
(Hint: maybe value here needs to be wrapped, see theano.compile.module.register_wrapper.)"""
(Hint: maybe value here needs to be wrapped, see theano.compile.module.register_wrapper.)"""
raise
TypeError
(
msg
,
value
,
type
(
value
))
raise
TypeError
(
msg
,
value
,
type
(
value
))
#value = value.bind(self, item)
#value = value.bind(self, item)
...
@@ -944,7 +944,7 @@ class Curry:
...
@@ -944,7 +944,7 @@ class Curry:
def
__setstate__
(
self
,
state
):
def
__setstate__
(
self
,
state
):
self
.
obj
,
self
.
name
,
self
.
arg
=
state
self
.
obj
,
self
.
name
,
self
.
arg
=
state
self
.
meth
=
getattr
(
self
.
obj
,
self
.
name
)
self
.
meth
=
getattr
(
self
.
obj
,
self
.
name
)
class
ModuleInstance
(
ComponentDictInstanceNoInit
):
class
ModuleInstance
(
ComponentDictInstanceNoInit
):
"""
"""
...
@@ -973,19 +973,19 @@ class ModuleInstance(ComponentDictInstanceNoInit):
...
@@ -973,19 +973,19 @@ class ModuleInstance(ComponentDictInstanceNoInit):
class
Module
(
ComponentDict
):
class
Module
(
ComponentDict
):
"""WRITEME
"""WRITEME
You should inherit from Module with the members will be other Modules or Components. To
You should inherit from Module with the members will be other Modules or Components. To
make more specialized elements of a Module graph, consider inheriting from Component
make more specialized elements of a Module graph, consider inheriting from Component
directly.
directly.
"""
"""
InstanceType
=
ModuleInstance
# By default, we use build ModuleInstance
InstanceType
=
ModuleInstance
# By default, we use build ModuleInstance
def
__init__
(
self
,
*
args
,
**
kw
):
def
__init__
(
self
,
*
args
,
**
kw
):
super
(
Module
,
self
)
.
__init__
(
*
args
,
**
kw
)
super
(
Module
,
self
)
.
__init__
(
*
args
,
**
kw
)
self
.
__dict__
[
"local_attr"
]
=
{}
self
.
__dict__
[
"local_attr"
]
=
{}
self
.
__dict__
[
"_components"
]
=
{}
self
.
__dict__
[
"_components"
]
=
{}
def
__wrapper__
(
self
,
x
):
def
__wrapper__
(
self
,
x
):
"""
"""
This function is called whenever x is set as an attribute of
This function is called whenever x is set as an attribute of
...
@@ -1090,7 +1090,7 @@ class Module(ComponentDict):
...
@@ -1090,7 +1090,7 @@ class Module(ComponentDict):
"""
"""
Module's __setattr__ method hides all members under local_attr. This
Module's __setattr__ method hides all members under local_attr. This
method iterates over those elements and wraps them so they can be used
method iterates over those elements and wraps them so they can be used
in a computation graph. The "wrapped" members are then set as object
in a computation graph. The "wrapped" members are then set as object
attributes accessible through the dotted notation syntax (<module_name>
attributes accessible through the dotted notation syntax (<module_name>
<dot> <member_name>). Submodules are handled recursively.
<dot> <member_name>). Submodules are handled recursively.
"""
"""
...
@@ -1111,7 +1111,7 @@ class Module(ComponentDict):
...
@@ -1111,7 +1111,7 @@ class Module(ComponentDict):
sv
=
sv
.
make_module_instance
(
args
,
kwargs
)
sv
=
sv
.
make_module_instance
(
args
,
kwargs
)
v
[
sk
]
=
sv
v
[
sk
]
=
sv
return
v
return
v
for
k
,
v
in
self
.
local_attr
.
iteritems
():
for
k
,
v
in
self
.
local_attr
.
iteritems
():
if
isinstance
(
v
,
Module
):
if
isinstance
(
v
,
Module
):
v
=
v
.
make_module_instance
(
args
,
kwargs
)
v
=
v
.
make_module_instance
(
args
,
kwargs
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论