o
    ohN                     @   s  d dl mZ d dlmZ d dlmZ ddlmZmZm	Z	m
Z
mZmZ ddlmZ d Zdd	 e D Zeefi d
ddddddddddddZddddddZdd e D Zdd e D ZG d d! d!eeZeD ]Zeed"e e
 qoeD ]Zeed"e e	 q}i d#d$d%d%d&d&d'd(d)d*d+d,d-d.d/d/d0d0d1d1d2d2d3d4d5d6d7d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFZdGddHZdId e D ZdJd e D ZG dKdL dLeZ eD ]Zee d"e e
 qeD ]Zee d"e e	 qdMd e D Z!dNd e D Z"G dOdP dPeZ#e!D ]Zee#d"e e
 q e"D ]Zee#d"e e	 q/dQd e D Z$dRd e D Z%G dSdT dTeZ&e$D ]Zee&d"e e
 qXe%D ]Zee&d"e e	 qgdUS )V    )S)Lambda)Pow   )PythonCodePrinter_known_functions_math_print_known_const_print_known_func_unpack_integral_limitsArrayPrinter)CodePrinterz!erf erfc factorial gamma loggammac                 C   s    g | ]\}}|t vr||fqS  )_not_in_numpy.0kvr   r   h/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/printing/numpy.py
<listcomp>	   s     r   arccosarccosharcsinarcsinharctanarctan2arctanhexp2sign	logaddexp
logaddexp2isnan)acosacoshasinasinhatanatan2atanhr   r   r   r   r    epieuler_gammananinf)Exp1Pi
EulerGammaNaNInfinityc                 C      i | ]	\}}|d | qS znumpy.r   r   r   r   r   
<dictcomp>        r4   c                 C   r2   r3   r   r   r   r   r   r4   !   r5   c                       sl  e Zd ZdZdZeZeZdN fdd	Z	dd Z
dd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Z fd(d)Zd*d+ Zd,d- Zd.d/ ZdOd1d2Zd3d4 Z d5d6 Z!d7d8 Z"d9d: Z#d;d< Z$d=d> Z%d?d@ Z&dAdB Z'dCdD Z(dEdF Z) fdGdHZ*dIZ+dJZ,dKZ-dLZ.dMZ/e0j1Z2e0j1Z3e0j1Z4e0j1Z5  Z6S )PNumPyPrinterza
    Numpy printer which handles vectorized piecewise functions,
    logical operators, etc.
    numpyNc                    s@   d | j| _d | j| _i tj| j| _t j|d dS )z
        `settings` is passed to CodePrinter.__init__()
        `module` specifies the array module to use, currently 'NumPy', 'CuPy'
        or 'JAX'.
        zPython with {}z_{}codesettingsN)format_modulelanguageprintmethodr   _kfsuper__init__selfr9   	__class__r   r   r@   -   s   zNumPyPrinter.__init__c                    s"   d}d | fdd|D S )z+General sequence printer: converts to tuple, z({},)c                 3       | ]}  |V  qd S N_print)r   itemrB   r   r   	<genexpr>@       z*NumPyPrinter._print_seq.<locals>.<genexpr>)r:   join)rB   seq	delimiterr   rK   r   
_print_seq;   s   zNumPyPrinter._print_seqc                 C   s   d|  tj S )N-)rI   r   r1   rB   exprr   r   r   _print_NegativeInfinityB   s   z$NumPyPrinter._print_NegativeInfinityc                    sj   |  d tjur%|  d |  d g }dd fdd|D S dd fdd|jD S )zMatrix multiplication printerr   r   ({})z).dot(c                 3   rF   rG   rH   r   irK   r   r   rL   I   rM   z-NumPyPrinter._print_MatMul.<locals>.<genexpr>c                 3   rF   rG   rH   rW   rK   r   r   rL   J   rM   )as_coeff_matricesr   Oner:   rN   args)rB   rT   	expr_listr   rK   r   _print_MatMulE   s    zNumPyPrinter._print_MatMulc                 C   s2   d | | jd | |jd | |jd S )zMatrix power printerz
{}({}, {})z.linalg.matrix_powerr   r   r:   _module_formatr;   rI   r[   rS   r   r   r   _print_MatPowL   s   zNumPyPrinter._print_MatPowc                 C   $   d | | jd | |jd S )zMatrix inverse printer{}({})z.linalg.invr   r^   rS   r   r   r   _print_InverseQ   s   zNumPyPrinter._print_Inversec                 C   sX   |j \}}|jd dkr|j}|jd dkr|j}d| | jd | || |f S )Nr   r   
%s(%s, %s)z.dot)r[   shapeTr_   r;   rI   )rB   rT   arg1arg2r   r   r   _print_DotProductV   s   
zNumPyPrinter._print_DotProductc                 C   s*   d|  | jd | |j| |jf S )Nrd   z.linalg.solve)r_   r;   rI   matrixvectorrS   r   r   r   _print_MatrixSolvec   s   

