本文整理汇总了Python中numpy.f2py方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.f2py方法的具体用法?Python numpy.f2py怎么用?Python numpy.f2py使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.f2py方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_code
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import f2py [as 别名]
def build_code(source_code, options=[], skip=[], only=[], suffix=None,
module_name=None):
"""
Compile and import Fortran code using f2py.
"""
if suffix is None:
suffix = '.f'
with temppath(suffix=suffix) as path:
with open(path, 'w') as f:
f.write(source_code)
return build_module([path], options=options, skip=skip, only=only,
module_name=module_name)
#
# Check if compilers are available at all...
#
示例2: build_code
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import f2py [as 别名]
def build_code(source_code, options=[], skip=[], only=[], suffix=None,
module_name=None):
"""
Compile and import Fortran code using f2py.
"""
if suffix is None:
suffix = '.f'
fd, tmp_fn = tempfile.mkstemp(suffix=suffix)
os.write(fd, asbytes(source_code))
os.close(fd)
try:
return build_module([tmp_fn], options=options, skip=skip, only=only,
module_name=module_name)
finally:
os.unlink(tmp_fn)
#
# Check if compilers are available at all...
#
示例3: calc_info
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import f2py [as 别名]
def calc_info(self):
try:
import numpy.f2py as f2py
except ImportError:
return
f2py_dir = os.path.join(os.path.dirname(f2py.__file__), 'src')
self.set_info(sources=[os.path.join(f2py_dir, 'fortranobject.c')],
include_dirs=[f2py_dir])
return
示例4: _compile
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import f2py [as 别名]
def _compile(self, code: str, path: pathlib.Path, output_folder: pathlib.Path,
module_name: str, **kwargs):
assert isinstance(code, str), type(code)
assert isinstance(path, pathlib.Path), type(path)
assert isinstance(module_name, str), type(module_name)
f2py_args = self.flags('compile') + self.options('compile') \
+ self.f_compiler.options('compile')
f2py_kwargs = {
'f90exec': self.f_compiler.executable('compile'),
'opt': ' '.join(self.f_compiler.flags('compile'))
}
# f2py_kwargs['noopt'] = True
if isinstance(self.f_compiler, PgifortranInterface):
f2py_kwargs['compiler'] = 'unix'
f2py_kwargs['fcompiler'] = 'pg'
extra_args = self.argunparser.unparse(*f2py_args, **f2py_kwargs)
_LOG.info('f2py extra args: %s', extra_args)
_LOG.warning('f2py compiling file: "%s", (%i characters)', path, len(code))
# _LOG.debug('compiled file\'s contents: %s', code)
result = call_tool(
numpy.f2py.compile, kwargs={
'source': code, 'modulename': module_name, 'extra_args': extra_args,
'verbose': False, 'source_fn': '{}'.format(path).replace(' ', '\\ '),
'extension': path.suffix},
cwd=output_folder,
commandline_equivalent='f2py -c -m {} {} "{}"'.format(module_name, extra_args, path),
capture_output=True)
return {'result': result}
示例5: finalize_options
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import f2py [as 别名]
def finalize_options(self):
self.set_undefined_options('build',
('build_base', 'build_base'),
('build_lib', 'build_lib'),
('force', 'force'))
if self.package is None:
self.package = self.distribution.ext_package
self.extensions = self.distribution.ext_modules
self.libraries = self.distribution.libraries or []
self.py_modules = self.distribution.py_modules or []
self.data_files = self.distribution.data_files or []
if self.build_src is None:
plat_specifier = ".%s-%s" % (get_platform(), sys.version[0:3])
self.build_src = os.path.join(self.build_base, 'src'+plat_specifier)
# py_modules_dict is used in build_py.find_package_modules
self.py_modules_dict = {}
if self.f2pyflags:
if self.f2py_opts:
log.warn('ignoring --f2pyflags as --f2py-opts already used')
else:
self.f2py_opts = self.f2pyflags
self.f2pyflags = None
if self.f2py_opts is None:
self.f2py_opts = []
else:
self.f2py_opts = shlex.split(self.f2py_opts)
if self.swigflags:
if self.swig_opts:
log.warn('ignoring --swigflags as --swig-opts already used')
else:
self.swig_opts = self.swigflags
self.swigflags = None
if self.swig_opts is None:
self.swig_opts = []
else:
self.swig_opts = shlex.split(self.swig_opts)
# use options from build_ext command
build_ext = self.get_finalized_command('build_ext')
if self.inplace is None:
self.inplace = build_ext.inplace
if self.swig_cpp is None:
self.swig_cpp = build_ext.swig_cpp
for c in ['swig', 'swig_opt']:
o = '--'+c.replace('_', '-')
v = getattr(build_ext, c, None)
if v:
if getattr(self, c):
log.warn('both build_src and build_ext define %s option' % (o))
else:
log.info('using "%s=%s" option from build_ext command' % (o, v))
setattr(self, c, v)
示例6: build_module
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import f2py [as 别名]
def build_module(source_files, options=[], skip=[], only=[], module_name=None):
"""
Compile and import a f2py module, built from the given files.
"""
code = ("import sys; sys.path = %s; import numpy.f2py as f2py2e; "
"f2py2e.main()" % repr(sys.path))
d = get_module_dir()
# Copy files
dst_sources = []
for fn in source_files:
if not os.path.isfile(fn):
raise RuntimeError("%s is not a file" % fn)
dst = os.path.join(d, os.path.basename(fn))
shutil.copyfile(fn, dst)
dst_sources.append(dst)
fn = os.path.join(os.path.dirname(fn), '.f2py_f2cmap')
if os.path.isfile(fn):
dst = os.path.join(d, os.path.basename(fn))
if not os.path.isfile(dst):
shutil.copyfile(fn, dst)
# Prepare options
if module_name is None:
module_name = get_temp_module_name()
f2py_opts = ['-c', '-m', module_name] + options + dst_sources
if skip:
f2py_opts += ['skip:'] + skip
if only:
f2py_opts += ['only:'] + only
# Build
cwd = os.getcwd()
try:
os.chdir(d)
cmd = [sys.executable, '-c', code] + f2py_opts
p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
out, err = p.communicate()
if p.returncode != 0:
raise RuntimeError("Running f2py failed: %s\n%s"
% (cmd[4:], asstr(out)))
finally:
os.chdir(cwd)
# Partial cleanup
for fn in dst_sources:
os.unlink(fn)
# Import
__import__(module_name)
return sys.modules[module_name]