Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d0e4dfc1
提交
d0e4dfc1
authored
11月 21, 2020
作者:
Brandon T. Willard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename _metadict to AssocList and move it to theano.gof.utils
上级
9bbaf30a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
77 行增加
和
80 行删除
+77
-80
opt.py
theano/gof/opt.py
+5
-80
utils.py
theano/gof/utils.py
+72
-0
没有找到文件。
theano/gof/opt.py
浏览文件 @
d0e4dfc1
...
@@ -21,8 +21,9 @@ import numpy as np
...
@@ -21,8 +21,9 @@ import numpy as np
import
theano
import
theano
from
theano
import
config
from
theano
import
config
from
theano.gof
import
graph
,
op
,
toolbox
,
unify
,
utils
from
theano.gof
import
graph
,
op
,
toolbox
,
unify
from
theano.gof.fg
import
InconsistencyError
from
theano.gof.fg
import
InconsistencyError
from
theano.gof.utils
import
AssocList
,
flatten
from
theano.misc.ordered_set
import
OrderedSet
from
theano.misc.ordered_set
import
OrderedSet
from
.
import
destroyhandler
as
dh
from
.
import
destroyhandler
as
dh
...
@@ -95,7 +96,6 @@ class GlobalOptimizer(abc.ABC):
...
@@ -95,7 +96,6 @@ class GlobalOptimizer(abc.ABC):
etc.
etc.
"""
"""
pass
def
print_summary
(
self
,
stream
=
sys
.
stdout
,
level
=
0
,
depth
=-
1
):
def
print_summary
(
self
,
stream
=
sys
.
stdout
,
level
=
0
,
depth
=-
1
):
name
=
getattr
(
self
,
"name"
,
None
)
name
=
getattr
(
self
,
"name"
,
None
)
...
@@ -451,80 +451,6 @@ class SeqOptimizer(GlobalOptimizer, UserList):
...
@@ -451,80 +451,6 @@ class SeqOptimizer(GlobalOptimizer, UserList):
)
)
class
_metadict
:
"""
WRITEME
"""
# dict that accepts unhashable keys
# uses an associative list
# for internal use only
def
__init__
(
self
):
self
.
_dict
=
{}
self
.
_list
=
[]
def
__getitem__
(
self
,
item
):
return
self
.
get
(
item
,
None
)
def
__setitem__
(
self
,
item
,
value
):
try
:
self
.
_dict
[
item
]
=
value
except
Exception
:
for
i
,
(
key
,
val
)
in
enumerate
(
self
.
_list
):
if
key
==
item
:
self
.
_list
[
i
]
=
(
item
,
value
)
return
self
.
_list
.
append
((
item
,
value
))
def
__delitem__
(
self
,
item
):
try
:
if
item
in
self
.
_dict
:
del
self
.
_dict
[
item
]
return
except
TypeError
as
e
:
assert
"unhashable type"
in
str
(
e
)
for
i
,
(
key
,
val
)
in
enumerate
(
self
.
_list
):
if
key
==
item
:
del
self
.
_list
[
i
]
return
raise
KeyError
(
item
)
def
discard
(
self
,
item
):
try
:
if
item
in
self
.
_dict
:
del
self
.
_dict
[
item
]
return
except
TypeError
as
e
:
assert
"unhashable type"
in
str
(
e
)
for
i
,
(
key
,
val
)
in
enumerate
(
self
.
_list
):
if
key
==
item
:
del
self
.
_list
[
i
]
return
def
get
(
self
,
item
,
default
):
try
:
return
self
.
_dict
[
item
]
except
Exception
:
for
item2
,
value
in
self
.
_list
:
try
:
if
item
==
item2
:
return
value
if
item
.
equals
(
item2
):
return
value
except
Exception
:
if
item
is
item2
:
return
value
return
default
def
clear
(
self
):
self
.
_dict
=
{}
self
.
_list
=
[]
def
__str__
(
self
):
return
f
"({self._dict}, {self._list})"
class
MergeFeature
:
class
MergeFeature
:
"""
"""
Keeps track of variables in fgraph that cannot be merged together.
Keeps track of variables in fgraph that cannot be merged together.
...
@@ -541,9 +467,9 @@ class MergeFeature:
...
@@ -541,9 +467,9 @@ class MergeFeature:
# For constants
# For constants
self
.
seen_constants
=
set
()
self
.
seen_constants
=
set
()
# variable -> signature (for constants)
# variable -> signature (for constants)
self
.
const_sig
=
_metadic
t
()
self
.
const_sig
=
AssocLis
t
()
# signature -> variable (for constants)
# signature -> variable (for constants)
self
.
const_sig_inv
=
_metadic
t
()
self
.
const_sig_inv
=
AssocLis
t
()
# For all Apply nodes
# For all Apply nodes
# Set of distinct (not mergeable) nodes
# Set of distinct (not mergeable) nodes
...
@@ -906,7 +832,7 @@ class MergeOptimizer(GlobalOptimizer):
...
@@ -906,7 +832,7 @@ class MergeOptimizer(GlobalOptimizer):
if
(
if
(
sum
(
sum
(
[
[
i
in
utils
.
flatten
(
c
.
op
.
destroy_map
.
values
())
i
in
flatten
(
c
.
op
.
destroy_map
.
values
())
for
c
,
i
in
clients
for
c
,
i
in
clients
if
c
!=
"output"
and
hasattr
(
c
.
op
,
"destroy_map"
)
if
c
!=
"output"
and
hasattr
(
c
.
op
,
"destroy_map"
)
]
]
...
@@ -1143,7 +1069,6 @@ class LocalOptimizer(abc.ABC):
...
@@ -1143,7 +1069,6 @@ class LocalOptimizer(abc.ABC):
fgraph, this is the place to do it.
fgraph, this is the place to do it.
"""
"""
pass
def
print_summary
(
self
,
stream
=
sys
.
stdout
,
level
=
0
,
depth
=-
1
):
def
print_summary
(
self
,
stream
=
sys
.
stdout
,
level
=
0
,
depth
=-
1
):
print
(
f
"{' ' * level}{self.__class_.__name__} id={id(self)}"
,
file
=
stream
)
print
(
f
"{' ' * level}{self.__class_.__name__} id={id(self)}"
,
file
=
stream
)
...
...
theano/gof/utils.py
浏览文件 @
d0e4dfc1
...
@@ -284,6 +284,78 @@ class D:
...
@@ -284,6 +284,78 @@ class D:
self
.
__dict__
.
update
(
d
)
self
.
__dict__
.
update
(
d
)
class
AssocList
:
"""An associative list.
This class is like a `dict` that accepts unhashable keys by using an
assoc list for internal use only
"""
def
__init__
(
self
):
self
.
_dict
=
{}
self
.
_list
=
[]
def
__getitem__
(
self
,
item
):
return
self
.
get
(
item
,
None
)
def
__setitem__
(
self
,
item
,
value
):
try
:
self
.
_dict
[
item
]
=
value
except
Exception
:
for
i
,
(
key
,
val
)
in
enumerate
(
self
.
_list
):
if
key
==
item
:
self
.
_list
[
i
]
=
(
item
,
value
)
return
self
.
_list
.
append
((
item
,
value
))
def
__delitem__
(
self
,
item
):
try
:
if
item
in
self
.
_dict
:
del
self
.
_dict
[
item
]
return
except
TypeError
as
e
:
assert
"unhashable type"
in
str
(
e
)
for
i
,
(
key
,
val
)
in
enumerate
(
self
.
_list
):
if
key
==
item
:
del
self
.
_list
[
i
]
return
raise
KeyError
(
item
)
def
discard
(
self
,
item
):
try
:
if
item
in
self
.
_dict
:
del
self
.
_dict
[
item
]
return
except
TypeError
as
e
:
assert
"unhashable type"
in
str
(
e
)
for
i
,
(
key
,
val
)
in
enumerate
(
self
.
_list
):
if
key
==
item
:
del
self
.
_list
[
i
]
return
def
get
(
self
,
item
,
default
):
try
:
return
self
.
_dict
[
item
]
except
Exception
:
for
item2
,
value
in
self
.
_list
:
try
:
if
item
==
item2
:
return
value
if
item
.
equals
(
item2
):
return
value
except
Exception
:
if
item
is
item2
:
return
value
return
default
def
clear
(
self
):
self
.
_dict
=
{}
self
.
_list
=
[]
def
__repr__
(
self
):
return
f
"AssocList({self._dict}, {self._list})"
def
memoize
(
f
):
def
memoize
(
f
):
"""
"""
Cache the return value for each tuple of arguments (which must be hashable).
Cache the return value for each tuple of arguments (which must be hashable).
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论