Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c0fd55c9
提交
c0fd55c9
authored
9月 16, 2011
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #44 from goodfeli/refactor_execute
Refactored _execute to make it more readable (using class instead of closure)
上级
03b07d02
50966470
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
35 行增加
和
18 行删除
+35
-18
cc.py
theano/gof/cc.py
+35
-18
没有找到文件。
theano/gof/cc.py
浏览文件 @
c0fd55c9
...
...
@@ -784,7 +784,7 @@ class CLinker(link.Linker):
init_tasks
,
tasks
=
self
.
get_init_tasks
()
cthunk
,
in_storage
,
out_storage
,
error_storage
=
self
.
__compile__
(
input_storage
,
output_storage
,
keep_lock
=
keep_lock
)
res
=
_
execute
(
cthunk
,
init_tasks
,
tasks
,
error_storage
),
in_storage
,
out_storage
res
=
_
CThunk
(
cthunk
,
init_tasks
,
tasks
,
error_storage
),
in_storage
,
out_storage
return
res
def
cmodule_key
(
self
):
...
...
@@ -1110,48 +1110,65 @@ class CLinker(link.Linker):
print
>>
code
,
" return thunk; }"
return
code
.
getvalue
()
def
_execute
(
cthunk
,
init_tasks
,
tasks
,
error_storage
):
"""WRITEME"""
global
run_cthunk
if
run_cthunk
is
None
:
# Lazy import to avoid compilation when importing theano.
from
theano.gof.cutils
import
run_cthunk
class
_CThunk
(
object
):
"""
A thunk with a C implementation
"""
def
find_task
(
failure_code
):
def
__init__
(
self
,
cthunk
,
init_tasks
,
tasks
,
error_storage
):
"""
Parameters
----------
cthunk: the CObject pointer used by run_cthunk
init_tasks: WRITEME
tasks: WRITEME
error_storage: WRITEME
"""
global
run_cthunk
if
run_cthunk
is
None
:
# Lazy import to avoid compilation when importing theano.
from
theano.gof.cutils
import
run_cthunk
self
.
cthunk
=
cthunk
self
.
init_tasks
=
init_tasks
self
.
tasks
=
tasks
self
.
error_storage
=
error_storage
def
find_task
(
self
,
failure_code
):
"""
Maps a failure code to the task that is associated to it.
"""
failure_code
-=
1
n
=
len
(
init_tasks
)
n
=
len
(
self
.
init_tasks
)
# note that the failure code is distributed in two lists
if
failure_code
<
2
*
n
:
return
[
init_tasks
,
tasks
][
failure_code
%
2
][
failure_code
/
2
]
return
[
self
.
init_tasks
,
self
.
tasks
][
failure_code
%
2
][
failure_code
/
2
]
else
:
return
tasks
[
failure_code
-
n
]
def
execute
():
failure
=
run_cthunk
(
cthunk
)
return
self
.
tasks
[
failure_code
-
n
]
def
__call__
(
self
):
failure
=
run_cthunk
(
self
.
cthunk
)
if
failure
:
task
,
taskname
,
id
=
find_task
(
failure
)
task
,
taskname
,
id
=
self
.
find_task
(
failure
)
try
:
trace
=
task
.
trace
except
AttributeError
:
trace
=
()
try
:
exc_type
,
_exc_value
,
exc_trace
=
error_storage
exc_type
,
_exc_value
,
exc_trace
=
self
.
error_storage
if
hasattr
(
task
,
"outputs"
):
exc_value
=
exc_type
(
_exc_value
,
task
,
task
.
outputs
)
else
:
exc_value
=
exc_type
(
_exc_value
,
task
)
exc_value
.
__thunk_trace__
=
trace
# this can be used to retrieve the location the Op was declared
except
Exception
:
print
>>
sys
.
stderr
,
'ERROR retrieving error_storage'
,
error_storage
print
>>
sys
.
stderr
,
'ERROR retrieving error_storage'
,
self
.
error_storage
raise
raise
exc_type
,
exc_value
,
exc_trace
execute
.
cthunk
=
cthunk
return
execute
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论