本文整理汇总了Python中numba.compiler.Flags.set方法的典型用法代码示例。如果您正苦于以下问题:Python Flags.set方法的具体用法?Python Flags.set怎么用?Python Flags.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numba.compiler.Flags
的用法示例。
在下文中一共展示了Flags.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from numba.compiler import Flags [as 别名]
# 或者: from numba.compiler.Flags import set [as 别名]
def __init__(self, pyfunc, signature):
self.py_func = pyfunc
self.signature = signature
self.name = pyfunc.__name__
# recreate for each UDF, as linking is destructive to the
# precompiled module
impala_typing = impala_typing_context()
impala_targets = ImpalaTargetContext(impala_typing)
args, return_type = sigutils.normalize_signature(signature)
flags = Flags()
flags.set('no_compile')
self._cres = compile_extra(typingctx=impala_typing,
targetctx=impala_targets, func=pyfunc,
args=args, return_type=return_type,
flags=flags, locals={})
llvm_func = impala_targets.finalize(self._cres.llvm_func, return_type,
args)
self.llvm_func = llvm_func
# numba_module = llvm_func.module
self.llvm_module = llvm_func.module
# link in the precompiled module
# bc it's destructive, load a fresh version
precompiled = lc.Module.from_bitcode(
pkgutil.get_data("impala.udf", "precompiled/impyla.bc"))
self.llvm_module.link_in(precompiled)
示例2: test_array_expr
# 需要导入模块: from numba.compiler import Flags [as 别名]
# 或者: from numba.compiler.Flags import set [as 别名]
def test_array_expr(self):
flags = Flags()
flags.set("enable_pyobject")
global cnd_array_jitted
scalty = types.float64
arrty = types.Array(scalty, 1, 'C')
cr1 = compile_isolated(cnd_array, args=(arrty,), flags=flags)
cnd_array_jitted = cr1.entry_point
cr2 = compile_isolated(blackscholes_arrayexpr_jitted,
args=(arrty, arrty, arrty, scalty, scalty),
flags=flags)
jitted_bs = cr2.entry_point
OPT_N = 400
iterations = 10
stockPrice = randfloat(self.random.random_sample(OPT_N), 5.0, 30.0)
optionStrike = randfloat(self.random.random_sample(OPT_N), 1.0, 100.0)
optionYears = randfloat(self.random.random_sample(OPT_N), 0.25, 10.0)
args = stockPrice, optionStrike, optionYears, RISKFREE, VOLATILITY
callResultGold, putResultGold = blackscholes_arrayexpr(*args)
callResultNumba, putResultNumba = jitted_bs(*args)
delta = np.abs(callResultGold - callResultNumba)
L1norm = delta.sum() / np.abs(callResultGold).sum()
print("L1 norm: %E" % L1norm)
print("Max absolute error: %E" % delta.max())
self.assertEqual(delta.max(), 0)
示例3: test_exercise_code_path_with_lifted_loop
# 需要导入模块: from numba.compiler import Flags [as 别名]
# 或者: from numba.compiler.Flags import set [as 别名]
def test_exercise_code_path_with_lifted_loop(self):
"""
Ensures that lifted loops are handled correctly in obj mode
"""
# the functions to jit
def bar(x):
return x
def foo(x):
h = 0.
for k in range(x):
h = h + k
if x:
h = h - bar(x)
return h
# compile into an isolated context
flags = Flags()
flags.set('enable_pyobject')
flags.set('enable_looplift')
cres = compile_isolated(foo, [types.intp], flags=flags)
ta = cres.type_annotation
buf = StringIO()
ta.html_annotate(buf)
output = buf.getvalue()
buf.close()
self.assertIn("bar", output)
self.assertIn("foo", output)
self.assertIn("LiftedLoop", output)
示例4: test_is_this_a_none_objmode
# 需要导入模块: from numba.compiler import Flags [as 别名]
# 或者: from numba.compiler.Flags import set [as 别名]
def test_is_this_a_none_objmode(self):
pyfunc = is_this_a_none
flags = Flags()
flags.set('force_pyobject')
cres = compile_isolated(pyfunc, [types.intp], flags=flags)
cfunc = cres.entry_point
self.assertTrue(cres.objectmode)
for v in [-1, 0, 1, 2]:
self.assertPreciseEqual(pyfunc(v), cfunc(v))
示例5: test_raise_object
# 需要导入模块: from numba.compiler import Flags [as 别名]
# 或者: from numba.compiler.Flags import set [as 别名]
def test_raise_object(self):
args = [types.int32]
flags = Flags()
flags.set('force_pyobject')
cres = compile_isolated(pyfunc, args,
flags=flags)
cfunc = cres.entry_point
cfunc(0)
with self.assertRaises(MyError):
cfunc(1)
示例6: test_usecase
# 需要导入模块: from numba.compiler import Flags [as 别名]
# 或者: from numba.compiler.Flags import set [as 别名]
def test_usecase(self):
n = 10
obs_got = np.zeros(n)
obs_expected = obs_got.copy()
flags = Flags()
flags.set("enable_pyobject")
cres = compile_isolated(usecase, (), flags=flags)
cres.entry_point(obs_got, n, 10.0, 1.0, 2.0, 3.0, 4.0, 5.0)
usecase(obs_expected, n, 10.0, 1.0, 2.0, 3.0, 4.0, 5.0)
self.assertTrue(np.allclose(obs_got, obs_expected))
示例7: _cull_exports
# 需要导入模块: from numba.compiler import Flags [as 别名]
# 或者: from numba.compiler.Flags import set [as 别名]
def _cull_exports(self):
"""Read all the exported functions/modules in the translator
environment, and join them into a single LLVM module.
Resets the export environment afterwards.
"""
self.exported_signatures = export_registry
# Create new module containing everything
llvm_module = lc.Module.new(self.module_name)
# Compile all exported functions
typing_ctx = CPUTarget.typing_context
# TODO Use non JIT-ing target
target_ctx = CPUTarget.target_context
modules = []
flags = Flags()
if not self.export_python_wrap:
flags.set("no_compile")
for entry in self.exported_signatures:
cres = compile_extra(typing_ctx, target_ctx, entry.function,
entry.signature.args,
entry.signature.return_type, flags,
locals={})
if self.export_python_wrap:
module = cres.llvm_func.module
cres.llvm_func.linkage = lc.LINKAGE_INTERNAL
wrappername = "wrapper." + cres.llvm_func.name
wrapper = module.get_function_named(wrappername)
wrapper.name = entry.symbol
else:
cres.llvm_func.name = entry.symbol
modules.append(cres.llvm_module)
# Link all exported functions
for mod in modules:
llvm_module.link_in(mod, preserve=self.export_python_wrap)
# Optimize
tm = le.TargetMachine.new(opt=3)
pms = lp.build_pass_managers(tm=tm, opt=3, loop_vectorize=True,
fpm=False)
pms.pm.run(llvm_module)
if self.export_python_wrap:
self._emit_python_wrapper(llvm_module)
#del self.exported_signatures[:]
print(llvm_module)
return llvm_module
示例8: test_usecase
# 需要导入模块: from numba.compiler import Flags [as 别名]
# 或者: from numba.compiler.Flags import set [as 别名]
def test_usecase(self):
n = 10
obs_got = np.zeros(n)
obs_expected = obs_got.copy()
flags = Flags()
flags.set("enable_pyobject")
cres = compile_isolated(usecase, (types.float64[:], types.intp),
flags=flags)
cres.entry_point(obs_got, n)
usecase(obs_expected, n)
self.assertTrue(np.allclose(obs_got, obs_expected))
示例9: _cull_exports
# 需要导入模块: from numba.compiler import Flags [as 别名]
# 或者: from numba.compiler.Flags import set [as 别名]
def _cull_exports(self):
"""Read all the exported functions/modules in the translator
environment, and join them into a single LLVM module.
Resets the export environment afterwards.
"""
self.exported_signatures = export_registry
self.exported_function_types = {}
typing_ctx = CPUTarget.typing_context
target_ctx = CPUTarget.target_context
codegen = target_ctx.aot_codegen(self.module_name)
library = codegen.create_library(self.module_name)
# Generate IR for all exported functions
flags = Flags()
flags.set("no_compile")
for entry in self.exported_signatures:
cres = compile_extra(typing_ctx, target_ctx, entry.function,
entry.signature.args,
entry.signature.return_type, flags,
locals={}, library=library)
func_name = cres.fndesc.llvm_func_name
llvm_func = cres.library.get_function(func_name)
if self.export_python_wrap:
# XXX: unsupported (necessary?)
llvm_func.linkage = lc.LINKAGE_INTERNAL
wrappername = cres.fndesc.llvm_cpython_wrapper_name
wrapper = cres.library.get_function(wrappername)
wrapper.name = entry.symbol
wrapper.linkage = lc.LINKAGE_EXTERNAL
fnty = cres.target_context.call_conv.get_function_type(
cres.fndesc.restype, cres.fndesc.argtypes)
self.exported_function_types[entry] = fnty
else:
llvm_func.linkage = lc.LINKAGE_EXTERNAL
llvm_func.name = entry.symbol
if self.export_python_wrap:
wrapper_module = library.create_ir_module("wrapper")
self._emit_python_wrapper(wrapper_module)
library.add_ir_module(wrapper_module)
return library
示例10: __init__
# 需要导入模块: from numba.compiler import Flags [as 别名]
# 或者: from numba.compiler.Flags import set [as 别名]
def __init__(self, pyfunc, signature):
self.py_func = pyfunc
self.signature = signature
self.name = pyfunc.__name__
args, return_type = sigutils.normalize_signature(signature)
flags = Flags()
flags.set('no_compile')
self._cres = compile_extra(typingctx=impala_typing,
targetctx=impala_targets, func=pyfunc,
args=args, return_type=return_type,
flags=flags, locals={})
llvm_func = impala_targets.finalize(self._cres.llvm_func, return_type,
args)
self.llvm_func = llvm_func
self.llvm_module = llvm_func.module
示例11: test_array_expr
# 需要导入模块: from numba.compiler import Flags [as 别名]
# 或者: from numba.compiler.Flags import set [as 别名]
def test_array_expr(self):
flags = Flags()
flags.set("enable_pyobject")
global cnd_array_jitted
cr1 = compile_isolated(cnd_array, args=(), flags=flags)
cnd_array_jitted = cr1.entry_point
cr2 = compile_isolated(blackscholes_arrayexpr_jitted, args=(),
flags=flags)
jitted_bs = cr2.entry_point
OPT_N = 400
iterations = 10
stockPrice = randfloat(self.random.random_sample(OPT_N), 5.0, 30.0)
optionStrike = randfloat(self.random.random_sample(OPT_N), 1.0, 100.0)
optionYears = randfloat(self.random.random_sample(OPT_N), 0.25, 10.0)
args = stockPrice, optionStrike, optionYears, RISKFREE, VOLATILITY
ts = timer()
for i in range(iterations):
callResultGold, putResultGold = blackscholes_arrayexpr(*args)
te = timer()
pytime = te - ts
ts = timer()
for i in range(iterations):
callResultNumba, putResultNumba = jitted_bs(*args)
te = timer()
jittime = te - ts
print("Python", pytime)
print("Numba", jittime)
print("Speedup: %s" % (pytime / jittime))
delta = np.abs(callResultGold - callResultNumba)
L1norm = delta.sum() / np.abs(callResultGold).sum()
print("L1 norm: %E" % L1norm)
print("Max absolute error: %E" % delta.max())
self.assertEqual(delta.max(), 0)
示例12: autogenerate
# 需要导入模块: from numba.compiler import Flags [as 别名]
# 或者: from numba.compiler.Flags import set [as 别名]
def autogenerate(cls):
test_flags = ['fastmath', ] # TODO: add 'auto_parallel' ?
# generate all the combinations of the flags
test_flags = sum([list(combinations(test_flags, x)) for x in range( \
len(test_flags)+1)], [])
flag_list = [] # create Flag class instances
for ft in test_flags:
flags = Flags()
flags.set('nrt')
flags.set('error_model', 'numpy')
flags.__name__ = '_'.join(ft+('usecase',))
for f in ft:
flags.set(f)
flag_list.append(flags)
# main loop covering all the modes and use-cases
for dtype in ('complex64', 'float64', 'float32', 'int32', ):
for vlen in vlen2cpu:
for flags in flag_list:
for mode in "scalar", "range", "prange", "numpy":
cls._inject_test(dtype, mode, vlen, flags)
# mark important
if sys.version_info[0] > 2:
for n in ( "test_int32_range4_usecase", # issue #3016
):
setattr(cls, n, tag("important")(getattr(cls, n)))
示例13: _cull_exports
# 需要导入模块: from numba.compiler import Flags [as 别名]
# 或者: from numba.compiler.Flags import set [as 别名]
def _cull_exports(self):
"""Read all the exported functions/modules in the translator
environment, and join them into a single LLVM module.
"""
self.exported_function_types = {}
self.function_environments = {}
self.environment_gvs = {}
codegen = self.context.codegen()
library = codegen.create_library(self.module_name)
# Generate IR for all exported functions
flags = Flags()
flags.set("no_compile")
if not self.export_python_wrap:
flags.set("no_cpython_wrapper")
if self.use_nrt:
flags.set("nrt")
# Compile NRT helpers
nrt_module, _ = nrtdynmod.create_nrt_module(self.context)
library.add_ir_module(nrt_module)
for entry in self.export_entries:
cres = compile_extra(self.typing_context, self.context,
entry.function,
entry.signature.args,
entry.signature.return_type, flags,
locals={}, library=library)
func_name = cres.fndesc.llvm_func_name
llvm_func = cres.library.get_function(func_name)
if self.export_python_wrap:
llvm_func.linkage = lc.LINKAGE_INTERNAL
wrappername = cres.fndesc.llvm_cpython_wrapper_name
wrapper = cres.library.get_function(wrappername)
wrapper.name = self._mangle_method_symbol(entry.symbol)
wrapper.linkage = lc.LINKAGE_EXTERNAL
fnty = cres.target_context.call_conv.get_function_type(
cres.fndesc.restype, cres.fndesc.argtypes)
self.exported_function_types[entry] = fnty
self.function_environments[entry] = cres.environment
self.environment_gvs[entry] = cres.fndesc.env_name
else:
llvm_func.name = entry.symbol
self.dll_exports.append(entry.symbol)
if self.export_python_wrap:
wrapper_module = library.create_ir_module("wrapper")
self._emit_python_wrapper(wrapper_module)
library.add_ir_module(wrapper_module)
# Hide all functions in the DLL except those explicitly exported
library.finalize()
for fn in library.get_defined_functions():
if fn.name not in self.dll_exports:
fn.visibility = "hidden"
return library
示例14: complex_constant
# 需要导入模块: from numba.compiler import Flags [as 别名]
# 或者: from numba.compiler.Flags import set [as 别名]
import numba.unittest_support as unittest
from numba.compiler import compile_isolated, Flags
from numba import utils, jit
from .support import TestCase
def complex_constant(n):
tmp = n + 4
return tmp + 3j
def long_constant(n):
return n + 100000000000000000000000000000000000000000000000
forceobj = Flags()
forceobj.set("force_pyobject")
def loop_nest_3(x, y):
n = 0
for i in range(x):
for j in range(y):
for k in range(x+y):
n += i * j
return n
def array_of_object(x):
return x
示例15: Flags
# 需要导入模块: from numba.compiler import Flags [as 别名]
# 或者: from numba.compiler.Flags import set [as 别名]
from __future__ import print_function
import numpy as np
import numba.unittest_support as unittest
from numba.compiler import compile_isolated, Flags
from numba import types, utils, njit, errors
from numba.tests import usecases
from .support import TestCase
import decimal
enable_pyobj_flags = Flags()
enable_pyobj_flags.set("enable_pyobject")
Noflags = Flags()
def slicing_1d_usecase(a, start, stop, step):
return a[start:stop:step]
def slicing_1d_usecase2(a, start, stop, step):
b = a[start:stop:step]
total = 0
for i in range(b.shape[0]):
total += b[i] * (i + 1)
return total
def slicing_1d_usecase3(a, start, stop):
b = a[start:stop]