403Webshell
Server IP : 35.80.110.71  /  Your IP : 216.73.216.221
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux ip-172-31-21-44 6.17.0-1019-aws #19~24.04.1-Ubuntu SMP Tue Jun 23 18:53:06 UTC 2026 x86_64
User : ubuntu ( 1000)
PHP Version : 8.3.31
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/sympy/printing/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/sympy/printing/__pycache__/llvmjitcode.cpython-312.pyc
�

M�ZdC���dZddlZddlmZddlmZddlmZddlm	Z	ddl
mZed�ZerTed	�jZed
�jZej#�ej%�ej'�ddgiZGd�d
e�ZGd�de�Zgae�adaGd�d�ZGd�de�ZGd�d�Zd�Zed��dd��Zy)z�
Use llvmlite to create executable functions from SymPy expressions

This module requires llvmlite (https://github.com/numba/llvmlite).
�N)�
import_module)�Printer)�S)�IndexedBase)�doctest_depends_on�llvmlitezllvmlite.irzllvmlite.binding�
llvm_callablec�X��eZdZdZ�fd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
�xZS)�LLVMJitPrinterzConvert expressions to LLVM IRc����|jdi�|_tstd��t	�|�|i|��tj�|_||_	||_
||_i|_i|_
y)N�func_arg_mapz'llvmlite is required for LLVMJITPrinter)�popr
r�ImportError�super�__init__�ll�
DoubleType�fp_type�module�builder�fn�ext_fn�tmp_var)�selfrrr�args�kwargs�	__class__s      ��</usr/lib/python3/dist-packages/sympy/printing/llvmjitcode.pyrzLLVMJitPrinter.__init__sg���"�J�J�~�r�:�����G�H�H�
���$�)�&�)��}�}�������������������c�"�||j|<y�N)r)r�name�values   r�_add_tmp_varzLLVMJitPrinter._add_tmp_var)s��"����T�rc�T�tj|jt|��Sr!)r�Constantr�float)r�ns  r�
_print_NumberzLLVMJitPrinter._print_Number,s���{�{�4�<�<��q��2�2rc�h�tj|jt|j��Sr!)rr&rr'�p�r�exprs  r�_print_IntegerzLLVMJitPrinter._print_Integer/s���{�{�4�<�<��t�v�v��7�7rc��|jj|�}|s|jj|�}|std|z��|S)N�Symbol not found: %s)r�getr
�LookupError)r�s�vals   r�
_print_SymbolzLLVMJitPrinter._print_Symbol2sH���l�l���q�!����#�#�'�'��*�C���4�q�8�9�9��
rc��|j|j�}|jtjk(r:|j
j
tj|jd�|�S|jtjk(r�|jjd�}|s[tj|j|jg�}tj|j|d�}||jd<|j
j!||gd�S|jdk(r|j
j#||�S|j|j�}|jjd�}|sftj|j|j|jg�}tj|j|d�}||jd<|j
j!|||gd�S)Ng�?�sqrt��pow)�_print�base�expr�NegativeOner�fdivrr&r�Halfrr1�FunctionType�Functionr�call�fmul)rr-�base0r�fn_type�exp0s      r�
_print_PowzLLVMJitPrinter._print_Pow;ss�����D�I�I�&���8�8�q�}�}�$��<�<�$�$�R�[�[����s�%C�U�K�K��8�8�q�v�v��������(�B���/�/�$�,�,�����G���[�[����g�v�>��&(����F�#��<�<�$�$�R�%��&�9�9��8�8�q�=��<�<�$�$�U�E�2�2��{�{�4�8�8�$��
�[�[�_�_�U�
#����o�o�d�l�l�T�\�\�4�<�<�4P�Q�G����T�[�[�'�5�9�B�!#�D�K�K����|�|� � ��e�T�]�E�:�:rc��|jD�cgc]}|j|���}}|d}|ddD]}|jj||�}� |Scc}w�Nr�)rr:rrC�rr-�a�nodes�e�nodes      r�
_print_MulzLLVMJitPrinter._print_MulQ�_��)-���3�A����Q��3��3��!�H���!�"�I�	+�D����!�!�!�T�*�A�	+����	4��Ac��|jD�cgc]}|j|���}}|d}|ddD]}|jj||�}� |Scc}wrI)rr:r�faddrKs      r�
_print_AddzLLVMJitPrinter._print_AddXrQrRc��|jj}|j|jd�}|jj|�}|s[tj|j|jg�}tj|j||�}||j|<|jj||g|�S�Nr)
�func�__name__r:rrr1rr@rrArrrB)rr-r"�e0rrEs      r�_print_FunctionzLLVMJitPrinter._print_Functionas����y�y�!�!��
�[�[����1��
&��
�[�[�_�_�T�
"����o�o�d�l�l�T�\�\�N�C�G����T�[�[�'�4�8�B� "�D�K�K����|�|� � ��b�T�4�0�0rc�0�tdt|�z��)Nz,Unsupported type for LLVM JIT conversion: %s)�	TypeError�typer,s  r�emptyPrinterzLLVMJitPrinter.emptyPrinterks���F��t�*�%�&�	&r)rY�
__module__�__qualname__�__doc__rr$r)r.r5rGrPrUr[r_�
__classcell__�rs@rrrs8���(�
�#�3�8��;�,��1�&rrc�*��eZdZ�fd�Zd�Zd�Z�xZS)�LLVMJitCallbackPrinterc�$��t�|�|i|��yr!�rr)rrrrs   �rrzLLVMJitCallbackPrinter.__init__ss���
���$�)�&�)rc��|j|j\}}t|jdj	��}|j
j
|tjtjd�|�g�}|j
j|tj|j��}|j
j|�}|S)Nr� )r
r;�int�indices�evalfr�geprr&�IntType�bitcast�PointerTyper�load)rr-�array�idx�offset�	array_ptr�fp_array_ptrr#s        r�_print_Indexedz%LLVMJitCallbackPrinter._print_Indexedvs����&�&�t�y�y�1�
��s��T�\�\�!�_�*�*�,�-���L�L�$�$�U�R�[�[����B���-P�,Q�R�	��|�|�+�+�I�r�~�~�d�l�l�7S�T�����!�!�,�/���rc���|jj|�}|r|S|jj|ddg�\}}|std|z��|jj|tjtjd�|�g�}|jj|tj|j��}|jj|�}|S)Nrr0rj)
rr1r
r2rrnrr&rorprqrrr)rr3r4rsrtrvrwr#s        rr5z$LLVMJitCallbackPrinter._print_Symbol~s����l�l���q�!����J��&�&�*�*�1�t�Q�i�8�
��s���4�q�8�9�9��L�L�$�$�U�R�[�[����B���-M�,N�O�	��|�|�+�+�I�,.�N�N�4�<�<�,H�J�����!�!�,�/���r)rYr`rarrxr5rcrds@rrfrfrs���*��rrfc�B�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�LLVMJitCodec���||_tj�|_tj	d�|_d|_g|_|j|_i|_	d|_
y)N�mod1�)�	signaturerrr�Modulerr�llvm_arg_types�
llvm_ret_type�
param_dict�	link_name)rrs  rrzLLVMJitCode.__init__�sO��"����}�}�����i�i��'������ ���!�\�\��������rc�6�|tjk(rtjd�S|tjk(r|j
S|tjtj�k(rtj|j
�S|tjk(r(tjtjd��S|tjk(r(tjtjd��Stdt|�z�y)NrjzUnhandled ctype = %s)�ctypes�c_intrro�c_doubler�POINTERrq�c_void_p�	py_object�print�str)r�ctypes  r�_from_ctypezLLVMJitCode._from_ctype�s����F�L�L� ��:�:�b�>�!��F�O�O�#��<�<���F�N�N�6�?�?�3�3��>�>�$�,�,�/�/��F�O�O�#��>�>�"�*�*�R�.�1�1��F�$�$�$��>�>�"�*�*�R�.�1�1�
�$�s�5�z�1�2rc���|j|jj�|_|jjD�cgc]}|j|���c}|_ycc}w)z#Create types for function argumentsN)r�r�ret_typer��
arg_ctypesr�)r�	func_argsrLs   r�_create_argszLLVMJitCode._create_args�sM��!�-�-�d�n�n�.E�.E�F���*.�.�.�*C�*C�D�Q�T�
�
�a�
 �D�	
���Ds�A$c�<�d}tdz
a|tt�z|_tj	|j�t
j
|j|j�}t
j|j||j��|_y)z,Create function with name and type signature�jit_funcrJ)r"N)�current_link_suffixr�r��
link_names�addrr@r�r�rArr)r�default_link_namerEs   r�_create_function_basez!LLVMJitCode._create_function_base�sq��'���q� ��*�S�1D�-E�E������t�~�~�&��/�/�$�"4�"4�d�6I�6I�J���+�+�d�k�k�7����+�H��rc���t|�D]R\}}t|�|jj|_|jj||j
|<�Ty)z0Mapping of symbolic values to function argumentsN)�	enumerater�rrr"r��rr��irLs    r�_create_param_dictzLLVMJitCode._create_param_dict�sL���i�(�	1�D�A�q�#&�q�6�D�G�G�L�L��O� �!%�����a��D�O�O�A��	1rc�d�|jjd�}tj|�}t	|j
||j|j��}|j||�}|jj|j||��t|j
�}|S)�'Create function body and return LLVM IR�entry�r
)r�append_basic_blockr�	IRBuilderrrr��
_convert_exprr�ret�_wrap_returnr�)rr-�bb_entryr�ljr��strmods       r�_create_functionzLLVMJitCode._create_function�s����7�7�-�-�g�6���,�,�x�(��
�D�K�K��$�'�'�)-���:��� � ��T�*��
�
�
���t�(�(��S�1�2��T�[�[�!���
rc�P�|jjtjk(r|dStjtj
d��}tj||jg�}tj|j|d�}|D�cgc]}|jj||g���!}}t|�dk(r|d}|Stj
d�g}	|	j|gt|�z�tj||	�}
tj|j|
d�}tjtj
d�t|��g}|j|�|jj||�}|Scc}w)Nrrj�PyFloat_FromDoublerJ�PyTuple_Pack)rr�r�r�rrqror@rrArrrB�len�extendr&)
rr��vals�void_ptr�	wrap_type�wrap_fn�v�wrapped_vals�	final_val�tuple_arg_types�
tuple_type�tuple_fn�
tuple_argss
             rr�zLLVMJitCode._wrap_return�sI��
�>�>�"�"�f�o�o�5���7�N��>�>�"�*�*�R�.�1���O�O�H�t�|�|�n�=�	��+�+�b�i�i��4H�I��?C�D�!��
�
����!��5�D��D��t�9��>�$�Q��I� �� "�z�z�"�~�.�O��"�"�H�:�c�$�i�#7�8�����?�C�J��{�{�2�9�9�j�.�I�H��+�+�b�j�j��n�c�,�6G�H�I�J����l�+��
�
����*�=�I����%Es�$F#c�|�	t|�dk(rw|d}|d}t|�dk7r2|jjtjk(rtd��|D](\}}|j
|�}|j||��*D�cgc]}|j
|���}}|S#t$r|g}Y�.wxYwcc}w)Nr8rrJz>Return of multiple expressions not supported for this callback)	r�rr�r�r��NotImplementedErrorr:r$r])	rr�r-�	tmp_exprs�final_exprsr"rNr4r�s	         rr�zLLVMJitCode._convert_expr�s���	!��4�y�A�~� ��G�	�"�1�g���{�#�q�(�T�^�^�-D�-D����-W�-�.n�o�o�(�/�G�D�!��)�)�A�,�C��O�O�D�#�.�/�'2�2���	�	�!��2��2�����	!��&�K�	!��3s�BB'�B9�'B6�5B6c���tj|�}tj�}d|_tj	�}|j|�|j
|�tjj�j�}tj||�}|j�tj|�	|j!|j"�}|S)Nr8)�llvm�parse_assembly�create_pass_manager_builder�	opt_level�create_module_pass_manager�populate�run�Target�from_default_triple�create_target_machine�create_mcjit_compiler�finalize_object�exe_engines�appendr��
emit_assembly�get_function_addressr�)rr��llmod�pmb�pass_manager�target_machine�exe_eng�fptrs        r�_compile_functionzLLVMJitCode._compile_function	s����#�#�F�+���.�.�0����
��6�6�8�����\�"������
�K�K�+�+�-�C�C�E�	��,�,�U�N�C�����!����7�#���+�+�D�N�N�;���rN)rYr`rarr�r�r�r�r�r�r�r��rrr{r{�s2���3�E�	I�1��!�F�$rr{c�*��eZdZ�fd�Zd�Zd�Z�xZS)�LLVMJitCodeCallbackc�$��t�|�|�yr!rh)rrrs  �rrzLLVMJitCodeCallback.__init__$s���
����#rc�b�t|�D]�\}}t|t�rP|jj||f|j
|<t
|�|jj|_�f|jj|jj|f|j
|<��yr!)
r��
isinstancerrrr�r�r"r�	input_argr�s    rr�z&LLVMJitCodeCallback._create_param_dict's����i�(�	)�D�A�q��!�[�)�&*�g�g�l�l�1�o�q�%9�����"�'*�1�v������Q��$�&*�g�g�l�l�4�>�>�3K�3K�&L�&'�&)�����"�	)rc�x�|jjd�}tj|�}t	|j
||j|j��}|j||�}|jjr�|j|jj|jjtj|j��}t|�D]S\}}tjtj!d�|�}	|j#||	g�}
|j%||
��U|j'tjtj!d�d��n+|j(j'|j+||��t-|j
�}|S)r�r�r�rjr)rr�rr�rfrr�r�r�ret_argrprrqrr�r&rorn�storer�rr�r�)rr-r�rr�r��
output_fp_ptrr�r4�index�output_array_ptrr�s            rr�z$LLVMJitCodeCallback._create_function0s?���7�7�-�-�g�6���,�,�x�(��
#�D�K�K��$�'�'�15���B��� � ��T�*���>�>�!�!�#�O�O�D�G�G�L�L����9O�9O�,P�,.�N�N�4�<�<�,H�J�M�#�C�.�
5���3����B�J�J�r�N�A�6��#*�;�;�}�u�g�#F� ��
�
�c�#3�4�
5�
�K�K����B�J�J�r�N�A�6�7��J�J�N�N�4�,�,�R��5�6��T�[�[�!���
r)rYr`rarr�r�rcrds@rr�r�#s���$�)�rr�c��eZdZd�Zy)�
CodeSignaturec�<�||_g|_d|_d|_yrW)r�r�r�r�)rr�s  rrzCodeSignature.__init__Js"�� ��
���������rN)rYr`rarr�rrr�r�Is��	rr�c���|�t|�}nt|�}|j|�|j�|j	|�|j|�}	|j|�}|S)z5Create a native code function from a SymPy expression)r{r�r�r�r�r�r�r�)rr-r�
callback_type�jitr�r�s       r�_llvm_jit_coder�Vsn�����)�$��!�)�,�����T���������4� �
�
!�
!�$�
'�F��� � ��(�D��Kr)r�scipy)�modulesc���tstd��ttj�}g}|�*|D]#}tj
}|j
|��%�n|dvrptj
|_tjtjtj
�g}tjtj
g}d|_
n�|dk(r�tjtjtj
�tjtjtjtj
�g}tj|_d|_
d|_ntd|z��||_t||||�}|r|dk(r}|jtjk(rtj }	ntj"}	|	|jg|���|�}
|
S)aCompile function from a SymPy expression

    Expressions are evaluated using double precision arithmetic.
    Some single argument math functions (exp, sin, cos, etc.) are supported
    in expressions.

    Parameters
    ==========

    args : List of Symbol
        Arguments to the generated function.  Usually the free symbols in
        the expression.  Currently each one is assumed to convert to
        a double precision scalar.
    expr : Expr, or (Replacements, Expr) as returned from 'cse'
        Expression to compile.
    callback_type : string
        Create function with signature appropriate to use as a callback.
        Currently supported:
           'scipy.integrate'
           'scipy.integrate.test'
           'cubature'

    Returns
    =======

    Compiled function that can evaluate the expression.

    Examples
    ========

    >>> import sympy.printing.llvmjitcode as jit
    >>> from sympy.abc import a
    >>> e = a*a + a + 1
    >>> e1 = jit.llvm_callable([a], e)
    >>> e.subs(a, 1.1)   # Evaluate via substitution
    3.31000000000000
    >>> e1(1.1)  # Evaluate using JIT-compiled code
    3.3100000000000005


    Callbacks for integration functions can be JIT compiled.
    >>> import sympy.printing.llvmjitcode as jit
    >>> from sympy.abc import a
    >>> from sympy import integrate
    >>> from scipy.integrate import quad
    >>> e = a*a
    >>> e1 = jit.llvm_callable([a], e, callback_type='scipy.integrate')
    >>> integrate(e, (a, 0.0, 2.0))
    2.66666666666667
    >>> quad(e1, 0.0, 2.0)[0]
    2.66666666666667

    The 'cubature' callback is for the Python wrapper around the
    cubature package ( https://github.com/saullocastro/cubature )
    and ( http://ab-initio.mit.edu/wiki/index.php/Cubature )

    There are two signatures for the SciPy integration callbacks.
    The first ('scipy.integrate') is the function to be passed to the
    integration routine, and will pass the signature checks.
    The second ('scipy.integrate.test') is only useful for directly calling
    the function using ctypes variables. It will not pass the signature checks
    for scipy.integrate.

    The return value from the cse module can also be compiled.  This
    can improve the performance of the compiled function.  If multiple
    expressions are given to cse, the compiled function returns a tuple.
    The 'cubature' callback handles multiple expressions (set `fdim`
    to match in the integration call.)
    >>> import sympy.printing.llvmjitcode as jit
    >>> from sympy import cse
    >>> from sympy.abc import x,y
    >>> e1 = x*x + y*y
    >>> e2 = 4*(x*x + y*y) + 8.0
    >>> after_cse = cse([e1,e2])
    >>> after_cse
    ([(x0, x**2), (x1, y**2)], [x0 + x1, 4*x0 + 4*x1 + 8.0])
    >>> j1 = jit.llvm_callable([x,y], after_cse)
    >>> j1(1.0, 2.0)
    (5.0, 28.0)
    z$llvmlite is required for llvmjitcode)�scipy.integratezscipy.integrate.testrJ�cubature�zUnknown callback type: %sr�)rrr�r�r�r�r�r�r�r�r�r�r��
