Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c47e8ecc
提交
c47e8ecc
authored
1月 25, 2012
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A few PEP8 fixes
上级
ebe3e3b4
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
49 行增加
和
21 行删除
+49
-21
cmodule.py
theano/gof/cmodule.py
+49
-21
没有找到文件。
theano/gof/cmodule.py
浏览文件 @
c47e8ecc
"""Generate and compile C modules for Python,
"""Generate and compile C modules for Python,
"""
"""
import
atexit
,
cPickle
,
logging
,
operator
,
os
,
shutil
,
stat
,
StringIO
import
atexit
import
subprocess
,
sys
,
tempfile
,
time
import
cPickle
import
logging
import
operator
import
os
import
shutil
import
stat
import
StringIO
import
subprocess
import
sys
import
tempfile
import
time
import
distutils.sysconfig
import
distutils.sysconfig
...
@@ -1268,16 +1278,20 @@ def std_lib_dirs_and_libs():
...
@@ -1268,16 +1278,20 @@ def std_lib_dirs_and_libs():
else
:
else
:
# Typical include directory: /usr/include/python2.6
# Typical include directory: /usr/include/python2.6
libname
=
os
.
path
.
basename
(
python_inc
)
libname
=
os
.
path
.
basename
(
python_inc
)
return
[
libname
],[]
return
[
libname
],
[]
def
std_libs
():
def
std_libs
():
return
std_lib_dirs_and_libs
()[
0
]
return
std_lib_dirs_and_libs
()[
0
]
def
std_lib_dirs
():
def
std_lib_dirs
():
return
std_lib_dirs_and_libs
()[
1
]
return
std_lib_dirs_and_libs
()[
1
]
# Using the dummy file descriptors below is a workaround for a crash experienced
# in an unusual Python 2.4.4 Windows environment with the default None values.
# Using the dummy file descriptors below is a workaround for a crash
# experienced in an unusual Python 2.4.4 Windows environment with the default
# None values.
dummy_in
=
open
(
os
.
devnull
)
dummy_in
=
open
(
os
.
devnull
)
dummy_err
=
open
(
os
.
devnull
,
'w'
)
dummy_err
=
open
(
os
.
devnull
,
'w'
)
p
=
None
p
=
None
...
@@ -1293,18 +1307,29 @@ del p
...
@@ -1293,18 +1307,29 @@ del p
del
dummy_in
del
dummy_in
del
dummy_err
del
dummy_err
def
gcc_version
():
def
gcc_version
():
return
gcc_version_str
return
gcc_version_str
def
gcc_module_compile_str
(
module_name
,
src_code
,
location
=
None
,
include_dirs
=
[],
lib_dirs
=
[],
libs
=
[],
preargs
=
[]):
def
gcc_module_compile_str
(
module_name
,
src_code
,
location
=
None
,
include_dirs
=
[],
lib_dirs
=
[],
libs
=
[],
preargs
=
[]):
"""
"""
:param module_name: string (this has been embedded in the src_code
:param module_name: string (this has been embedded in the src_code
:param src_code: a complete c or c++ source listing for the module
:param src_code: a complete c or c++ source listing for the module
:param location: a pre-existing filesystem directory where the cpp file and .so will be written
:param include_dirs: a list of include directory names (each gets prefixed with -I)
:param location: a pre-existing filesystem directory where the cpp file and
:param lib_dirs: a list of library search path directory names (each gets prefixed with -L)
.so will be written
:param include_dirs: a list of include directory names (each gets prefixed
with -I)
:param lib_dirs: a list of library search path directory names (each gets
prefixed with -L)
:param libs: a list of libraries to link with (each gets prefixed with -l)
:param libs: a list of libraries to link with (each gets prefixed with -l)
:param preargs: a list of extra compiler arguments
:param preargs: a list of extra compiler arguments
:returns: dynamically-imported python module of the compiled code.
:returns: dynamically-imported python module of the compiled code.
...
@@ -1327,16 +1352,18 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
...
@@ -1327,16 +1352,18 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
lib_dirs
=
std_lib_dirs
()
+
lib_dirs
lib_dirs
=
std_lib_dirs
()
+
lib_dirs
#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'
])
python_inc
=
distutils
.
sysconfig
.
get_python_inc
()
python_inc
=
distutils
.
sysconfig
.
get_python_inc
()
# link with the framework library *if specifically requested*
# link with the framework library *if specifically requested*
# config.mac_framework_link is by default False, since on some mac
# config.mac_framework_link is by default False, since on some mac
# installs linking with -framework causes a Bus Error
# installs linking with -framework causes a Bus Error
if
python_inc
.
count
(
'Python.framework'
)
>
0
and
config
.
cmodule
.
mac_framework_link
:
if
(
python_inc
.
count
(
'Python.framework'
)
>
0
and
preargs
.
extend
([
'-framework'
,
'Python'
])
config
.
cmodule
.
mac_framework_link
):
preargs
.
extend
([
'-framework'
,
'Python'
])
# Figure out whether the current Python executable is 32 or 64 bit and compile accordingly
# Figure out whether the current Python executable is 32 or 64 bit and
# compile accordingly.
n_bits
=
local_bitwidth
()
n_bits
=
local_bitwidth
()
preargs
.
extend
([
'-m
%
s'
%
n_bits
])
preargs
.
extend
([
'-m
%
s'
%
n_bits
])
_logger
.
debug
(
"OS X: compiling for
%
s bit architecture"
,
n_bits
)
_logger
.
debug
(
"OS X: compiling for
%
s bit architecture"
,
n_bits
)
...
@@ -1377,11 +1404,11 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
...
@@ -1377,11 +1404,11 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
cxxflags
=
[
flag
for
flag
in
config
.
gcc
.
cxxflags
.
split
(
' '
)
if
flag
]
cxxflags
=
[
flag
for
flag
in
config
.
gcc
.
cxxflags
.
split
(
' '
)
if
flag
]
#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
])
#print >> sys.stderr, 'COMPILING W CMD', cmd
#print >> sys.stderr, 'COMPILING W CMD', cmd
_logger
.
debug
(
'Running cmd:
%
s'
,
' '
.
join
(
cmd
))
_logger
.
debug
(
'Running cmd:
%
s'
,
' '
.
join
(
cmd
))
...
@@ -1405,7 +1432,7 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
...
@@ -1405,7 +1432,7 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
print
'==============================='
print
'==============================='
for
i
,
l
in
enumerate
(
src_code
.
split
(
'
\n
'
)):
for
i
,
l
in
enumerate
(
src_code
.
split
(
'
\n
'
)):
#gcc put its messages to stderr, so we add ours now
#gcc put its messages to stderr, so we add ours now
print
>>
sys
.
stderr
,
'
%05
i
\t
%
s'
%
(
i
+
1
,
l
)
print
>>
sys
.
stderr
,
'
%05
i
\t
%
s'
%
(
i
+
1
,
l
)
print
'==============================='
print
'==============================='
print_command_line_error
()
print_command_line_error
()
# Print errors just below the command line.
# Print errors just below the command line.
...
@@ -1417,8 +1444,9 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
...
@@ -1417,8 +1444,9 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
(
status
,
compile_stderr
.
replace
(
'
\n
'
,
'. '
)))
(
status
,
compile_stderr
.
replace
(
'
\n
'
,
'. '
)))
#touch the __init__ file
#touch the __init__ file
file
(
os
.
path
.
join
(
location
,
"__init__.py"
),
'w'
)
.
close
()
file
(
os
.
path
.
join
(
location
,
"__init__.py"
),
'w'
)
.
close
()
return
dlimport
(
lib_filename
)
return
dlimport
(
lib_filename
)
def
icc_module_compile_str
(
*
args
):
def
icc_module_compile_str
(
*
args
):
raise
NotImplementedError
()
raise
NotImplementedError
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论