Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6da09d81
提交
6da09d81
authored
4月 01, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
updated getattr and setattr in Module
上级
e80036df
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
47 行增加
和
36 行删除
+47
-36
module.py
theano/compile/module.py
+47
-36
没有找到文件。
theano/compile/module.py
浏览文件 @
6da09d81
...
@@ -970,6 +970,8 @@ class Module(ComponentDict):
...
@@ -970,6 +970,8 @@ class Module(ComponentDict):
def
__init__
(
self
):
def
__init__
(
self
):
super
(
Module
,
self
)
.
__init__
()
super
(
Module
,
self
)
.
__init__
()
self
.
__dict__
[
"local_attr"
]
=
{}
self
.
__dict__
[
"local_attr"
]
=
{}
self
.
__dict__
[
"_components"
]
=
{}
def
__wrapper__
(
self
,
x
):
def
__wrapper__
(
self
,
x
):
"""
"""
...
@@ -978,7 +980,47 @@ class Module(ComponentDict):
...
@@ -978,7 +980,47 @@ class Module(ComponentDict):
"""
"""
return
wrap
(
x
)
return
wrap
(
x
)
def
__getattr__
(
self
,
attr
):
def
__setattr__
(
self
,
attr
,
value
):
# a is a new attribute
# we will use the local_attr dict to store it
v
=
self
.
unpack_member_and_external
(
value
)
# this __setattr__ function overrides property.__set__, so we don't worry about a
# setter here
self
.
__dict__
[
attr
]
=
v
self
.
__dict__
[
"local_attr"
][
attr
]
=
v
@staticmethod
def
unpack_member_and_external
(
v
):
if
isinstance
(
v
,
Member
):
print
>>
sys
.
stderr
,
(
"WARNING: assignment of Member "
"object
%
s (either directly or indirectly) to Module "
"is deprecated. Just use Variable."
%
v
)
return
v
.
r
elif
isinstance
(
v
,
External
):
print
>>
sys
.
stderr
,
(
"WARNING: assignment of External "
"object
%
s (either directly or indirectly) to Module "
"is deprecated. Just use Variable."
%
v
)
return
v
.
r
elif
isinstance
(
v
,
(
gof
.
Variable
,
Method
,
Module
)):
return
v
elif
isinstance
(
v
,(
int
,
bool
)):
return
v
elif
isinstance
(
v
,
(
list
)):
return
map
(
Module
.
unpack_member_and_external
,
v
)
elif
isinstance
(
v
,
(
tuple
)):
return
tuple
(
map
(
Module
.
unpack_member_and_external
,
v
))
elif
isinstance
(
v
,
dict
):
v_copy
=
dict
()
for
k
,
vv
in
v
.
iteritems
():
v_copy
[
k
]
=
Module
.
unpack_member_and_external
(
vv
)
return
v
else
:
# raise NotImplementedError
# print "WARNING: unknow:",v
return
v
def
old__getattr__
(
self
,
attr
):
if
attr
==
'_components'
and
'_components'
not
in
self
.
__dict__
:
if
attr
==
'_components'
and
'_components'
not
in
self
.
__dict__
:
self
.
__dict__
[
'_components'
]
=
{}
self
.
__dict__
[
'_components'
]
=
{}
try
:
try
:
...
@@ -987,44 +1029,13 @@ class Module(ComponentDict):
...
@@ -987,44 +1029,13 @@ class Module(ComponentDict):
raise
AttributeError
(
'
%
s has no
%
s attribute.'
%
(
self
.
__class__
,
attr
))
raise
AttributeError
(
'
%
s has no
%
s attribute.'
%
(
self
.
__class__
,
attr
))
return
rval
return
rval
def
__setattr__
(
self
,
attr
,
value
):
def
old__setattr__
(
self
,
attr
,
value
):
"""
"""
if
attr
in
(
'parent'
,
'_components'
):
if
attr
in
(
'parent'
,
'_components'
):
self
.
__dict__
[
attr
]
=
value
self
.
__dict__
[
attr
]
=
value
return
return
elif
attr
==
'name'
:
self
.
__dict__
[
"local_attr"
][
attr
]
=
self
.
unpack_member_and_external
(
value
)
self
.
__set_name__
(
value
)
return
def
unpack_member_and_external
(
v
):
if
isinstance
(
v
,
Member
):
print
>>
sys
.
stderr
,
(
"WARNING: assignment of Member "
"object
%
s (either directly or indirectly) to Module "
"is deprecated. Just use Variable."
%
v
)
return
v
.
r
elif
isinstance
(
v
,
External
):
print
>>
sys
.
stderr
,
(
"WARNING: assignment of External "
"object
%
s (either directly or indirectly) to Module "
"is deprecated. Just use Variable."
%
v
)
return
v
.
r
elif
isinstance
(
v
,
(
gof
.
Variable
,
Method
,
Module
)):
return
v
elif
isinstance
(
v
,(
int
,
bool
)):
return
v
elif
isinstance
(
v
,
(
list
)):
return
map
(
unpack_member_and_external
,
v
)
elif
isinstance
(
v
,
(
tuple
)):
return
tuple
(
map
(
unpack_member_and_external
,
v
))
elif
isinstance
(
v
,
dict
):
v_copy
=
dict
()
for
k
,
vv
in
v
.
iteritems
():
v_copy
[
k
]
=
unpack_member_and_external
(
vv
)
return
v
else
:
# raise NotImplementedError
# print "WARNING: unknow:",v
return
v
self
.
__dict__
[
"local_attr"
][
attr
]
=
unpack_member_and_external
(
value
)
def
build
(
self
,
mode
,
memo
):
def
build
(
self
,
mode
,
memo
):
if
self
in
memo
:
if
self
in
memo
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论