ValueErrorr�r��
PYFUNCTYPE�	CFUNCTYPE)rr-r�rr��_�	arg_ctype�arg_ctypes_formalr��FUNCTYPE�cfuncs           rr	r	hs���f��@�A�A��f�.�.�/�I��J����	)�A����I����i�(�	)�
�E�	E�#�_�_�	���l�l�F�N�N�6�?�?�$C�D�
�#�\�\�6�?�?�;���	��	�*�	$��l�l��n�n�V�_�_�5��o�o��l�l��n�n�V�_�_�5�	�
�$�\�\�	���	���	���4�}�D�E�E�%�I���$��i��?�D���*;�;�&�
����V�-�-�-��$�$���#�#��5�H�Y�'�'�5�*�5�d�;�E��Lrr!) rbr��sympy.externalr�sympy.printing.printerr�sympy.core.singletonr�sympy.tensor.indexedr�sympy.utilities.decoratorrr�irr�bindingr��
initialize�initialize_native_target�initialize_native_asmprinter�__doctest_requires__rrfr��setr�r�r{r�r�r�r	r�rr�<module>rs�����(�*�"�,�8���$���	�}�	%�	(�	(�B��+�,�4�4�D��O�O���!�!�#��%�%�'�)�J�<�8��R&�W�R&�n�^��:���U�
���J�J�Z#�+�#�L
�
��$�1�2�@�3�@r

Youez - 2016 - github.com/yon3zu
LinuXploit