
    \h|)                         S SK JrJr  S SKJr  S SKJr  S SKJr  S SK	J
r
  S SKJr  S SKJr  S SKJr  S S	Kr\
" S
5      r " S S\\5      rSS jrg	)    )AbstractPythonCodePrinterArrayPrinter)
MatrixExpr)Mul)
PRECEDENCE)import_module)Sqrt)S)IntegerNtorchc                   (  ^  \ rS rSrSr0 \R                  S_\R                  S_\R                  S_\R                  S_\R                  S_\R                  S_\S	_\R                  S
_\R                  S_\R                  S_\R                   S_\R"                  S_\R$                  S_\R&                  S_\R(                  S_\R*                  S_\R,                  S_0 \R.                  S_\R0                  S_\R2                  S_\R4                  S_\R6                  S_\R8                  S_\R:                  S_\R<                  S_\R>                  S_\R@                  S_\RB                  S_\RD                  S_\RF                  S _\RH                  S!_\RJ                  S"_\RL                  S#_\RN                  S$_E\RP                  S%\RR                  S&\RT                  S'\RV                  S(\RX                  S)\RZ                  S*\R\                  S+0Er/\0" \1Rd                  S,S-S.S/9r2SLU 4S0 jjr3U 4S1 jr4\4r5\4r6\4r7\4r8\4r9\4r:\4r;\4r<\4r=\4r>S2 r?S3 r@S4 rAS5 rBS6 rCS7 rDS8 rES9 rFS: rGS; rHS< rIS= rJS> rKS? rLS@ rMSA rNSB rOSC rPSD rQSErRSFrSSGrTSHrUSIrVSJrWSKrXU =rY$ )MTorchPrinter   
_torchcodez	torch.absz
torch.signz
torch.ceilztorch.floorz	torch.logz	torch.exp
torch.sqrtz	torch.cosz
torch.acosz	torch.sinz
torch.asinz	torch.tanz
torch.atanztorch.atan2z
torch.coshztorch.acoshz
torch.sinhztorch.asinhz
torch.tanhztorch.atanh	torch.powz
torch.realz
torch.imagztorch.anglez	torch.erfztorch.lgammaztorch.eqztorch.neztorch.gtztorch.ltztorch.leztorch.geztorch.logical_andztorch.logical_orztorch.logical_notz	torch.maxz	torch.minz	torch.addz	torch.mulztorch.tracez	torch.detNFtorch.float64)torch_versionrequires_graddtypec                    > [         TU ]  U5        U R                  S   nU R                  S   U l        U R                  S   U l        Uc  [
        (       a  [
        R                  nX l        g )Nr   r   r   )super__init__	_settingsr   r   r   __version__r   )selfsettingsversion	__class__s      N/var/www/auris/envauris/lib/python3.13/site-packages/sympy/printing/pytorch.pyr   TorchPrinter.__init__S   sY    "..1!^^O<^^G,
?uu''G$    c                 H  > U R                   R                  [        U5      S 5      nUc  [        TU ]  U5      $ UR
                   Vs/ s H  o0R                  U5      PM     nn[        U5      S:X  a  U R                  U5      < SUS   < S3$ U R                  X$5      $ s  snf )N   (r   ))
