Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d4e705ea
提交
d4e705ea
authored
2月 22, 2008
作者:
bergstrj@iro.umontreal.ca
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
minor fixes, working on producer in build mode... getting state right
上级
32249295
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
55 行增加
和
29 行删除
+55
-29
core.py
core.py
+0
-0
__init__.py
gof/__init__.py
+1
-10
lib.py
gof/lib.py
+5
-4
result.py
gof/result.py
+48
-14
grad.py
grad.py
+1
-1
没有找到文件。
core.py
浏览文件 @
d4e705ea
差异被折叠。
点击展开。
gof/__init__.py
浏览文件 @
d4e705ea
# from op import *
# from value import *
# from opt import *
# from env import *
# from prog import *
# from diff import *
# import dispatchers
import
op
,
ext
,
lib
,
link
,
result
,
env
,
prog
,
features
,
opt
,
graph
from
op
import
*
from
ext
import
*
...
...
@@ -18,5 +11,3 @@ from features import *
from
opt
import
*
import
graph
#import utils
gof/lib.py
浏览文件 @
d4e705ea
...
...
@@ -44,6 +44,8 @@ def compute_from(nodes, history):
if
hasattr
(
node
,
'owner'
):
#node is storage
compute_recursive
(
node
.
owner
)
else
:
#node is op
if
node
.
destroy_map
():
raise
ValueError
(
'compute_from() does not work on nodes with destroy_maps'
)
for
input
in
node
.
inputs
:
compute_recursive
(
input
)
node
.
perform
()
...
...
@@ -95,8 +97,6 @@ class ForbidConstantOverwrite(features.Listener, features.Constraint):
else
:
return
True
class
DestroyHandler
(
features
.
Listener
,
features
.
Constraint
,
features
.
Orderings
):
def
__init__
(
self
,
env
):
...
...
@@ -383,13 +383,14 @@ class PythonOp(Op):
return
all
([
is_result
(
i
)
for
i
in
self
.
inputs
])
def
gen_outputs
(
self
):
raise
NotImplemented
Error
()
raise
AbstractFunction
Error
()
def
view_map
(
self
):
return
{}
def
destroy_map
(
self
):
return
{}
def
root_inputs
(
self
,
input
):
@staticmethod
def
root_inputs
(
input
):
owner
=
input
.
owner
if
owner
:
view_map
=
owner
.
view_map
()
...
...
gof/result.py
浏览文件 @
d4e705ea
...
...
@@ -11,7 +11,7 @@ from err import GofError
from
utils
import
AbstractFunctionError
__all__
=
[
'is_result'
,
'ResultBase'
,
'BrokenLink'
,
'BrokenLinkError'
]
__all__
=
[
'is_result'
,
'ResultBase'
,
'BrokenLink'
,
'BrokenLinkError'
]
class
BrokenLink
:
...
...
@@ -36,6 +36,10 @@ class BrokenLinkError(GofError):
pass
# ResultBase state keywords
class
Empty
:
pass
class
Computed
:
pass
############################
# Result
...
...
@@ -53,6 +57,7 @@ class ResultBase(object):
_role - None or (owner, index) or BrokenLink
_data - anything
constant - Boolean
state - one of (Empty, Allocated, Computed)
Properties:
role - (rw)
...
...
@@ -60,13 +65,12 @@ class ResultBase(object):
index - (ro)
data - (rw)
replaced - (rw) : True iff _role is BrokenLink
computed - (ro) : True iff contents of data are fresh
Abstract Methods:
data_filter
Notes:
Notes
(from previous implementation)
:
A Result instance should be immutable: indeed, if some aspect of a
Result is changed, operations that use it might suddenly become
...
...
@@ -89,22 +93,28 @@ class ResultBase(object):
class
AbstractFunction
(
Exception
):
"""Exception thrown when an abstract function is called"""
__slots__
=
[
'_role'
,
'
_data'
,
'constant
'
]
__slots__
=
[
'_role'
,
'
constant'
,
'_data'
,
'state
'
]
def
__init__
(
self
,
role
=
None
,
data
=
None
,
constant
=
False
):
self
.
_role
=
role
self
.
constant
=
constant
if
data
is
None
:
#None is not filtered
self
.
_data
=
None
self
.
state
=
Empty
else
:
try
:
self
.
_data
=
self
.
data_filter
(
data
)
except
ResultBase
.
AbstractFunction
:
self
.
_data
=
data
self
.
state
=
Computed
#
# role
#
#role is pair: (owner, outputs_position)
def
__get_role
(
self
):
return
self
.
_role
def
__set_role
(
self
,
role
):
owner
,
index
=
role
if
self
.
_role
is
not
None
:
...
...
@@ -116,29 +126,41 @@ class ResultBase(object):
raise
ValueError
(
"Result
%
s was already mapped to a different index."
%
self
)
return
# because _owner is owner and _index == index
self
.
_role
=
role
role
=
property
(
__get_role
,
__set_role
)
#owner is role[0]
#
# owner
#
def
__get_owner
(
self
):
if
self
.
_role
is
None
:
return
None
if
self
.
replaced
:
raise
ResultBase
.
BrokenLinkError
()
return
self
.
_role
[
0
]
owner
=
property
(
__get_owner
,
doc
=
"Op of which this Result is an output, or None if role is None"
)
#index is role[1]
#
# index
#
def
__get_index
(
self
):
if
self
.
_role
is
None
:
return
None
if
self
.
replaced
:
raise
ResultBase
.
BrokenLinkError
()
return
self
.
_role
[
1
]
index
=
property
(
__get_index
,
doc
=
"position of self in owner's outputs, or None if role is None"
)
# assigning to self.data will invoke self.data_filter(value) if that
# function is defined
#
# data
#
def
__get_data
(
self
):
return
self
.
_data
def
__set_data
(
self
,
data
):
if
self
.
replaced
:
raise
ResultBase
.
BrokenLinkError
()
if
self
.
constant
:
raise
Exception
(
'cannot set constant ResultBase'
)
...
...
@@ -146,27 +168,39 @@ class ResultBase(object):
self
.
_data
=
self
.
data_filter
(
data
)
except
ResultBase
.
AbstractFunction
:
#use default behaviour
self
.
_data
=
data
self
.
state
=
Computed
data
=
property
(
__get_data
,
__set_data
,
doc
=
"The storage associated with this result"
)
def
data_filter
(
self
,
data
):
"""(abstract) Return an appropriate _data based on data."""
"""(abstract) Return an appropriate _data based on data.
If a subclass overrides this function, then that overriding
implementation will be used in __set_data to map the argument to
self._data. This gives a subclass the opportunity to ensure that
the contents of self._data remain sensible.
"""
raise
ResultBase
.
AbstractFunction
()
#
# replaced
def
__get_replaced
(
self
):
return
isinstance
(
self
.
_role
,
ResultBase
.
BrokenLink
)
#
def
__get_replaced
(
self
):
return
isinstance
(
self
.
_role
,
ResultBase
.
BrokenLink
)
def
__set_replaced
(
self
,
replace
):
if
replace
==
self
.
replaced
:
return
if
replace
:
self
.
_role
=
ResultBase
.
BrokenLink
(
self
.
_role
)
else
:
self
.
_role
=
self
.
_role
.
old_role
replaced
=
property
(
__get_replaced
,
__set_replaced
,
doc
=
"has this Result been replaced?"
)
# computed
#TODO: think about how to handle this more correctly
computed
=
property
(
lambda
self
:
self
.
_data
is
not
None
)
#################
...
...
grad.py
浏览文件 @
d4e705ea
...
...
@@ -77,7 +77,7 @@ class Grad(object):
r
.
shape
,
dr
.
shape
))
# prevent 'r' from being re-calculated by self.__call__ in 'build_eval' mode
if
r
.
c
omputed
:
if
r
.
state
is
gof
.
result
.
C
omputed
:
self
.
_compute_history
.
add
(
r
)
# add dr to self[r]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论