Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3c440a74
提交
3c440a74
authored
4月 03, 2017
作者:
notoraptor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Secure code.
Optimize Wrap.__hash__.
上级
c81517aa
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
10 行增加
和
5 行删除
+10
-5
op.py
theano/gof/op.py
+2
-1
wrapper.py
theano/gof/wrapper.py
+8
-4
没有找到文件。
theano/gof/op.py
浏览文件 @
3c440a74
...
@@ -801,7 +801,8 @@ class Op(utils.object2, PureOp, CLinkerOp):
...
@@ -801,7 +801,8 @@ class Op(utils.object2, PureOp, CLinkerOp):
def
get_params
(
self
,
node
):
def
get_params
(
self
,
node
):
if
hasattr
(
self
,
'params_type'
)
and
isinstance
(
self
.
params_type
,
theano
.
gof
.
Wrapper
):
if
hasattr
(
self
,
'params_type'
)
and
isinstance
(
self
.
params_type
,
theano
.
gof
.
Wrapper
):
wrapper
=
self
.
params_type
wrapper
=
self
.
params_type
if
all
(
hasattr
(
self
,
field
)
for
field
in
wrapper
.
fields
):
if
not
all
(
hasattr
(
self
,
field
)
for
field
in
wrapper
.
fields
):
raise
AttributeError
(
'
%
s: missing attributes for Wrapper parameter.'
%
type
(
self
)
.
__name__
)
wrap_dict
=
dict
()
wrap_dict
=
dict
()
for
i
in
range
(
wrapper
.
length
):
for
i
in
range
(
wrapper
.
length
):
field
=
wrapper
.
fields
[
i
]
field
=
wrapper
.
fields
[
i
]
...
...
theano/gof/wrapper.py
浏览文件 @
3c440a74
...
@@ -101,7 +101,7 @@ class Wrap(dict):
...
@@ -101,7 +101,7 @@ class Wrap(dict):
if
field
not
in
kwargs
:
if
field
not
in
kwargs
:
raise
TypeError
(
'Wrap: Wrapper attribute "
%
s" not in Wrap args.'
%
field
)
raise
TypeError
(
'Wrap: Wrapper attribute "
%
s" not in Wrap args.'
%
field
)
super
(
Wrap
,
self
)
.
__init__
(
**
kwargs
)
super
(
Wrap
,
self
)
.
__init__
(
**
kwargs
)
self
.
__dict__
.
update
(
wrapper
=
wrapper
)
self
.
__dict__
.
update
(
wrapper
=
wrapper
,
signatures
=
None
)
def
__repr__
(
self
):
def
__repr__
(
self
):
return
'Wrap(
%
s)'
%
', '
.
join
([(
'
%
s:
%
s'
%
(
k
,
type
(
self
[
k
])))
for
k
in
sorted
(
self
.
keys
())])
return
'Wrap(
%
s)'
%
', '
.
join
([(
'
%
s:
%
s'
%
(
k
,
type
(
self
[
k
])))
for
k
in
sorted
(
self
.
keys
())])
...
@@ -121,11 +121,15 @@ class Wrap(dict):
...
@@ -121,11 +121,15 @@ class Wrap(dict):
raise
NotImplementedError
(
'Wrap is immutable'
)
raise
NotImplementedError
(
'Wrap is immutable'
)
def
__hash__
(
self
):
def
__hash__
(
self
):
return
hash
((
type
(
self
),
self
.
wrapper
)
+
tuple
(
# As values are immutable, we can save data signatures the first time
# to not regenerate them in future hash() calls.
if
self
.
__dict__
[
'signatures'
]
is
None
:
self
.
__dict__
[
'signatures'
]
=
tuple
(
# NB: Wrapped data should have been already filtered.
# NB: Wrapped data should have been already filtered.
self
.
wrapper
.
types
[
i
]
.
make_constant
(
self
[
self
.
wrapper
.
fields
[
i
]])
.
signature
()
self
.
wrapper
.
types
[
i
]
.
make_constant
(
self
[
self
.
wrapper
.
fields
[
i
]])
.
signature
()
for
i
in
range
(
self
.
wrapper
.
length
)
for
i
in
range
(
self
.
wrapper
.
length
)
))
)
return
hash
((
type
(
self
),
self
.
wrapper
)
+
self
.
signatures
)
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
==
type
(
other
)
and
self
.
wrapper
==
other
.
wrapper
and
all
(
return
(
type
(
self
)
==
type
(
other
)
and
self
.
wrapper
==
other
.
wrapper
and
all
(
...
@@ -210,7 +214,7 @@ class Wrapper(Type):
...
@@ -210,7 +214,7 @@ class Wrapper(Type):
wrap_instance
=
dict
()
wrap_instance
=
dict
()
for
i
in
range
(
self
.
length
):
for
i
in
range
(
self
.
length
):
wrap_instance
[
self
.
fields
[
i
]]
=
self
.
types
[
i
]
.
filter
(
getattr
(
data
,
self
.
fields
[
i
]),
strict
,
allow_downcast
)
wrap_instance
[
self
.
fields
[
i
]]
=
self
.
types
[
i
]
.
filter
(
getattr
(
data
,
self
.
fields
[
i
]),
strict
,
allow_downcast
)
return
data
if
strict
else
Wrap
(
self
,
**
wrap_instance
)
return
data
if
(
strict
or
isinstance
(
data
,
Wrap
))
else
Wrap
(
self
,
**
wrap_instance
)
# Returns a wrapped object with expected attributes or (in strict mode) checks that data has expected attributes.
# Returns a wrapped object with expected attributes or (in strict mode) checks that data has expected attributes.
def
filter
(
self
,
data
,
strict
=
False
,
allow_downcast
=
None
):
def
filter
(
self
,
data
,
strict
=
False
,
allow_downcast
=
None
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论