Example #1
0
        def gen_ol(impl, strict=True):

            def myoverload(a, kw=None):
                pass

            overload(myoverload, strict=strict)(impl)

            @jit(nopython=True)
            def foo(a, b):
                return myoverload(a, kw=11)

            return foo
Example #2
0
    def test_typing_vs_impl_signature_mismatch_handling_var_positional(self):
        """
        Tests that an overload which has a differing typing and implementing
        signature raises an exception and uses VAR_POSITIONAL (*args) in typing
        """
        def myoverload(a, kw=None):
            pass

        from .overload_usecases import var_positional_impl
        overload(myoverload)(var_positional_impl)

        @jit(nopython=True)
        def foo(a, b):
            return myoverload(a, b, 9, kw=11)

        with self.assertRaises(errors.TypingError) as e:
            foo(1, 5)
        msg = str(e.exception)
        self.assertIn("VAR_POSITIONAL (e.g. *args) argument kind", msg)
        self.assertIn("offending argument name is '*star_args_token'", msg)
Example #3
0
    def test_typing_vs_impl_signature_mismatch_handling_var_positional(self):
        """
        Tests that an overload which has a differing typing and implementing
        signature raises an exception and uses VAR_POSITIONAL (*args) in typing
        """
        def myoverload(a, kw=None):
            pass

        from .overload_usecases import var_positional_impl
        overload(myoverload)(var_positional_impl)


        @jit(nopython=True)
        def foo(a, b):
            return myoverload(a, b, 9, kw=11)

        with self.assertRaises(errors.TypingError) as e:
            foo(1, 5)
        msg = str(e.exception)
        self.assertIn("VAR_POSITIONAL (e.g. *args) argument kind", msg)
        self.assertIn("offending argument name is '*star_args_token'", msg)
Example #4
0
def sdc_overload(func, jit_options={}, strict=True, inline=None):
    if 'parallel' not in jit_options:
        jit_options = jit_options.copy()
        jit_options.update({'parallel': config_use_parallel_overloads})

    if inline is None:
        inline = 'always' if config_inline_overloads else 'never'

    return overload(func,
                    jit_options=jit_options,
                    strict=strict,
                    inline=inline)
Example #5
0
def sdc_overload(func,
                 jit_options={},
                 parallel=None,
                 strict=True,
                 inline=None):
    jit_options = update_jit_options(jit_options, parallel,
                                     config_use_parallel_overloads)

    if inline is None:
        inline = 'always' if config_inline_overloads else 'never'

    return overload(func,
                    jit_options=jit_options,
                    strict=strict,
                    inline=inline)
Example #6
0
 def add_scipy_special_overloads():
     for name, sigs in name_to_numba_signatures.items():
         sig = sigs[0]  # Sig is a tuple of arguments
         func = getattr(sc, name)
         overload(func)(select_kernel(name, sigs[0]))
Example #7
0
            def impl(a, b):
                return val

            return impl
        elif a_none ^ b_none:

            def impl(a, b):
                return not val

            return impl

    return none_equality


overload(operator.eq)(gen_non_eq(True))
overload(operator.ne)(gen_non_eq(False))

#-------------------------------------------------------------------------------


@lower_getattr_generic(types.DeferredType)
def deferred_getattr(context, builder, typ, value, attr):
    """
    Deferred.__getattr__ => redirect to the actual type.
    """
    inner_type = typ.get()
    val = context.cast(builder, value, typ, inner_type)
    imp = context.get_getattr(inner_type, attr)
    return imp(context, builder, inner_type, val, attr)