zNumPyPrinter._print_MatrixSolvec                 C       d | | jd | |jS )Nrb   z.zerosr:   r_   r;   rI   re   rS   r   r   r   _print_ZeroMatrixh      
zNumPyPrinter._print_ZeroMatrixc                 C   rm   )Nrb   z.onesrn   rS   r   r   r   _print_OneMatrixl   rp   zNumPyPrinter._print_OneMatrixc                    s~   ddl m}m} |j}t|tst||f|||}d  jd d	 fdd|j
d D  |j
d  |jS )	Nr   )rX   jz{}(lambda {}: {}, {})z.fromfunctionrE   c                 3   rF   rG   rH   r   argrK   r   r   rL   v   rM   z5NumPyPrinter._print_FunctionMatrix.<locals>.<genexpr>r   )	sympy.abcrX   rr   lamda
isinstancer   r:   r_   r;   rN   r[   rI   re   )rB   rT   rX   rr   rv   r   rK   r   _print_FunctionMatrixp   s   
z"NumPyPrinter._print_FunctionMatrixc                    Z    jd  d fdd|jd d D d|jd dt|jd   S )	N	.multiply c                 3   "    | ]}d   |V  qdS z{}({}, Nr:   rI   rs   funcrB   r   r   rL   {       z6NumPyPrinter._print_HadamardProduct.<locals>.<genexpr>{}{})r   r_   r;   rN   r[   r:   rI   lenrS   r   r   r   _print_HadamardProducty      z#NumPyPrinter._print_HadamardProductc                    ry   )	Nz.kronr{   c                 3   r|   r}   r~   rs   r   r   r   rL      r   z7NumPyPrinter._print_KroneckerProduct.<locals>.<genexpr>r   r   r   r   r   rS   r   r   r   _print_KroneckerProduct   r   z$NumPyPrinter._print_KroneckerProductc                 C   s2   d | | jd | | jd | |jd S )Nz
{}({}({}))z
.conjugatez
.transposer   r^   rS   r   r   r   _print_Adjoint   s
   zNumPyPrinter._print_Adjointc                 C   s8   d | | jd | |j}d | | jd |S )Nrb   z.diagz{}({}, (-1, 1))z.reshape)r:   r_   r;   rI   rt   )rB   rT   vectr   r   r   _print_DiagonalOf   s   
zNumPyPrinter._print_DiagonalOfc                 C   ra   )Nrb   z	.diagflatr   r^   rS   r   r   r   _print_DiagMatrix   s   zNumPyPrinter._print_DiagMatrixc              
   C   sJ   d | | jd | |j| | jd | |jd | |jd S )Nz{}({}, {}({}, {}))rz   .eyer   r   )r:   r_   r;   rI   rt   re   rS   r   r   r   _print_DiagonalMatrix   s   z"NumPyPrinter._print_DiagonalMatrixc                    s   ddl m m  fddddfdd|jD }ddfd	d|jD }d
jd ||t	j
S )zPiecewise function printerr   )ITEsimplify_logicc                    s"   |   r| S | S )z$ Problem having an ITE in the cond. )hasrI   cond)r   rB   r   r   r   
print_cond   s   

