

@doctest_depends_on(modules=('llvmlite', 'scipy'))
def llvm_callable(args, expr, callback_type=None):
    "Compile function from a Sympy expression\n\n    Expressions are evaluated using double precision arithmetic.\n    Some single argument math functions (exp, sin, cos, etc.) are supported\n    in expressions.\n\n    Parameters\n    ==========\n    args : List of Symbol\n        Arguments to the generated function.  Usually the free symbols in\n        the expression.  Currently each one is assumed to convert to\n        a double precision scalar.\n    expr : Expr, or (Replacements, Expr) as returned from 'cse'\n        Expression to compile.\n    callback_type : string\n        Create function with signature appropriate to use as a callback.\n        Currently supported:\n           'scipy.integrate'\n           'scipy.integrate.test'\n           'cubature'\n\n    Returns\n    =======\n    Compiled function that can evaluate the expression.\n\n    Examples\n    ========\n    >>> import sympy.printing.llvmjitcode as jit\n    >>> from sympy.abc import a\n    >>> e = a*a + a + 1\n    >>> e1 = jit.llvm_callable([a], e)\n    >>> e.subs(a, 1.1)   # Evaluate via substitution\n    3.31000000000000\n    >>> e1(1.1)  # Evaluate using JIT-compiled code\n    3.3100000000000005\n\n\n    Callbacks for integration functions can be JIT compiled.\n    >>> import sympy.printing.llvmjitcode as jit\n    >>> from sympy.abc import a\n    >>> from sympy import integrate\n    >>> from scipy.integrate import quad\n    >>> e = a*a\n    >>> e1 = jit.llvm_callable([a], e, callback_type='scipy.integrate')\n    >>> integrate(e, (a, 0.0, 2.0))\n    2.66666666666667\n    >>> quad(e1, 0.0, 2.0)[0]\n    2.66666666666667\n\n    The 'cubature' callback is for the Python wrapper around the\n    cubature package ( https://github.com/saullocastro/cubature )\n    and ( http://ab-initio.mit.edu/wiki/index.php/Cubature )\n\n    There are two signatures for the SciPy integration callbacks.\n    The first ('scipy.integrate') is the function to be passed to the\n    integration routine, and will pass the signature checks.\n    The second ('scipy.integrate.test') is only useful for directly calling\n    the function using ctypes variables. It will not pass the signature checks\n    for scipy.integrate.\n\n    The return value from the cse module can also be compiled.  This\n    can improve the performance of the compiled function.  If multiple\n    expressions are given to cse, the compiled function returns a tuple.\n    The 'cubature' callback handles multiple expressions (set `fdim`\n    to match in the integration call.)\n    >>> import sympy.printing.llvmjitcode as jit\n    >>> from sympy import cse, exp\n    >>> from sympy.abc import x,y\n    >>> e1 = x*x + y*y\n    >>> e2 = 4*(x*x + y*y) + 8.0\n    >>> after_cse = cse([e1,e2])\n    >>> after_cse\n    ([(x0, x**2), (x1, y**2)], [x0 + x1, 4*x0 + 4*x1 + 8.0])\n    >>> j1 = jit.llvm_callable([x,y], after_cse)\n    >>> j1(1.0, 2.0)\n    (5.0, 28.0)\n    "
    if (not llvmlite):
        raise ImportError('llvmlite is required for llvmjitcode')
    signature = CodeSignature(ctypes.py_object)
    arg_ctypes = []
    if (callback_type is None):
        for arg in args:
            arg_ctype = ctypes.c_double
            arg_ctypes.append(arg_ctype)
    elif ((callback_type == 'scipy.integrate') or (callback_type == 'scipy.integrate.test')):
        signature.ret_type = ctypes.c_double
        arg_ctypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_double)]
        arg_ctypes_formal = [ctypes.c_int, ctypes.c_double]
        signature.input_arg = 1
    elif (callback_type == 'cubature'):
        arg_ctypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_double), ctypes.c_void_p, ctypes.c_int, ctypes.POINTER(ctypes.c_double)]
        signature.ret_type = ctypes.c_int
        signature.input_arg = 1
        signature.ret_arg = 4
    else:
        raise ValueError(('Unknown callback type: %s' % callback_type))
    signature.arg_ctypes = arg_ctypes
    fptr = _llvm_jit_code(args, expr, arg_ctype, callback_type)
    if (callback_type and (callback_type == 'scipy.integrate')):
        arg_ctypes = arg_ctypes_formal
    cfunc = ctypes.CFUNCTYPE(signature.ret_type, *arg_ctypes)(fptr)
    return cfunc

dataset/ETHPy150Open sympy/sympy/sympy/printing/llvmjitcode.py llvm_callable/VarMisuse@244/1550 `signature`->`arg_ctype`