本文整理匯總了Python中numba.extending方法的典型用法代碼示例。如果您正苦於以下問題:Python numba.extending方法的具體用法?Python numba.extending怎麽用?Python numba.extending使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numba
的用法示例。
在下文中一共展示了numba.extending方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: do_class_init
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import extending [as 別名]
def do_class_init(cls):
"""
Register generic method implementation.
"""
# this line is changed for __call__
@numba.extending.lower_builtin(cls.key, cls.key, types.VarArg(types.Any))
def method_impl(context, builder, sig, args):
typ = sig.args[0]
typing_context = context.typing_context
fnty = cls._get_function_type(typing_context, typ)
sig = cls._get_signature(typing_context, fnty, sig.args, {})
call = context.get_function(fnty, sig)
# Link dependent library
context.add_linking_libs(getattr(call, 'libs', ()))
return call(builder, args)
示例2: _resolve
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import extending [as 別名]
def _resolve(self, typ, attr):
if self._attr != attr:
return None
assert isinstance(typ, self.key)
class MethodTemplate(AbstractTemplate):
key = self.key # this line is changed for __call__
_inline = self._inline
_overload_func = staticmethod(self._overload_func)
_inline_overloads = self._inline_overloads
def generic(_, args, kws):
args = (typ,) + tuple(args)
fnty = self._get_function_type(self.context, typ)
sig = self._get_signature(self.context, fnty, args, kws)
sig = sig.replace(pysig=numba.extending.utils.pysignature(self._overload_func))
for template in fnty.templates:
self._inline_overloads.update(template._inline_overloads)
if sig is not None:
return sig.as_method()
return types.BoundFunction(MethodTemplate, typ)
示例3: is_alloc_callname
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import extending [as 別名]
def is_alloc_callname(func_name, mod_name):
"""
return true if function represents an array creation call
"""
return isinstance(mod_name, str) and ((mod_name == 'numpy'
and func_name in np_alloc_callnames)
or (func_name == 'empty_inferred'
and mod_name in ('numba.extending', 'numba.unsafe.ndarray'))
or (func_name == 'pre_alloc_string_array'
and mod_name == 'sdc.str_arr_ext')
or (func_name in ('alloc_str_list', 'alloc_list_list_str')
and mod_name == 'sdc.str_ext'))
示例4: overload_call
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import extending [as 別名]
def overload_call(typ, **kwargs):
def decorate(overload_func):
template = make_overload_attribute_template(
typ, '__call__', overload_func,
inline=kwargs.get('inline', 'never'),
base=_OverloadCallTemplate
)
numba.extending.infer_getattr(template)
numba.extending.overload(overload_func, **kwargs)(overload_func)
return overload_func
return decorate
示例5: value_type
# 需要導入模塊: import numba [as 別名]
# 或者: from numba import extending [as 別名]
def value_type(self):
return self._scalar_type[:]
# The docs say we should use register a function to determine the numba type
# with `@numba.extending.typeof_impl.register(MultiVector)`, but this is way
# too slow (https://github.com/numba/numba/issues/5839). Instead, we use the
# undocumented `_numba_type_` attribute, and use our own cache. In future
# this may need to be a weak cache, but for now the objects are tiny anyway.