
    SiK                        S SK Jr  S SKJrJr  S SKrS SKJrJ	r	  \(       a  S SK
Jr   " S S\5      r " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)    )annotations)TYPE_CHECKINGAnyN)OpRunRuntimeTypeError)	NodeProtoc                      \ rS rSrSrS rSrg)
OpRunUnary   zeAncestor to all unary operators in this subfolder.

Checks that input and output types are the same.
c                   U R                  SU R                  R                  5         U R                  U5      nU R                  SU R                  R                  [        U5      5        U R                  U5      $ ! [         aD  n[	        SSR                  S U4 5       5       SU R                  R                  < S35      UeSnAff = f)	zlCalls method ``_run``, catches exceptions, displays a longer error message.

Supports only unary operators.
z-- begin %s.run(1 input)Issues with types , c              3  J   #    U  H  n[        [        U5      5      v   M     g 7fNstrtype.0_s     U/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/onnx/reference/ops/_op.py	<genexpr>!OpRunUnary.run.<locals>.<genexpr>    s     .ISs47||S   !#z (unary operator ).N-- done %s.run -> %d outputs)_log	__class____name___run	TypeErrorjoinlen_check_and_fix_outputs)selfxreses       r   runOpRunUnary.run   s    
 			,dnn.E.EF	))A,C 			0$..2I2I3s8T**3//  	$TYY.IaS.I%I$J K##'>>#:#:"=RA 	s   A: :
C?CC Nr   
__module____qualname____firstlineno____doc__r)   __static_attributes__r+       r   r
   r
          
0r2   r
   c                      \ rS rSrSrS rSrg)OpRunUnaryNum'   zsAncestor to all unary and numerical operators in this subfolder.

