Ejemplo n.º 1
0
    def insert_user_function(self, fn, ft):
        """Insert a user function.

        Args
        ----
        - fn:
            object used as callee
        - ft:
            function template
        """
        self._insert_global(fn, types.Function(ft))
Ejemplo n.º 2
0
    def decorate(typing_func):
        def generic(self):
            return typing_func(self.context)

        name = "%s_CallableTemplate" % (func_name, )
        bases = (CallableTemplate, )
        class_dict = dict(key=func, generic=generic)
        template = type(name, bases, class_dict)
        infer(template)
        if callable(func):
            infer_global(func, types.Function(template))
        return typing_func
Ejemplo n.º 3
0
    def resolve___call__(self, classty):
        """
        Resolve a number class's constructor (e.g. calling int(...))
        """
        ty = classty.instance_type

        if not isinstance(ty, types.Number):
            raise errors.TypingError("invalid use of non-number types")

        def typer(val):
            # Scalar constructor, e.g. int32(42)
            return ty

        return types.Function(make_callable_template(key=ty, typer=typer))
Ejemplo n.º 4
0
    def resolve___call__(self, classty):
        """
        Resolve a number class's constructor (e.g. calling int(...))
        """
        ty = classty.instance_type

        def typer(val):
            if isinstance(val, (types.BaseTuple, types.Sequence)):
                # Array constructor, e.g. np.int32([1, 2])
                sig = self.context.resolve_function_type(
                    numpy.array, (val, ), {'dtype': types.DType(ty)})
                return sig.return_type
            else:
                # Scalar constructor, e.g. np.int32(42)
                return ty

        return types.Function(make_callable_template(key=ty, typer=typer))
Ejemplo n.º 5
0
    def test_function_incompatible_templates(self):
        # issue 4345
        def func_stub():
            pass

        def func_stub2():
            pass

        def ol():
            pass

        template1 = make_overload_template(func_stub, ol, {}, True, 'never')
        template2 = make_overload_template(func_stub2, ol, {}, True, 'never')

        with self.assertRaises(ValueError) as raises:
            types.Function((template1, template2))
        self.assertIn("incompatible templates:", str(raises.exception))
Ejemplo n.º 6
0
 def resolve_get_local_size(self, mod):
     return types.Function(Hsa_get_local_size)
Ejemplo n.º 7
0
 def resolve_add(self, mod):
     return types.Function(Hsa_atomic_add)
Ejemplo n.º 8
0
 def resolve_log10(self, mod):
     return types.Function(Math_log10)
Ejemplo n.º 9
0
class MappedInplaceOperator(AbstractTemplate):
    def generic(self, args, kws):
        assert not kws
        if not args:
            return
        first = args[0]
        op = self.mutable_op if first.mutable else self.immutable_op
        return self.context.resolve_function_type(op, args, kws)


# Redirect all functions in the operator module to the corresponding
# built-in operators.

for name, inplace_name, op in utils.operator_map:
    op_func = getattr(operator, name)
    op_type = type('Operator_' + name, (MappedOperator, ), {
        'key': op_func,
        'op': op
    })
    infer_global(op_func, types.Function(op_type))

    if inplace_name:
        op_func = getattr(operator, inplace_name)
        op_type = type('Operator_' + inplace_name, (MappedInplaceOperator, ), {
            'key': op_func,
            'mutable_op': op + '=',
            'immutable_op': op
        })
        infer_global(op_func, types.Function(op_type))
Ejemplo n.º 10
0
    def _register(self):
        from .typing.templates import make_intrinsic_template, infer_global

        template = make_intrinsic_template(self, self._defn, self._name)
        infer(template)
        infer_global(self, types.Function(template))
Ejemplo n.º 11
0
 def resolve_wavebarrier(self, mod):
     return types.Function(Hsa_wavebarrier)
Ejemplo n.º 12
0
 def resolve_get_group_id(self, mod):
     return types.Function(Hsa_get_group_id)
