Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
dc00b2b6
提交
dc00b2b6
authored
9月 15, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
差异文件
tricky merge of cc and cmodule
上级
2f8f4194
d7103a60
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
20 行增加
和
10 行删除
+20
-10
cc.py
theano/gof/cc.py
+1
-3
cmodule.py
theano/gof/cmodule.py
+19
-7
没有找到文件。
theano/gof/cc.py
浏览文件 @
dc00b2b6
...
...
@@ -830,9 +830,7 @@ class CLinker(link.Linker):
This method is a callback for `ModuleCache.module_from_key`
"""
if
location
is
None
:
location
=
get_compiledir
()
#backport
#location = get_compiledir() if location is None else location
location
=
cmodule
.
dlimport_workdir
(
get_compiledir
())
mod
=
self
.
build_dynamic_module
()
get_lock
()
try
:
...
...
theano/gof/cmodule.py
浏览文件 @
dc00b2b6
...
...
@@ -139,6 +139,8 @@ def dlimport(fullpath, suffix=None):
:returns: the dynamically loaded module (from __import__)
"""
if
not
os
.
path
.
isabs
(
fullpath
):
raise
ValueError
(
'`fullpath` must be an absolute path'
,
fullpath
)
if
suffix
is
None
:
if
fullpath
.
endswith
(
'.so'
):
suffix
=
'.so'
...
...
@@ -156,21 +158,26 @@ def dlimport(fullpath, suffix=None):
else
:
raise
ValueError
(
'path has wrong suffix'
,
(
fullpath
,
suffix
))
workdir
=
fullpath
[:
-
len
(
module_name
)
-
1
-
len
(
suffix
)]
#debug("WORKDIR", workdir)
#debug("module_name", module_name)
pathcopy
=
list
(
sys
.
path
)
sys
.
path
=
[
workdir
]
debug
(
"WORKDIR"
,
workdir
)
debug
(
"module_name"
,
module_name
)
sys
.
path
[
0
:
0
]
=
[
workdir
]
#insert workdir at beginning (temporarily)
try
:
rval
=
__import__
(
module_name
,
{},
{},
[
module_name
])
if
not
rval
:
error
(
'__import__ failed'
,
fullpath
)
raise
Exception
(
'__import__ failed'
,
fullpath
)
finally
:
sys
.
path
=
pathcopy
del
sys
.
path
[
0
]
assert
fullpath
.
startswith
(
rval
.
__file__
)
return
rval
def
dlimport_workdir
(
basedir
):
"""Return a directory where you should put your .so file for dlimport to be able to load
it, given a basedir which should normally be the result of get_compiledir()"""
return
tempfile
.
mkdtemp
(
dir
=
basedir
)
def
last_access_time
(
path
):
"""Return the number of seconds since the epoch of the last access of a given file"""
return
os
.
stat
(
path
)[
stat
.
ST_ATIME
]
...
...
@@ -347,6 +354,11 @@ class ModuleCache(object):
compilelock
.
release_lock
()
def
module_from_key
(
self
,
key
,
fn
=
None
):
"""
:param fn: a callable object that will return a module for the key (it is called only if the key isn't in
the cache). This function will be called with a single keyword argument "location"
that is a path on the filesystem wherein the function should write the module.
"""
rval
=
None
try
:
_version
,
_rest
=
key
...
...
@@ -366,7 +378,7 @@ class ModuleCache(object):
rval
=
self
.
module_from_name
[
name
]
else
:
# we have never seen this key before
location
=
tempfile
.
mkdtemp
(
dir
=
self
.
dirname
)
location
=
dlimport_workdir
(
self
.
dirname
)
#debug("LOCATION*", location)
try
:
module
=
fn
(
location
=
location
)
# WILL FAIL FOR BAD C CODE
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论