z1NumPyPrinter._print_Piecewise.<locals>.print_condz[{}],c                 3   s    | ]	}  |jV  qd S rG   )rI   rT   rs   rK   r   r   rL      s    z0NumPyPrinter._print_Piecewise.<locals>.<genexpr>c                 3   s    | ]} |j V  qd S rG   r   rs   )r   r   r   rL      rM   z{}({}, {}, default={})z.select)sympy.logic.boolalgr   r   r:   rN   r[   r_   r;   rI   r   r0   )rB   rT   exprscondsr   )r   r   rB   r   r   _print_Piecewise   s     
zNumPyPrinter._print_Piecewisec                    sf   ddddddd}|j |v r-| |j}| |j}dj| | jd	 ||j   ||d
S t |S )z.Relational printer for Equality and Unequalityequal	not_equalless
less_equalgreatergreater_equal)z==z!=<z<=>z>=z{op}({lhs}, {rhs}).)oplhsrhs)	rel_oprI   r   r   r:   r_   r;   r?   _print_Relational)rB   rT   r   r   r   rC   r   r   r      s   
zNumPyPrinter._print_Relationalc                    .   d   jd d fdd|jD S )Logical And printer{}.reduce(({}))z.logical_andr   c                 3   rF   rG   rH   rW   rK   r   r   rL      rM   z*NumPyPrinter._print_And.<locals>.<genexpr>r:   r_   r;   rN   r[   rS   r   rK   r   
_print_And      .zNumPyPrinter._print_Andc                    r   )Logical Or printerr   z.logical_orr   c                 3   rF   rG   rH   rW   rK   r   r   rL      rM   z)NumPyPrinter._print_Or.<locals>.<genexpr>r   rS   r   rK   r   	_print_Or   r   zNumPyPrinter._print_Orc                    r   )zLogical Not printerrb   z.logical_notr   c                 3   rF   rG   rH   rW   rK   r   r   rL      rM   z*NumPyPrinter._print_Not.<locals>.<genexpr>r   rS   r   rK   r   
_print_Not   r   zNumPyPrinter._print_NotFc                 C   s<   |j jr|j jrt|j|j  dd}| j||| jd dS )NF)evaluatez.sqrt)rationalsqrt)exp
is_integeris_negativer   baseevalf_hprint_Powr;   )rB   rT   r   r   r   r   
_print_Pow   s   zNumPyPrinter._print_Powc              	      8   d   jd   jd fdd|jD S )N{}({}.asarray([{}]), axis=0)z.aminr   c                 3   rF   rG   rH   rW   rK   r   r   rL      rM   z*NumPyPrinter._print_Min.<locals>.<genexpr>r   rS   r   rK   r   
_print_Min      8zNumPyPrinter._print_Minc              	      r   )Nr   z.amaxr   c                 3   rF   rG   rH   rW   rK   r   r   rL      rM   z*NumPyPrinter._print_Max.<locals>.<genexpr>r   rS   r   rK   r   
_print_Max   r   zNumPyPrinter._print_Maxc                 C   $   d|  | jd | |jd f S )N%s(%s)z.angler   r_   r;   rI   r[   rS   r   r   r   
_print_arg      $zNumPyPrinter._print_argc                 C   r   )Nr   z.imagr   r   rS   r   r   r   	_print_im   r   zNumPyPrinter._print_imc                    s.   d   jd d fdd|jD f S )Nr   z.modrE   c                 3   rF   rG   rH   rs   rK   r   r   rL      rM   z*NumPyPrinter._print_Mod.<locals>.<genexpr>)r_   r;   rN   r[   rS   r   rK   r   
_print_Mod   s   zNumPyPrinter._print_Modc                 C   r   )Nr   z.realr   r   rS   r   r   r   	_print_re   r   zNumPyPrinter._print_rec                 C   s*   d|  | jd | |jd tj f S )Nr   z.sincr   )r_   r;   rI   r[   r   r.   rS   r   r   r   _print_sinc   s   *zNumPyPrinter._print_sincc                 C   s@   | j |jjd }|d u r| | jd }d|| | f S )Nz.arrayr   )known_functionsgetrD   __name__r_   r;   rI   tolist)rB   rT   r   r   r   r   _print_MatrixBase   s   zNumPyPrinter._print_MatrixBasec                 C   sD   |j }tdd |D rd| | jd | |j d f S td)Nc                 s   s    | ]}|j V  qd S rG   )
is_Integer)r   dimr   r   r   rL      s    z/NumPyPrinter._print_Identity.<locals>.<genexpr>r   r   r   zFSymbolic matrix dimensions are not yet supported for identity matrices)re   allr_   r;   rI   NotImplementedError)rB   rT   re   r   r   r   _print_Identity   s   $zNumPyPrinter._print_Identityc                 C   s(   d | | jd | |jd  S )Nrb   z.blockr   )r:   r_   r;   rI   r[   r   rS   r   r   r   _print_BlockMatrix   s   zNumPyPrinter._print_BlockMatrixc                    sV   t |jdkr| jd | |jd  d S t |jdkr$| | S t | |S )Nr   z.array(r   r      )r   re   r;   rI   r[   tomatrixr?   _print_not_supportedrS   rC   r   r   _print_NDimArray   s
   zNumPyPrinter._print_NDimArrayaddeinsum	transposeoneszerosrG   )F)7r   