Checks that input and output types are the same.
c           	     h   [         R                  X5      n[        U5      S:X  d  US   c  U$ [        US   [        5      (       d^  US   R
                  UR
                  :w  aA  [        SUR
                   SUS   R
                   SU R                  R                  < S35      eU R                  U5      $ )z|Calls method ``OpRunUnary.run``.

Catches exceptions, displays a longer error message.
Checks that the result is not empty.
r   zOutput type mismatch: input 'z' != output 'z' (operator r   )
r
   r)   r#   
isinstancelistdtyper   r   r   r$   )r%   r&   r'   s      r   r)   OpRunUnaryNum.run-   s     nnT%s8q=CFNJ#a&$''CFLLAGG,C"/yc!fll^ T!^^447r;  **3//r2   r+   Nr,   r+   r2   r   r5   r5   '   r3   r2   r5   c                      \ rS rSrSrS rSrg)OpRunBinary>   zfAncestor to all binary operators in this subfolder.

Checks that input and output types are the same.
c                   U R                  SU R                  R                  5        Ub  Uc0  [        S[	        U5       S[	        U5       S[	        U 5       S35      eUR
                  UR
                  :w  aX  [        SUR
                   SUR
                   SU R                  R                  < S	UR                   S
UR                   S35      e U R                  X5      nU R                  SU R                  R                  [        U5      5        U R                  U5      $ ! [        [        4 aD  n[        SS
R                  S X4 5       5       SU R                  R                  < S35      UeSnAff = f)zmCalls method ``_run``, catches exceptions, displays a longer error message.

Supports only binary operators.
z-- begin %s.run(2 inputs)Nzx and y have different dtype:  != z ()zInput type mismatch: z (operator 'z
', shapes r   r   r   c              3  J   #    U  H  n[        [        U5      5      v   M     g 7fr   r   r   s     r   r   "OpRunBinary.run.<locals>.<genexpr>X   s     .LVs47||Vr   z (binary operator r   )r   r   r   RuntimeErrorr   r:   r   shaper    r!   
ValueErrorr"   r#   r$   )r%   r&   yr'   r(   s        r   r)   OpRunBinary.runD   sd   
 			-t~~/F/FG9	0a	d1gYbdTUV  77agg"'yQWWI >"nn558 9''"QWWIR1 
	))A/C 			0$..2I2I3s8T**3// :& 	$TYY.LaV.L%L$M N$$(NN$;$;#>bB 	s   D" "E62?E11E6r+   Nr,   r+   r2   r   r=   r=   >   s    
0r2   r=   c                      \ rS rSrSrSrg)OpRunBinaryComparison_   zEAncestor to all binary operators in this subfolder comparing tensors.r+   N)r   r-   r.   r/   r0   r1   r+   r2   r   rJ   rJ   _   s    Or2   rJ   c                      \ rS rSrSrS rSrg)OpRunBinaryNumc   zfAncestor to all binary operators in this subfolder.

Checks that input oud output types are the same.
c                T   [         R                  XU5      nUS   R                  UR                  :w  ae  [        SUR                   SUS   R                   SUR                   SU R                  R
                  < S[        U5       S[        U5       35      eU R                  U5      $ )zVCalls method ``OpRunBinary.run``, catches exceptions, displays a longer error message.r   zOutput type mismatch: r@   z or z (operator z
) type(x)=z	 type(y)=)r=   r)   r:   r   r   r   r   r$   )r%   r&   rG   r'   s       r   r)   OpRunBinaryNum.runi   s    oodq)q6<<177""(	c!fll^4y Q!^^447 8 G9Id1gY8 
 **3//r2   r+   Nr,   r+   r2   r   rM   rM   c   s    
	0r2   rM   c                  4    \ rS rSrSr      SS jrS rSrg)OpRunBinaryNumpyu   zA*numpy_fct* is a binary numpy function which
takes two matrices.
c                <    [         R                  XU5        Xl        g r   )rM   __init__	numpy_fct)r%   rV   	onnx_node
run_paramss       r   rU   OpRunBinaryNumpy.__init__z   s     	<"r2   c                H    U R                  X5      4nU R                  U5      $ r   )rV   r$   )r%   abr'   s       r   r    OpRunBinaryNumpy._run   s$    ~~a#%**3//r2   )rV   N)rV   r   rW   r   rX   dict[str, Any])r   r-   r.   r/   r0   rU   r    r1   r+   r2   r   rR   rR   u   s)    ##)2#@N#0r2   rR   c                  >    \ rS rSrSrS
S jrS rSS jrS rS r	Sr
g	)OpRunReduceNumpy   z>Implements the reduce logic.
It must have a parameter *axes*.
c                   [         R                  " XU5        [        U S5      (       a  [        U R                  [
        R                  5      (       ac  [        U R                  R                  5      S:X  d  U R                  R                  S   S:X  a  S U l        g [        U R                  5      U l        g U R                  / S4;   a  S U l        g [        U R                  [        5      (       a  [        U R                  5      U l        g g g )Naxesr   r+   )r   rU   hasattrr8   rc   npndarrayr#   rE   tupler9   )r%   rW   rX   s      r   rU   OpRunReduceNumpy.__init__   s    t
34  $))RZZ00tyy'1,		0Ba0G $DI %dii 0DIr2h& 	DIIt,,!$)),	 - !r2   c                6    US L =(       d    UR                   S:H  $ )N)r   )rE   )r%   rc   s     r   is_axes_emptyOpRunReduceNumpy.is_axes_empty   s    t|1tzzT11r2   c                   [        U[        5      (       a  [        U5      S:X  a  U(       d  g U$ Uc	  U(       a  gg [        U[        [        45      (       a  U$ [        U[        R
                  5      (       d  [        S[        U5       S35      e[        UR                  5      S:X  a  [        U5      $ SUR                  ;   a	  U(       a  gg [        UR                  5       R                  5       5      $ )Nr   r+   zaxes must be an array, not .)r8   rg   r#   intre   rf   r!   r   rE   raveltolist)r%   rc   noop_with_empty_axess      r   handle_axesOpRunReduceNumpy.handle_axes   s    dE""4yA~&:K<#dS%L))K$

++9$t*QGHHtzz?at9

?#TZZ\((*++r2   c                @    [         R                  " XUS9R                  $ )N)axiskeepdims)re   sumrE   )r%   datarc   rv   s       r   output_shapeOpRunReduceNumpy.output_shape   s    vvd9???r2   c                f    U R                  XU5      n[        R                  " XRUR                  S94$ )z<Special case reduction where the output value is a constant.)r:   )ry   re   fullr:   )r%   rx   	const_valrc   rv   ry   s         r   reduce_constant OpRunReduceNumpy.reduce_constant   s,    ((X>tzzBDDr2   )rc   N)rW   r   rX   r^   )F)r   r-   r.   r/   r0   rU   rj   rr   ry   r~   r1   r+   r2   r   r`   r`      s"    -2,,@Er2   r`   )
__future__r   typingr   r   numpyre   onnx.reference.op_runr   r   onnx.onnx_pbr   r
   r5   r=   rJ   rM   rR   r`   r+   r2   r   <module>r      sr    # %  9&0 0.0J 0.0% 0BPK P0[ 0$0~ 0 1Eu 1Er2   