Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
93493fc4
提交
93493fc4
authored
1月 28, 2011
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
whitespace/indentation fix.
上级
7c23cdd8
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
18 行增加
和
19 行删除
+18
-19
cmodule.py
theano/gof/cmodule.py
+18
-19
没有找到文件。
theano/gof/cmodule.py
浏览文件 @
93493fc4
"""Generate and compile C modules for Python,
"""Generate and compile C modules for Python,
"""
"""
import
os
,
tempfile
,
StringIO
,
sys
,
logging
,
subprocess
,
cPickle
,
atexit
,
time
,
shutil
,
stat
import
os
,
tempfile
,
StringIO
,
sys
,
logging
,
subprocess
,
cPickle
,
atexit
,
time
,
shutil
,
stat
import
distutils.sysconfig
import
distutils.sysconfig
...
@@ -219,8 +219,8 @@ class ModuleCache(object):
...
@@ -219,8 +219,8 @@ class ModuleCache(object):
will be deleted in an atexit() handler.
will be deleted in an atexit() handler.
If the ``version`` is neither 0 nor (), then the module will be kept in the cache between
If the ``version`` is neither 0 nor (), then the module will be kept in the cache between
processes.
processes.
An unversioned module is not deleted by the process that creates it. Deleting such modules
An unversioned module is not deleted by the process that creates it. Deleting such modules
does not work on NFS filesystems because the tmpdir in which the library resides is in use
does not work on NFS filesystems because the tmpdir in which the library resides is in use
until the end of the process' lifetime. Instead, unversioned modules are left in their
until the end of the process' lifetime. Instead, unversioned modules are left in their
...
@@ -233,7 +233,7 @@ class ModuleCache(object):
...
@@ -233,7 +233,7 @@ class ModuleCache(object):
module_from_name
=
{}
module_from_name
=
{}
"""maps a module filename to the loaded module object"""
"""maps a module filename to the loaded module object"""
entry_from_key
=
{}
entry_from_key
=
{}
"""Maps keys to the filename of a .so/.pyd.
"""Maps keys to the filename of a .so/.pyd.
"""
"""
...
@@ -261,7 +261,7 @@ class ModuleCache(object):
...
@@ -261,7 +261,7 @@ class ModuleCache(object):
self
.
entry_from_key
=
dict
(
self
.
entry_from_key
)
self
.
entry_from_key
=
dict
(
self
.
entry_from_key
)
self
.
stats
=
[
0
,
0
,
0
]
self
.
stats
=
[
0
,
0
,
0
]
if
force_fresh
is
not
None
:
if
force_fresh
is
not
None
:
self
.
force_fresh
=
force_fresh
self
.
force_fresh
=
force_fresh
self
.
loaded_key_pkl
=
set
()
self
.
loaded_key_pkl
=
set
()
self
.
refresh
()
self
.
refresh
()
...
@@ -363,7 +363,7 @@ class ModuleCache(object):
...
@@ -363,7 +363,7 @@ class ModuleCache(object):
gone
=
True
gone
=
True
if
gone
:
if
gone
:
# assert that we didn't have one of the deleted files
# assert that we didn't have one of the deleted files
# loaded up and in use.
# loaded up and in use.
# If so, it should not have been deleted. This should be considered a
# If so, it should not have been deleted. This should be considered a
# failure of the OTHER process, that deleted it.
# failure of the OTHER process, that deleted it.
if
entry
in
self
.
module_from_name
:
if
entry
in
self
.
module_from_name
:
...
@@ -484,7 +484,7 @@ class ModuleCache(object):
...
@@ -484,7 +484,7 @@ class ModuleCache(object):
seconds ago will be erased.
seconds ago will be erased.
"""
"""
if
age_thresh_del
is
None
:
if
age_thresh_del
is
None
:
age_thresh_del
=
self
.
age_thresh_del
age_thresh_del
=
self
.
age_thresh_del
compilelock
.
get_lock
()
compilelock
.
get_lock
()
try
:
try
:
...
@@ -497,7 +497,7 @@ class ModuleCache(object):
...
@@ -497,7 +497,7 @@ class ModuleCache(object):
# the .items() is important here:
# the .items() is important here:
# we need to get a copy of the whole list of keys and entries
# we need to get a copy of the whole list of keys and entries
items_copy
=
list
(
self
.
entry_from_key
.
iteritems
())
items_copy
=
list
(
self
.
entry_from_key
.
iteritems
())
for
key
,
entry
in
items_copy
+
too_old_to_use
:
for
key
,
entry
in
items_copy
+
too_old_to_use
:
age
=
time_now
-
last_access_time
(
entry
)
age
=
time_now
-
last_access_time
(
entry
)
if
age
>
age_thresh_del
:
if
age
>
age_thresh_del
:
# TODO: we are assuming that modules that haven't been accessed in over
# TODO: we are assuming that modules that haven't been accessed in over
...
@@ -526,7 +526,7 @@ class ModuleCache(object):
...
@@ -526,7 +526,7 @@ class ModuleCache(object):
filesystem.
filesystem.
"""
"""
items_copy
=
list
(
self
.
entry_from_key
.
iteritems
())
items_copy
=
list
(
self
.
entry_from_key
.
iteritems
())
for
key
,
entry
in
items_copy
:
for
key
,
entry
in
items_copy
:
version
,
rest
=
key
version
,
rest
=
key
if
not
version
:
if
not
version
:
del
self
.
entry_from_key
[
key
]
del
self
.
entry_from_key
[
key
]
...
@@ -535,13 +535,13 @@ class ModuleCache(object):
...
@@ -535,13 +535,13 @@ class ModuleCache(object):
# because an unversioned entry should never have been loaded via refresh
# because an unversioned entry should never have been loaded via refresh
assert
entry
in
self
.
module_from_name
assert
entry
in
self
.
module_from_name
del
self
.
module_from_name
[
entry
]
del
self
.
module_from_name
[
entry
]
parent
=
os
.
path
.
dirname
(
entry
)
parent
=
os
.
path
.
dirname
(
entry
)
assert
parent
.
startswith
(
os
.
path
.
join
(
self
.
dirname
,
'tmp'
))
assert
parent
.
startswith
(
os
.
path
.
join
(
self
.
dirname
,
'tmp'
))
info
(
"clear_unversioned removing cache dir"
,
parent
)
info
(
"clear_unversioned removing cache dir"
,
parent
)
_rmtree
(
parent
)
_rmtree
(
parent
)
time_now
=
time
.
time
()
time_now
=
time
.
time
()
for
filename
in
os
.
listdir
(
self
.
dirname
):
for
filename
in
os
.
listdir
(
self
.
dirname
):
if
filename
.
startswith
(
'tmp'
):
if
filename
.
startswith
(
'tmp'
):
...
@@ -658,9 +658,9 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
...
@@ -658,9 +658,9 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
#TODO: Do not do the dlimport in this function
#TODO: Do not do the dlimport in this function
if
preargs
is
None
:
if
preargs
is
None
:
preargs
=
[]
preargs
=
[]
else
:
else
:
preargs
=
list
(
preargs
)
preargs
=
list
(
preargs
)
if
sys
.
platform
!=
'win32'
:
if
sys
.
platform
!=
'win32'
:
# Under Windows it looks like fPIC is useless. Compiler warning:
# Under Windows it looks like fPIC is useless. Compiler warning:
...
@@ -668,7 +668,7 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
...
@@ -668,7 +668,7 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
preargs
.
append
(
'-fPIC'
)
preargs
.
append
(
'-fPIC'
)
no_opt
=
False
no_opt
=
False
include_dirs
=
include_dirs
+
std_include_dirs
()
include_dirs
=
include_dirs
+
std_include_dirs
()
libs
=
std_libs
()
+
libs
libs
=
std_libs
()
+
libs
lib_dirs
=
std_lib_dirs
()
+
lib_dirs
lib_dirs
=
std_lib_dirs
()
+
lib_dirs
if
sys
.
platform
==
'win32'
:
if
sys
.
platform
==
'win32'
:
...
@@ -684,7 +684,7 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
...
@@ -684,7 +684,7 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
python_inc
=
distutils
.
sysconfig
.
get_python_inc
()
python_inc
=
distutils
.
sysconfig
.
get_python_inc
()
libname
=
os
.
path
.
basename
(
python_inc
)
libname
=
os
.
path
.
basename
(
python_inc
)
#DSE Patch 1 for supporting OSX frameworks; add -framework Python
#DSE Patch 1 for supporting OSX frameworks; add -framework Python
if
sys
.
platform
==
'darwin'
:
if
sys
.
platform
==
'darwin'
:
preargs
.
extend
([
'-undefined'
,
'dynamic_lookup'
])
preargs
.
extend
([
'-undefined'
,
'dynamic_lookup'
])
# link with the framework library *if specifically requested*
# link with the framework library *if specifically requested*
...
@@ -698,11 +698,11 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
...
@@ -698,11 +698,11 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
preargs
.
extend
([
'-m
%
s'
%
n_bits
])
preargs
.
extend
([
'-m
%
s'
%
n_bits
])
debug
(
"OS X: compiling for
%
s bit architecture"
%
n_bits
)
debug
(
"OS X: compiling for
%
s bit architecture"
%
n_bits
)
# sometimes, the linker cannot find -lpython so we need to tell it
# sometimes, the linker cannot find -lpython so we need to tell it
# explicitly where it is located
# explicitly where it is located
# this returns somepath/lib/python2.x
# this returns somepath/lib/python2.x
python_lib
=
distutils
.
sysconfig
.
get_python_lib
(
plat_specific
=
1
,
\
python_lib
=
distutils
.
sysconfig
.
get_python_lib
(
plat_specific
=
1
,
\
standard_lib
=
1
)
standard_lib
=
1
)
python_lib
=
os
.
path
.
dirname
(
python_lib
)
python_lib
=
os
.
path
.
dirname
(
python_lib
)
if
python_lib
not
in
lib_dirs
:
if
python_lib
not
in
lib_dirs
:
lib_dirs
.
append
(
python_lib
)
lib_dirs
.
append
(
python_lib
)
...
@@ -732,7 +732,7 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
...
@@ -732,7 +732,7 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
#print >> sys.stderr, config.gcc.cxxflags.split(' ')
#print >> sys.stderr, config.gcc.cxxflags.split(' ')
cmd
.
extend
(
cxxflags
)
cmd
.
extend
(
cxxflags
)
cmd
.
extend
(
'-I
%
s'
%
idir
for
idir
in
include_dirs
)
cmd
.
extend
(
'-I
%
s'
%
idir
for
idir
in
include_dirs
)
cmd
.
extend
([
'-o'
,
lib_filename
])
cmd
.
extend
([
'-o'
,
lib_filename
])
cmd
.
append
(
cppfilename
)
cmd
.
append
(
cppfilename
)
cmd
.
extend
([
'-L
%
s'
%
ldir
for
ldir
in
lib_dirs
])
cmd
.
extend
([
'-L
%
s'
%
ldir
for
ldir
in
lib_dirs
])
cmd
.
extend
([
'-l
%
s'
%
l
for
l
in
libs
])
cmd
.
extend
([
'-l
%
s'
%
l
for
l
in
libs
])
...
@@ -757,4 +757,3 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
...
@@ -757,4 +757,3 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
def
icc_module_compile_str
(
*
args
):
def
icc_module_compile_str
(
*
args
):
raise
NotImplementedError
()
raise
NotImplementedError
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论