__module____qualname____doc__r;   _numpy_known_functionsr>   _numpy_known_constants_kcr@   rQ   rU   r]   r`   rc   ri   rl   ro   rq   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _add_einsum
_transpose_ones_zerosr   r   _print_lowergamma_print_uppergamma_print_fresnelc_print_fresnels__classcell__r   r   rC   r   r6   #   s`    	
r6   _print_Eiexpierferfcbesseljjvbesselyyvbesseliivbesselkkvcosm1powm1	factorialgammaloggammagammalndigammapsi	polygammaRisingFactorialpochjacobieval_jacobi
gegenbauereval_gegenbauereval_chebyteval_chebyueval_legendreeval_hermiteeval_laguerreeval_genlaguerrebetalambertw)
chebyshevt
chebyshevulegendrehermitelaguerreassoc_laguerrer  LambertWgolden_ratio)GoldenRatior.   c                 C   r2   )zscipy.special.r   r   r   r   r   r4   :  r5   c                 C   r2   )zscipy.constants.r   r   r   r   r   r4   ;  r5   c                       s   e Zd Zi ejeZi ejeZd& fdd	Zdd Z	e	Z
dd Zdd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Z  ZS )'SciPyPrinterNc                       t  j|d d| _d S )Nr8   zPython with SciPy and NumPy)r?   r@   r<   rA   rC   r   r   r@   B     
zSciPyPrinter.__init__c                 C   sd   g g g }}}|   D ]\\}}}|| || || qdj| d||||jdS )Nz+{name}(({data}, ({i}, {j})), shape={shape})zscipy.sparse.coo_matrix)namedatarX   rr   re   )todokitemsappendr:   r_   re   )rB   rT   rX   rr   r  rcr   r   r   r   _print_SparseRepMatrixF  s   


z#SciPyPrinter._print_SparseRepMatrixc              	   C   s:   d | d| |jd | |jd | |jd S )Nz{0}({2}, {1}, {3})zscipy.special.lpmvr   r   r   r:   r_   rI   r[   rS   r   r   r   _print_assoc_legendreU  s   z"SciPyPrinter._print_assoc_legendrec              	   C   4   d | d| d| |jd | |jd S )N{0}({2})*{1}({2}, {3})scipy.special.gammazscipy.special.gammaincr   r   r&  rS   r   r   r   r   \     zSciPyPrinter._print_lowergammac              	   C   r(  )Nr)  r*  zscipy.special.gammainccr   r   r&  rS   r   r   r   r   c  r+  zSciPyPrinter._print_uppergammac                    s     d}  d} fdd|jD }d| d|d  d|d  d|d	  d
| d|d  d|d  d|d  d| d|d  d|d  dS )Nscipy.special.betainczscipy.special.betac                    s   g | ]}  |qS r   rH   rs   rK   r   r   r   m  s    z/SciPyPrinter._print_betainc.<locals>.<listcomp>(r   rE   r      z) - r   z))             * r   )r_   r[   )rB   rT   betaincr  r[   r   rK   r   _print_betaincj  s   

JzSciPyPrinter._print_betaincc              
   C   sH   d | d| |jd | |jd | |jd | |jd S )Nz'{0}({1}, {2}, {4}) - {0}({1}, {2}, {3})r,  r   r   r   r.  r&  rS   r   r   r   _print_betainc_regularizedq  s   z'SciPyPrinter._print_betainc_regularizedc                 C      d | d| |jd S )N	{}({})[0]scipy.special.fresnelr   r&  rS   r   r   r   r   y     zSciPyPrinter._print_fresnelsc                 C   r2  )N	{}({})[1]r4  r   r&  rS   r   r   r   r   ~  r5  zSciPyPrinter._print_fresnelcc                 C   r2  )Nr3  scipy.special.airyr   r&  rS   r   r   r   _print_airyai  r5  zSciPyPrinter._print_airyaic                 C   r2  )Nr6  r7  r   r&  rS   r   r   r   _print_airyaiprime  r5  zSciPyPrinter._print_airyaiprimec                 C   r2  )Nz	{}({})[2]r7  r   r&  rS   r   r   r   _print_airybi  r5  zSciPyPrinter._print_airybic                 C   r2  )Nz	{}({})[3]r7  r   r&  rS   r   r   r   _print_airybiprime  r5  zSciPyPrinter._print_airybiprimec                 C      |  |j|j S rG   rI   _eval_rewrite_as_zetar[   rS   r   r   r   _print_bernoulli  s   zSciPyPrinter._print_bernoullic                 C   r<  rG   r=  rS   r   r   r   _print_harmonic     zSciPyPrinter._print_harmonicc                    s   t |\}}t|dkr d}dtt j|d  }n d}dd fdd	|D }d