mappinggettyper   _print_Basicargs_printlen_module_format_expand_fold_binary_op)r   expropargchildrenr   s        r    _print_FunctionTorchPrinter._print_Function]   s    \\d4j$/:7'--04		:	KK$	:x=A##B' 
 ..r<< ;s   Bc                 |    SR                  U R                  S5      U R                  UR                  S   5      5      $ )N{}({})ztorch.linalg.invr   )formatr.   r,   r+   r   r0   s     r    _print_InverseTorchPrinter._print_Inversew   s5    t223EF#{{499Q<8: 	:r"   c                     UR                   R                  (       a_  UR                   R                  S   UR                   R                  S   :X  a+  SR                  SU R	                  UR                   5      5      $ SR                  U R	                  UR                   5      SR                  [        [        UR                   R                  5      5       Vs/ s H  n[        U5      PM     sn5      S S S2   5      $ s  snf )Nr   r$   z
{}({}).t()ztorch.transposez{}.permute({}), )	r2   	is_Matrixshaper8   r,   joinranger-   str)r   r0   is      r    _print_TransposeTorchPrinter._print_Transpose{   s    88$((.."3txx~~a7H"H&&'8$++dhh:OPP $**DHH%		5TXX^^1D+EF+Ea3q6+EFG"M Fs   C;c                     U R                  UR                  5      < SSR                  S UR                  R                   5       5      < S3$ )Nz	.permute(r=   c              3   8   #    U  H  n[        U5      v   M     g 7fN)rC   ).0rD   s     r    	<genexpr>2TorchPrinter._print_PermuteDims.<locals>.<genexpr>   s     B&Ac!ff&A   r&   )r,   r0   rA   permutation
array_formr9   s     r    _print_PermuteDimsTorchPrinter._print_PermuteDims   s:    KK		"IIBd&6&6&A&ABB
 	
r"   c                    UR                   nUR                  n[        U5      S:  d?  [        U5      S:X  a  [        US   [        5      (       d  UR                  US   5      S:  a  U R                  U5      n0 nU HL  n[        U[        5      (       a  Uu  pxUR                  US5      U-   XW'   M5  UR                  US5      S-   XV'   MN     UR                  5        H7  u  ph[        U5       H#  n	SR                  X@R                  U5      5      nM%     M9     U$ [        U5      S:X  a  US   n
[        U
[        5      (       ax  [        U
5      S:X  ai  U
u  px[        U[        5      (       d  [        S5      eU R                  U5      n[        U5       H#  n	SR                  X@R                  U5      5      nM%     U$ SR                  U R                  U5      U R                  U
5      5      $ U R                  U5      $ )Nr$   r   z1torch.autograd.grad({}, {}, create_graph=True)[0]   z!Only integer orders are supportedztorch.autograd.grad({}, {})[0])	variablesr0   r-   
isinstancetuplecountr,   r(   itemsrB   r8   r   NotImplementedError)r   r0   rT   expr_argresult
var_groupsvarbase_varorder_variables              r    _print_DerivativeTorchPrinter._print_Derivative   s   NN	99 y>A	Na
9Q<(G(GIOO\efg\hLilmLm[[*FJ !c5))&)OH+5>>(A+F+NJ(&0nnS!&<q&@JO ! )..0
uAPWWX^`k`klo`pqF & 1 M y>Q |H(E**s8}/A"*!%119LMp9q3qX.uAPWWX^`k`klt`uvF &3::4;;x;PRVR]R]^fRghh{{8$$r"   c                    SSK Jn  UR                  S   R                  u  p4[        UR                  5      S:X  aA  SR	                  U R                  S5      U R                  U5      U R                  U5      S5      $ SR	                  U R                  S5      U R                  U5      U R                  U5      U R                  U" UR                  SS  6 5      5      $ )Nr   )	Piecewiser$   z{}({}, {}, {})ztorch.where)sympyre   r+   r-   r8   r.   r,   )r   r0   re   econds        r    _print_PiecewiseTorchPrinter._print_Piecewise   s    #))A,##tyy>Q#**##M2D!A	   &&.KKKKNKK	499QR=12	4 	4r"   c                 :   UR                   u  p#UR                  [        R                  :X  a0  SR	                  U R                  S5      U R                  U5      5      $ SR	                  U R                  S5      U R                  U5      U R                  U5      5      $ )Nr7   r   
{}({}, {})r   )r+   expr
   Halfr8   r.   r,   )r   r0   baserm   s       r    
_print_PowTorchPrinter._print_Pow   s     II	88qvv??##L14;;t3DF F"",KKt{{3/1 	1r"   c                 |   UR                    Vs/ s H  n[        U[        5      (       d  M  UPM     nnUR                    Vs/ s H  o"U;  d  M
  UPM     nnU(       aD  U R                  [        R
                  " U5      [        S   5      < SU R                  SU5      < 3$ U R                  SU5      $ s  snf s  snf )Nr   *ztorch.matmul)r+   rU   r   parenthesizer   fromiterr   r/   )r   r0   r2   mat_argsr+   s        r    _print_MatMulTorchPrinter._print_MatMul   s    #'99L9C
3
0KC9L#yy@yx,?y@!!#,,t"4j6GH++NHE 
 ..~xHH M@s   B4B4	B9B9c                 V    U R                  SUR                  /UR                  -  5      $ )Nztorch.mm)r/   ro   rm   r9   s     r    _print_MatPowTorchPrinter._print_MatPow   s$    **:		{4887KLLr"   c                    SSR                  UR                  5        VVs/ s H9  nSSR                  U Vs/ s H  o0R                  U5      PM     sn5      -   S-   PM;     snn5      -   S-   n[        U5      /nUR	                  SU R
                   35        U R                  (       a  UR	                  S5        SR                  U R                  S5      SR                  U5      5      $ s  snf s  snnf )N[r=   ]zdtype=zrequires_grad=Truer7   ztorch.tensor)	rA   tolistr,   rC   appendr   r   r8   r.   )r   r0   rD   jdataparamss         r    _print_MatrixBaseTorchPrinter._print_MatrixBase   s    TYY\`\g\g\ij\iWXdii0KAQ0K&L Ls R\ijkknqqd)tzzl+,MM.//IIf
 	
 1Ljs   C.C)C.)C.c                 F    SU R                  UR                  S   5       S3$ )Nztorch.isnan(r   r&   r,   r+   r9   s     r    _print_isnanTorchPrinter._print_isnan   #    dkk$))A,78::r"   c                 F    SU R                  UR                  S   5       S3$ )Nztorch.isinf(r   r&   r   r9   s     r    _print_isinfTorchPrinter._print_isinf   r   r"   c                 r   [        S UR                   5       5      (       a=  SR                  U R                  S5      U R	                  UR                  S   5      5      $ SR                  U R                  S5      U R	                  UR                  S   5      U R	                  UR                  S   5      5      $ )Nc              3   8   #    U  H  oR                   v   M     g 7frI   )
is_Integer)rJ   dims     r    rK   /TorchPrinter._print_Identity.<locals>.<genexpr>   s     4#~~rM   r7   z	torch.eyer   rl   r$   )allr@   r8   r.   r,   r9   s     r    _print_IdentityTorchPrinter._print_Identity   s    4444??##K0DJJqM*   &&##K0DJJqM*DJJqM* r"   c                 v    SR                  U R                  S5      U R                  UR                  5      5      $ )Nr7   ztorch.zerosr8   r.   r,   r@   r9   s     r    _print_ZeroMatrixTorchPrinter._print_ZeroMatrix   s1    .KK

#
 	
r"   c                 v    SR                  U R                  S5      U R                  UR                  5      5      $ )Nr7   z
torch.onesr   r9   s     r    _print_OneMatrixTorchPrinter._print_OneMatrix  s1    -KK

#
 	
r"   c                 h    U R                  S5       SU R                  UR                  S   5       S3$ )Nz
torch.conjr%   r   r&   r.   r,   r+   r9   s     r    _print_conjugateTorchPrinter._print_conjugate  s4    %%l34Adkk$))A,6O5PPQRRr"   c                     g)N1j r9   s     r    _print_ImaginaryUnit!TorchPrinter._print_ImaginaryUnit  s    r"   c                     U R                  UR                  S   5      S/n[        UR                  5      S:  a!  U R                  UR                  S   5      US'   U R                  S5       SUS    SUS    S3$ )Nr   z0.5r$   ztorch.heavisider%   r=   r&   )r,   r+   r-   r.   )r   r0   r+   s      r    _print_HeavisideTorchPrinter._print_Heaviside  su    DIIaL)51tyy>Akk$))A,/DG%%&78947)2d1gYaPPr"   c                 h    U R                  S5       SU R                  UR                  S   5       S3$ )Nztorch.special.gammar%   r   r&   r   r9   s     r    _print_gammaTorchPrinter._print_gamma  s6    %%&;<=Qt{{499UV<?X>YYZ[[r"   c                     UR                   S   [        R                  :X  a3  U R                  S5       SU R	                  UR                   S   5       S3$ [        S5      e)Nr   ztorch.special.digammar%   r$   r&   z3PyTorch only supports digamma (0th order polygamma))r+   r
   Zeror.   r,   rY   r9   s     r    _print_polygammaTorchPrinter._print_polygamma  sZ    99Q<166!))*ABC1T[[QUQZQZ[\Q]E^D__`aa%&[\\r"   r   einsumaddtoneszeros)r   r   r   rI   )Z__name__
__module____qualname____firstlineno__printmethodrf   Abssignceilingfloorlogrm   r	   cosacossinasintanatanatan2coshacoshsinhasinhtanhatanhPowreimr2   erfloggammaEqNeStrictGreaterThanStrictLessThanLessThanGreaterThanAndOrNotMaxMinMatAddHadamardProductTraceDeterminantr'   dictr   _default_settingsr   r4   _print_Expr_print_Application_print_MatrixExpr_print_Relational
_print_Not
_print_And	_print_Or_print_HadamardProduct_print_Trace_print_Determinantr:   rE   rP   rb   ri   rp   rw   rz   r   r   r   r   r   r   r   r   r   r   r   _module_einsum_add
_transpose_ones_zeros__static_attributes____classcell__)r   s   @r    r   r      s{   K6		;6

L6
 	|6 	]6 			;6 			;6 	l6 			;6 	

L6 			;6 	

L6 			;6 	

L6  	]!6$ 	

L%6& 	]'6( 	

L)6* 	]+6, 	

L-6. 	]/60 			;164 	,566 	,768 			=96> 			;?6@ 	A6D 	*E6F 	*G6H 	I6J 	jK6L 	
M6N 	:O6R 			&S6T 	$U6V 			&		;		; 	k{] 	;k6Gp !33	%= "K('' J JI,"L(:

%%N4 	1IM

;;

SQ\] GGDJEFr"   r   c                 >    [        XS.S9nUR                  " U 40 UD6$ )N)r   r   )r   )r   doprint)r0   r   r   r   printers        r    
torch_coder   '  s#    m$TUG??4,8,,r"   )Fr   )sympy.printing.pycoder   r   sympy.matrices.expressionsr   sympy.core.mulr   sympy.printing.precedencer   sympy.externalr   sympy.codegen.cfunctionsr	   rf   r
   r   r   r   r   r   r"   r    <module>r      sA    I 1  0 ( )   gU<!: Un-r"   