Python numba.extending() Examples

The following are 5 code examples of numba.extending(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module numba , or try the search function .
Example #1
Source File: _overload_call.py    From clifford with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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) 
Example #2
Source File: _overload_call.py    From clifford with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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) 
Example #3
Source File: utils.py    From sdc with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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')) 
Example #4
Source File: _overload_call.py    From clifford with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #5
Source File: _multivector.py    From clifford with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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.