|dt j| |jd |S )Nr   zscipy.integrate.quadz%s, %sr   zscipy.integrate.nquadrV   rE   c                 3   s$    | ]}d t t j| V  qdS )z(%s, %s)N)tuplemaprI   )r   lrK   r   r   rL     s    
z/SciPyPrinter._print_Integral.<locals>.<genexpr>z{}(lambda {}: {}, {})[0])	r
   r   r_   rB  rC  rI   r:   rN   r[   )rB   r(   integration_varslimits
module_str	limit_strr   rK   r   _print_Integral  s   


zSciPyPrinter._print_Integralc                 C   r2  )Nr3  scipy.special.sicir   r&  rS   r   r   r   	_print_Si  r5  zSciPyPrinter._print_Sic                 C   r2  )Nr6  rJ  r   r&  rS   r   r   r   	_print_Ci  r5  zSciPyPrinter._print_CirG   )r   r   r   r6   r>   _scipy_known_functionsr   _scipy_known_constantsr@   r%  _print_ImmutableSparseMatrixr'  r   r   r0  r1  r   r   r8  r9  r:  r;  r?  r@  rI  rK  rL  r   r   r   rC   r   r  =  s,    r  c                 C   r2   zcupy.r   r   r   r   r   r4     r5   c                 C   r2   rP  r   r   r   r   r   r4     r5   c                       s.   e Zd ZdZdZeZeZd fdd	Z	  Z
S )CuPyPrinterz`
    CuPy printer which handles vectorized piecewise functions,
    logical operators, etc.
    cupyNc                    s   t  j|d d S )Nr8   )r?   r@   rA   rC   r   r   r@     rA  zCuPyPrinter.__init__rG   )r   r   r   r   r;   _cupy_known_functionsr>   _cupy_known_constantsr   r@   r   r   r   rC   r   rQ    s    rQ  c                 C   r2   z
jax.numpy.r   r   r   r   r   r4     r5   c                 C   r2   rU  r   r   r   r   r   r4     r5   c                       s>   e Zd ZdZdZeZeZd
 fdd	Z	dd Z
dd	 Z  ZS )
JaxPrinterz_
    JAX printer which handles vectorized piecewise functions,
    logical operators, etc.
    z	jax.numpyNc                    r  )Nr8   _jaxcode)r?   r@   r=   rA   rC   r   r   r@     r  zJaxPrinter.__init__c              	      r   )r   r   z.allr   c                 3   rF   rG   rH   rW   rK   r   r   rL     rM   z(JaxPrinter._print_And.<locals>.<genexpr>r   rS   r   rK   r   r     
   
zJaxPrinter._print_Andc              	      r   )r   r   z.anyr   c                 3   rF   rG   rH   rW   rK   r   r   rL     rM   z'JaxPrinter._print_Or.<locals>.<genexpr>r   rS   r   rK   r   r     rX  zJaxPrinter._print_OrrG   )r   r   r   r   r;   _jax_known_functionsr>   _jax_known_constantsr   r@   r   r   r   r   r   rC   r   rV    s    rV  N)'
sympy.corer   sympy.core.functionr   sympy.core.powerr   pycoder   r   r   r	   r
   r   codeprinterr   splitr   r!  	_in_numpydict_known_functions_numpy_known_constants_numpyr   r   r6   r   setattrconst_known_functions_scipy_special _known_constants_scipy_constantsrM  rN  r  rS  rT  rQ  rY  rZ  rV  r   r   r   r   <module>   s     
 q	
}