o
    GZh9R                     @   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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
 qpeD ]Zeed#e e	 q~i d$d%d&d&d'd'd(d)d*d+d,d-d.d/d0d0d1d1d2d2d3d3d4d5d6d7d8d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGZdHddIZdJd e D ZdKd e D ZG dLdM dMeZ eD ]Zee d#e e
 qeD ]Zee d#e e	 qdNd e D Z!dOd e D Z"G dPdQ dQeZ#e!D ]Zee#d#e e
 q!e"D ]Zee#d#e e	 q0dRd e D Z$dSd e D Z%G dTdU dUeZ&e$D ]Zee&d#e e
 qYe%D ]Zee&d#e e	 qhdVS )W    )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   C/var/www/auris/lib/python3.10/site-packages/sympy/printing/numpy.py
<listcomp>	   s     r   ZarccosZarccoshZarcsinZarcsinhZarctanZarctan2Zarctanhexp2sign	logaddexp
logaddexp2isinfisnan)acosacoshasinasinhatanatan2atanhr   r   r   r   r   r   epiZeuler_gammananinf)ZExp1PiZ
EulerGammaNaNInfinityc                 C      i | ]	\}}|d | qS znumpy.r   r   r   r   r   
<dictcomp>"       r+   c                 C   r)   r*   r   r   r   r   r   r+   #   r,   c                       s  e Zd ZdZdZeZeZdY 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dZd1d2Zd3e fd4d5Z!d6d7 Z"d8d9 Z#d:d; Z$d<d= Z%d>d? Z&d@dA Z'dBdC Z(dDdE Z)dFdG Z*dHdI Z+dJdK Z,dLdM Z-dNdO Z.dPdQ Z/dRdS Z0dTZ1dUZ2dVZ3dWZ4dXZ5e6j7Z8e6j7Z9e6j7Z:e6j7Z;  Z<S )[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__selfr0   	__class__r   r   r7   /   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r9   r   r   	<genexpr>B       z*NumPyPrinter._print_seq.<locals>.<genexpr>)r1   join)r9   seq	delimiterr   rB   r   
_print_seq=   s   zNumPyPrinter._print_seqc                 C   s   d|  tj S )N-)r@   r   r(   r9   exprr   r   r   _print_NegativeInfinityD   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   r=   r>   r?   r   irB   r   r   rC   K   rD   z-NumPyPrinter._print_MatMul.<locals>.<genexpr>c                 3   r=   r>   r?   rN   rB   r   r   rC   L   rD   )Zas_coeff_matricesr   ZOner1   rE   args)r9   rK   Z	expr_listr   rB   r   _print_MatMulG   s    zNumPyPrinter._print_MatMulc                 C   s2   d | | jd | |jd | |jd S )zMatrix power printerz
{}({}, {})z.linalg.matrix_powerr   r   r1   _module_formatr2   r@   rP   rJ   r   r   r   _print_MatPowN   s   zNumPyPrinter._print_MatPowc                 C   $   d | | jd | |jd S )zMatrix inverse printer{}({})z.linalg.invr   rR   rJ   r   r   r   _print_InverseS   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)rP   shapeTrS   r2   r@   )r9   rK   Zarg1Zarg2r   r   r   _print_DotProductX   s   
zNumPyPrinter._print_DotProductc                 C   s*   d|  | jd | |j| |jf S )NrX   z.linalg.solve)rS   r2   r@   matrixZvectorrJ   r   r   r   _print_MatrixSolvee   s   

zNumPyPrinter._print_MatrixSolvec                 C       d | | jd | |jS )NrV   z.zerosr1   rS   r2   r@   rY   rJ   r   r   r   _print_ZeroMatrixj      
zNumPyPrinter._print_ZeroMatrixc                 C   r^   )NrV   z.onesr_   rJ   r   r   r   _print_OneMatrixn   ra   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   )rO   jz{}(lambda {}: {}, {})z.fromfunctionr<   c                 3   r=   r>   r?   r   argrB   r   r   rC   x   rD   z5NumPyPrinter._print_FunctionMatrix.<locals>.<genexpr>r   )Z	sympy.abcrO   rc   lamda
isinstancer   r1   rS   r2   rE   rP   r@   rY   )r9   rK   rO   rc   rf   r   rB   r   _print_FunctionMatrixr   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r1   r@   rd   funcr9   r   r   rC   }       z6NumPyPrinter._print_HadamardProduct.<locals>.<genexpr>{}{})r   rS   r2   rE   rP   r1   r@   lenrJ   r   ro   r   _print_HadamardProduct{      z#NumPyPrinter._print_HadamardProductc                    ri   )	Nz.kronrk   c                 3   rl   rm   rn   rd   ro   r   r   rC      rq   z7NumPyPrinter._print_KroneckerProduct.<locals>.<genexpr>rr   rs   rt   r   ru   rJ   r   ro   r   _print_KroneckerProduct   rx   z$NumPyPrinter._print_KroneckerProductc                 C   s2   d | | jd | | jd | |jd S )Nz
{}({}({}))z
.conjugatez
.transposer   rR   rJ   r   r   r   _print_Adjoint   s
   zNumPyPrinter._print_Adjointc                 C   s8   d | | jd | |j}d | | jd |S )NrV   z.diagz{}({}, (-1, 1))z.reshape)r1   rS   r2   r@   re   )r9   rK   Zvectr   r   r   _print_DiagonalOf   s   