Ejemplo n.º 13
0
 def resolve_isnan(self, mod):
     return types.Function(Math_isnan)
Ejemplo n.º 14
0
 def resolve_trunc(self, mod):
     return types.Function(Math_trunc)
Ejemplo n.º 15
0
 def resolve_ceil(self, mod):
     return types.Function(Math_ceil)
Ejemplo n.º 16
0
 def resolve_floor(self, mod):
     return types.Function(Math_floor)
Ejemplo n.º 17
0
 def resolve_atanh(self, mod):
     return types.Function(Math_atanh)
Ejemplo n.º 18
0
 def resolve_acosh(self, mod):
     return types.Function(Math_acosh)
Ejemplo n.º 19
0
 def resolve_asin(self, mod):
     return types.Function(Math_asin)
Ejemplo n.º 20
0
 def resolve_get_num_groups(self, mod):
     return types.Function(Hsa_get_num_groups)
Ejemplo n.º 21
0
 def resolve_get_work_dim(self, mod):
     return types.Function(Hsa_get_work_dim)
Ejemplo n.º 22
0
 def resolve_isinf(self, mod):
     return types.Function(Math_isinf)
Ejemplo n.º 23
0
 def resolve_mem_fence(self, mod):
     return types.Function(Hsa_mem_fence)
Ejemplo n.º 24
0
 def resolve_degrees(self, mod):
     return types.Function(Math_degrees)
Ejemplo n.º 25
0
 def resolve_activelanepermute_wavewidth(self, mod):
     return types.Function(Hsa_activelanepermute_wavewidth)
Ejemplo n.º 26
0
        for op in sorted(types.signed_domain)
    ]
    cases += [
        signature(types.float64, types.float64, op)
        for op in sorted(types.unsigned_domain)
    ]
    cases += [signature(op, op, op) for op in sorted(types.real_domain)]
    cases += [signature(op, op, op) for op in sorted(types.complex_domain)]


class PowerBuiltin(BinOpPower):
    key = pow
    # TODO add 3 operand version


builtin_global(pow, types.Function(PowerBuiltin))


class BitwiseShiftOperation(ConcreteTemplate):
    cases = list(integer_binop_cases)


@builtin
class BitwiseLeftShift(BitwiseShiftOperation):
    key = "<<"


@builtin
class BitwiseRightShift(BitwiseShiftOperation):
    key = ">>"
Ejemplo n.º 27
0
 def decorate(overload_func):
     template = make_overload_template(func, overload_func, opts, strict)
     infer(template)
     if hasattr(func, '__module__'):
         infer_global(func, types.Function(template))
     return overload_func
Ejemplo n.º 28
0
if np.divide == np.true_divide:
    _aliases.add("divide")

for func in numba.typing.npydecl.supported_ufuncs:
    name = func.__name__

    # _numpy_ufunc(func)


    class typing_class(Series_Numpy_rules_ufunc):
        key = func

    typing_class.__name__ = "resolve_series_{0}".format(name)

    if name not in _aliases:
        infer_global(func, types.Function(typing_class))

# @infer_global(len)
# class LenSeriesType(AbstractTemplate):
#     def generic(self, args, kws):
#         if not kws and len(args) == 1 and isinstance(args[0], SeriesType):
#             return signature(types.intp, *args)

# @infer_global(np.empty_like)
# @infer_global(np.zeros_like)
# @infer_global(np.ones_like)
# class SeriesLikeTyper(NdConstructorLike):
#     def generic(self):
#         typer = super(SeriesLikeTyper, self).generic()
#         def wrapper(*args, **kws):
#             new_args = tuple(if_series_to_array_type(arg) for arg in args)
Ejemplo n.º 29
0
 def resolve_radians(self, mod):
     return types.Function(Math_radians)
Ejemplo n.º 30
0
 def resolve_sqrt(self, mod):
     return types.Function(Math_sqrt)