Esempio n. 1
0
def abs_(typesystem, node, x):
    from . import builtinmodule

    argtype = get_type(x)
    nodes.annotate(typesystem.env, node, is_math=True)

    if argtype.is_array and argtype.dtype.is_numeric:
        # Handle np.abs() on arrays
        dtype = builtinmodule.abstype(argtype.dtype)
        result_type = argtype.add('dtype', dtype)
        node.variable = Variable(result_type)
    else:
        node = builtinmodule.abs_(typesystem, node, x)

    return node
Esempio n. 2
0
def infer_unary_math_call(context, call_node, arg, default_result_type=double):
    "Resolve calls to math functions to llvm.log.f32() etc"
    # signature is a generic signature, build a correct one
    type = get_type(call_node.args[0])

    if type.is_numeric and type.kind < default_result_type.kind:
        type = default_result_type
    elif type.is_array and type.dtype.is_int:
        type = type.copy(dtype=double)

    # signature = minitypes.FunctionType(return_type=type, args=[type])
    # result = nodes.MathNode(py_func, signature, call_node.args[0])
    nodes.annotate(context.env, call_node, is_math=True)
    call_node.variable = Variable(type)
    return call_node
Esempio n. 3
0
def infer_unary_math_call(context, call_node, arg, default_result_type=double):
    "Resolve calls to math functions to llvm.log.f32() etc"
    # signature is a generic signature, build a correct one
    type = get_type(call_node.args[0])

    if type.is_numeric and type.kind < default_result_type.kind:
        type = default_result_type
    elif type.is_array and type.dtype.is_int:
        type = type.copy(dtype=double)

    # signature = minitypes.FunctionType(return_type=type, args=[type])
    # result = nodes.MathNode(py_func, signature, call_node.args[0])
    nodes.annotate(context.env, call_node, is_math=True)
    call_node.variable = Variable(type)
    return call_node
Esempio n. 4
0
def abs_(typesystem, node, x):
    from . import builtinmodule

    argtype = get_type(x)
    nodes.annotate(typesystem.env, node, is_math=True)

    if argtype.is_array and argtype.dtype.is_numeric:
        # Handle np.abs() on arrays
        dtype = builtinmodule.abstype(argtype.dtype)
        result_type = argtype.add('dtype', dtype)
        node.variable = Variable(result_type)
    else:
        node = builtinmodule.abs_(typesystem, node, x)

    return node
Esempio n. 5
0
    def infer(typesystem, call_node, *args):
        "Resolve calls to llvmmath math calls"
        # signature is a generic signature, build a correct one
        type = reduce(typesystem.promote, map(get_type, call_node.args))

        if type.is_numeric and rank(type) < rank(default_result_type):
            type = default_result_type
        elif type.is_array and type.dtype.is_int:
            type = typesystem.array(double, type.ndim)

        call_node.args[:] = nodes.CoercionNode.coerce(call_node.args, type)

        # TODO: Remove the abuse below
        nodes.annotate(typesystem.env, call_node, is_math=True)
        call_node.variable = Variable(type)
        return call_node
Esempio n. 6
0
    def infer(typesystem, call_node, *args):
        "Resolve calls to llvmmath math calls"
        # signature is a generic signature, build a correct one
        type = reduce(typesystem.promote, map(get_type, call_node.args))

        if type.is_numeric and rank(type) < rank(default_result_type):
            type = default_result_type
        elif type.is_array and type.dtype.is_int:
            type = typesystem.array(double, type.ndim)

        call_node.args[:] = nodes.CoercionNode.coerce(call_node.args, type)

        # TODO: Remove the abuse below
        nodes.annotate(typesystem.env, call_node, is_math=True)
        call_node.variable = Variable(type)
        return call_node
Esempio n. 7
0
def infer_unary_cmath_call(context, call_node, arg):
    result = infer_unary_math_call(context, call_node, arg,
                                   default_result_type=complex128)
    nodes.annotate(context.env, call_node, is_cmath=True)
    return result
Esempio n. 8
0
def infer_unary_cmath_call(context, call_node, arg):
    result = infer_unary_math_call(context, call_node, arg,
                                   default_result_type=complex128)
    nodes.annotate(context.env, call_node, is_cmath=True)
    return result