zNumPyPrinter._print_DiagonalOfc                 C   rU   )NrV   z	.diagflatr   rR   rJ   r   r   r   _print_DiagMatrix   s   zNumPyPrinter._print_DiagMatrixc              
   C   sJ   d | | jd | |j| | jd | |jd | |jd S )Nz{}({}, {}({}, {}))rj   .eyer   r   )r1   rS   r2   r@   re   rY   rJ   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. )hasr@   Zcond)r   r9   r   r   r   
print_cond   s   

z1NumPyPrinter._print_Piecewise.<locals>.print_condz[{}],c                 3   s    | ]	}  |jV  qd S r>   )r@   rK   rd   rB   r   r   rC      s    z0NumPyPrinter._print_Piecewise.<locals>.<genexpr>c                 3   s    | ]} |j V  qd S r>   r   rd   )r   r   r   rC      rD   z{}({}, {}, default={})z.select)Zsympy.logic.boolalgr   r   r1   rE   rP   rS   r2   r@   r   r'   )r9   rK   exprsZcondsr   )r   r   r9   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lessZ
less_equalZgreaterZgreater_equal)z==z!=<z<=>z>=z{op}({lhs}, {rhs}).)oplhsrhs)	Zrel_opr@   r   r   r1   rS   r2   r6   _print_Relational)r9   rK   r   r   r   r:   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   r=   r>   r?   rN   rB   r   r   rC      rD   z*NumPyPrinter._print_And.<locals>.<genexpr>r1   rS   r2   rE   rP   rJ   r   rB   r   
_print_And      .zNumPyPrinter._print_Andc                    r   )Logical Or printerr   z.logical_orr   c                 3   r=   r>   r?   rN   rB   r   r   rC      rD   z)NumPyPrinter._print_Or.<locals>.<genexpr>r   rJ   r   rB   r   	_print_Or   r   zNumPyPrinter._print_Orc                    r   )zLogical Not printerrV   z.logical_notr   c                 3   r=   r>   r?   rN   rB   r   r   rC      rD   z*NumPyPrinter._print_Not.<locals>.<genexpr>r   rJ   r   rB   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_integerZis_negativer   baseZevalfZ_hprint_Powr2   )r9   rK   r   r   r   r   
_print_Pow   s   zNumPyPrinter._print_Powr   c                    sl   t |dkrtd| t |dkr |d S  d} fdd|D }| d| dd	| d
S )Nr   zNeed at least one argument for r   zfunctools.reducec                       g | ]}  |qS r   r?   rd   rB   r   r   r          z8NumPyPrinter._helper_minimum_maximum.<locals>.<listcomp>(z, [r<   z]))rv   NotImplementedErrorr@   rS   rE   )r9   r   rP   Z_reduces_argsr   rB   r   _helper_minimum_maximum   s   
z$NumPyPrinter._helper_minimum_maximumc                 C   
   |  |S r>   )_print_minimumrJ   r   r   r   
