示例#1
0
def typeset_matching():
    numeric = typeset.typeset([int_, longlong])
    n = numeric(numeric, numeric)
    f = numba.floating(numba.floating, numba.floating)

    signatures = [n, f, object_(object_, object_)]
    ts = typeset.typeset(signatures)

    assert ts.find_match(promote, [float_, float_]) == s(float_)
    assert ts.find_match(promote, [float_, double]) == s(double)
    assert ts.find_match(promote, [longdouble, float_]) == s(longdouble)

    assert ts.find_match(promote, [int_, int_]) == s(int_)
示例#2
0
def test_typeset_matching():
    numeric = typeset.typeset([int_, longlong])
    n = numeric(numeric, numeric)
    f = numba.floating(numba.floating, numba.floating)

    signatures = [n, f, object_(object_, object_)]
    ts = typeset.typeset(signatures)

    assert ts.find_match(context, [float_, float_]) == s(float_)
    assert ts.find_match(context, [float_, double]) == s(double)
    assert ts.find_match(context, [longdouble, float_]) == s(longdouble)

    assert ts.find_match(context, [int_, int_]) == s(int_)
    assert ts.find_match(context, [int_, longlong]) == s(longlong)
    assert ts.find_match(context, [short, int_]) == s(int_)

    assert ts.find_match(context, [short, ulonglong]) is None
示例#3
0
def test_typeset_matching():
    context = NumbaEnvironment.get_environment().context

    numeric = typeset.typeset([int_, longlong])
    n = numeric(numeric, numeric)
    f = numba.floating(numba.floating, numba.floating)

    signatures = [n, f, object_(object_, object_)]
    ts = typeset.typeset(signatures)

    assert ts.find_match(context, [float_, float_]) == s(float_)
    assert ts.find_match(context, [float_, double]) == s(double)
    assert ts.find_match(context, [longdouble, float_]) == s(longdouble)

    assert ts.find_match(context, [int_, int_]) == s(int_)
    assert ts.find_match(context, [int_, longlong]) == s(longlong)
    assert ts.find_match(context, [short, int_]) == s(int_)

    assert ts.find_match(context, [short, ulonglong]) is None
示例#4
0
def register_callable(signature):
    """
    signature := FunctionType | typeset(signature *)

    @register_callable(signature)
    def my_function(...):
        ...
    """
    assert isinstance(signature, (typeset.typeset, minitypes.Type))

    # convert void return type to object_ (None)
    def convert_void_to_object(sig):
        from copy import copy
        if sig.return_type == void:
            sig = copy(sig)
            sig.return_type = object_
        return sig

    if isinstance(signature, typeset.typeset):
        signature = typeset.typeset([convert_void_to_object(x)
                                     for x in signature.types],
                                    name=signature.name)
    else:
        assert isinstance(signature, minitypes.Type)
        signature = convert_void_to_object(signature)


    def decorator(function):
        def infer(context, *args):
            if signature.is_typeset:
                specialization = signature.find_match(context, args)
            else:
                specialization = typeset.match(context, signature, args)

            if specialization is None:
                raise UnmatchedTypeError(
                        "Unmatched argument types for function '%s': %s" %
                                                    (function.__name__, args))

            assert specialization.is_function
            return specialization.return_type

        register_value(function, infer)
        return function

    return decorator