_print_Min      
zNumPyPrinter._print_Minc                 C   *   d | | jd | |j| |jS )N{}({}, axis={})z.aminr1   rS   r2   r@   arrayZaxisrJ   r   r   r   _print_amin      *zNumPyPrinter._print_aminc                 C   $   |  | jd }| j|g|jR  S )Nz.minimumrS   r2   r   rP   r9   rK   r   r   r   r   r         zNumPyPrinter._print_minimumc                 C   r   r>   )_print_maximumrJ   r   r   r   
_print_Max   r   zNumPyPrinter._print_Maxc                 C   r   )Nr   z.amaxr   rJ   r   r   r   _print_amax   r   zNumPyPrinter._print_amaxc                 C   r   )Nz.maximumr   r   r   r   r   r      r   zNumPyPrinter._print_maximumc                 C   $   d|  | jd | |jd f S )N%s(%s)z.angler   rS   r2   r@   rP   rJ   r   r   r   
_print_arg      $zNumPyPrinter._print_argc                 C   r   )Nr   z.imagr   r   rJ   r   r   r   	_print_im   r   zNumPyPrinter._print_imc                    s.   d   jd d fdd|jD f S )Nr   z.modr<   c                 3   r=   r>   r?   rd   rB   r   r   rC     rD   z*NumPyPrinter._print_Mod.<locals>.<genexpr>)rS   r2   rE   rP   rJ   r   rB   r   
_print_Mod   s   zNumPyPrinter._print_Modc                 C   r   )Nr   z.realr   r   rJ   r   r   r   	_print_re  r   zNumPyPrinter._print_rec                 C   s*   d|  | jd | |jd tj f S )Nr   z.sincr   )rS   r2   r@   rP   r   r&   rJ   r   r   r   _print_sinc  r   zNumPyPrinter._print_sincc                 C   s|   d|j v r| | j d| j }| d| |j  dS | j|jjd }|d u r3| | j d}d|| |	 f S )Nr   r   r   rt   .arrayr   )
rY   rS   r2   _zerosr@   Zknown_functionsgetr;   __name__tolistr9   rK   rp   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 r>   )Z
is_Integer)r   dimr   r   r   rC     s    z/NumPyPrinter._print_Identity.<locals>.<genexpr>r   r}   r   zFSymbolic matrix dimensions are not yet supported for identity matrices)rY   allrS   r2   r@   r   )r9   rK   rY   r   r   r   _print_Identity  s   $zNumPyPrinter._print_Identityc                 C   s(   d | | jd | |jd  S )NrV   z.blockr   )r1   rS   r2   r@   rP   r   rJ   r   r   r   _print_BlockMatrix  s   zNumPyPrinter._print_BlockMatrixc                 C   s   |  dkr| | j d}| d| |d  dS d|jv r9| | j d| j }| d| |j dS | | j d}| d| |  dS )Nr   r   r   r   rt   r   )ZrankrS   r2   r@   rY   r   r   r   r   r   r   _print_NDimArray  s   
zNumPyPrinter._print_NDimArrayaddZeinsumZ	transposeZonesZzerosr>   )F)=r   
__module____qualname____doc__r2   _numpy_known_functionsr5   _numpy_known_constants_kcr7   rH   rL   rQ   rT   rW   r[   r]   r`   rb   rh   rw   ry   rz   r{   r|   r~   r   r   r   r   r   r   strr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _addZ_einsumZ
_transposeZ_onesr   r   Z_print_not_supported_print_lowergamma_print_uppergamma_print_fresnelc_print_fresnels__classcell__r   r   r:   r   r-   %   sj    	
		
r-   Z_print_ZEiZexpierferfcZbesseljZjvZbesselyZyvZbesseliZivZbesselkkvZcosm1Zpowm1	factorialgammaZloggammaZgammalnZdigammapsiZ	polygammaZRisingFactorialZpochZjacobiZeval_jacobiZ
gegenbauerZeval_gegenbauerZeval_chebytZeval_chebyuZeval_legendreZeval_hermiteZeval_laguerreZeval_genlaguerrebetaZlambertw)Z
chebyshevtZ
chebyshevuZlegendreZhermiteZlaguerreZassoc_laguerrer   ZLambertWZgolden_ratio)ZGoldenRatior&   c                 C   r)   )zscipy.special.r   r   r   r   r   r+   Y  r,   c                 C   r)   )zscipy.constants.r   r   r   r   r   r+   Z  r,   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 )Nr/   zPython with SciPy and NumPy)r6   r7   r3   r8   r:   r   r   r7   a     
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datarO   rc   rY   )Ztodokitemsappendr1   rS   rY   )r9   rK   rO   rc   r   rcr   r   r   r   _print_SparseRepMatrixe  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      r1   rS   r@   rP   rJ   r   r   r   _print_assoc_legendret  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   rJ   r   r   r   r   {     zSciPyPrinter._print_lowergammac              	   C   r   )Nr   r   zscipy.special.gammainccr   r   r   rJ   r   r   r   r     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                    r   r   r?   rd   rB   r   r   r     r   z/SciPyPrinter._print_betainc.<locals>.<listcomp>r   r   r<   r      z) - r   z))             * rt   )rS   rP   )r9   rK   Zbetaincr   rP   r   rB   r   _print_betainc  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   rJ   r   r   r   _print_betainc_regularized  s   z'SciPyPrinter._print_betainc_regularizedc                 C      d | d| |jd S )N	{}({})[0]scipy.special.fresnelr   r   rJ   r   r   r   r        zSciPyPrinter._print_fresnelsc                 C   r   )N	{}({})[1]r   r   r   rJ   r   r   r   r     r   zSciPyPrinter._print_fresnelcc                 C   r   )Nr   scipy.special.airyr   r   rJ   r   r   r   _print_airyai  r   zSciPyPrinter._print_airyaic                 C   r   )Nr   r   r   r   rJ   r   r   r   _print_airyaiprime  r   zSciPyPrinter._print_airyaiprimec                 C   r   )Nz	{}({})[2]r   r   r   rJ   r   r   r   _print_airybi  r   zSciPyPrinter._print_airybic                 C   r   )Nz	{}({})[3]r   r   r   rJ   r   r   r   _print_airybiprime  r   zSciPyPrinter._print_airybiprimec                 C      |  |j|j S r>   r@   Z_eval_rewrite_as_zetarP   rJ   r   r   r   _print_bernoulli  s   zSciPyPrinter._print_bernoullic                 C   r  r>   r  rJ   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.nquadrM   r<   c                 3   s$    | ]}d t t j| V  qdS )z(%s, %s)N)tuplemapr@   )r   lrB   r   r   rC     s    
z/SciPyPrinter._print_Integral.<locals>.<genexpr>z{}(lambda {}: {}, {})[0])	r
   rv   rS   r  r  r@   r1   rE   rP   )r9   r"   Zintegration_varsZlimitsZ
module_strZ	limit_strr   rB   r   _print_Integral  s   


zSciPyPrinter._print_Integralc                 C   r   )Nr   scipy.special.sicir   r   rJ   r   r   r   	_print_Si  r   zSciPyPrinter._print_Sic                 C   r   )Nr   r
  r   r   rJ   r   r   r   	_print_Ci  r   zSciPyPrinter._print_Cir>   )r   r   r   r-   r5   _scipy_known_functionsr   _scipy_known_constantsr7   r   Z_print_ImmutableSparseMatrixr   r   r   r   r   r   r   r   r   r   r   r  r  r	  r  r  r   r   r   r:   r   r   \  s,    r   c                 C   r)   zcupy.r   r   r   r   r   r+     r,   c                 C   r)   r  r   r   r   r   r   r+     r,   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.
    ZcupyNc                    s   t  j|d d S )Nr/   )r6   r7   r8   r:   r   r   r7     r  zCuPyPrinter.__init__r>   )r   r   r   r   r2   _cupy_known_functionsr5   _cupy_known_constantsr   r7   r   r   r   r:   r   r    s    r  c                 C   r)   z
jax.numpy.r   r   r   r   r   r+     r,   c                 C   r)   r  r   r   r   r   r   r+     r,   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   )Nr/   Z_jaxcode)r6   r7   r4   r8   r:   r   r   r7     r   zJaxPrinter.__init__c              	      8   d   jd   jd fdd|jD S )r   {}({}.asarray([{}]), axis=0)z.allr   c                 3   r=   r>   r?   rN   rB   r   r   rC     rD   z(JaxPrinter._print_And.<locals>.<genexpr>r   rJ   r   rB   r   r   	  
   
zJaxPrinter._print_Andc              	      r  )r   r  z.anyr   c                 3   r=   r>   r?   rN   rB   r   r   rC     rD   z'JaxPrinter._print_Or.<locals>.<genexpr>r   rJ   r   rB   r   r     r  zJaxPrinter._print_Orr>   )r   r   r   r   r2   _jax_known_functionsr5   _jax_known_constantsr   r7   r   r   r   r   r   r:   r   r    s    r  N)'Z
sympy.corer   Zsympy.core.functionr   Zsympy.core.powerr   Zpycoder   r   r   r	   r
   r   Zcodeprinterr   splitr   r   Z	_in_numpydictZ_known_functions_numpyZ_known_constants_numpyr   r   r-   rp   setattrconstZ_known_functions_scipy_specialZ _known_constants_scipy_constantsr  r  r   r  r  r  r  r  r  r   r   r   r   <module>   s     
  	
}