
    wiK                       d dl mZ d dlmZmZ d dlZd dlmZm	Z	 erd dl
mZ  G d de          Z G d d	e          Z G d
 de          Z G d de          Z G d de          Z G d de          Z G d de          ZdS )    )annotations)TYPE_CHECKINGAnyN)OpRunRuntimeTypeError)	NodeProtoc                      e Zd ZdZd ZdS )
OpRunUnaryzmAncestor to all unary operators in this subfolder.

    Checks that input and output types are the same.
    c                   |                      d| j        j                   	 |                     |          }nQ# t          $ rD}t	          dd                    d |fD                        d| j        j        d          |d}~ww xY w|                      d| j        j        t          |                     |                     |          S )	z|Calls method ``_run``, catches exceptions, displays a longer error message.

        Supports only unary operators.
        z-- begin %s.run(1 input)Issues with types , c              3  N   K   | ] }t          t          |                    V  !d S Nstrtype.0_s     f/root/.openclaw/workspace/chatterbox_venv_py311/lib/python3.11/site-packages/onnx/reference/ops/_op.py	<genexpr>z!OpRunUnary.run.<locals>.<genexpr>    s.      .I.Is477||.I.I.I.I.I.I    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   runzOpRunUnary.run   s    
 			,dn.EFFF	))A,,CC 	 	 	ATYY.I.IaS.I.I.I%I%I A A#'>#:A A A  	
 			0$.2I3s88TTT**3///s   8 
B?BBNr   
__module____qualname____doc__r'    r   r   r
   r
      -         
0 0 0 0 0r   r
   c                      e Zd ZdZd ZdS )OpRunUnaryNumz{Ancestor to all unary and numerical operators in this subfolder.

    Checks that input and output types are the same.
    c           	     d   t                               | |          }t          |          dk    s|d         |S t          |d         t                    sI|d         j        |j        k    r3t          d|j         d|d         j         d| j        j        d          | 	                    |          S )zCalls method ``OpRunUnary.run``.

        Catches exceptions, displays a longer error message.
        Checks that the result is not empty.
        r   NzOutput type mismatch: input 'z' != output 'z' (operator r   )
r
   r'   r!   
isinstancelistdtyper   r   r   r"   )r#   r$   r%   s      r   r'   zOpRunUnaryNum.run-   s     nnT1%%s88q==CFNJ#a&$'' 	CFLAG,C,C"; ; ;c!fl ; ;!^4; ; ;   **3///r   Nr(   r,   r   r   r/   r/   '   r-   r   r/   c                      e Zd ZdZd ZdS )OpRunBinaryznAncestor to all binary operators in this subfolder.

    Checks that input and output types are the same.
    c                   |                      d| j        j                   ||@t          dt	          |           dt	          |           dt	          |            d          |j        |j        k    r=t          d|j         d|j         d| j        j        d	|j         d
|j         d          	 |                     ||          }nY# t          t          f$ rE}t          dd
                    d ||fD                        d| j        j        d          |d}~ww xY w|                      d| j        j        t          |                     |                     |          S )z}Calls 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  N   K   | ] }t          t          |                    V  !d S r   r   r   s     r   r   z"OpRunBinary.run.<locals>.<genexpr>X   s.      .L.Ls477||.L.L.L.L.L.Lr   z (binary operator r   )r   r   r   RuntimeErrorr   r3   r   shaper   r   
ValueErrorr    r!   r"   )r#   r$   yr%   r&   s        r   r'   zOpRunBinary.runD   s   
 			-t~/FGGG9	VaVVd1ggVVdVVV   7ag"1 1 1QW 1 1"n51 1'1 1%&W1 1 1  
	))Aq//CC:& 	 	 	BTYY.L.LaV.L.L.L%L%L B B$(N$;B B B  	
 			0$.2I3s88TTT**3///s   3C
 
D A DD Nr(   r,   r   r   r5   r5   >   s-         
0 0 0 0 0r   r5   c                      e Zd ZdZdS )OpRunBinaryComparisonzEAncestor to all binary operators in this subfolder comparing tensors.N)r   r)   r*   r+   r,   r   r   r?   r?   _   s        OOOOr   r?   c                      e Zd ZdZd ZdS )OpRunBinaryNumznAncestor to all binary operators in this subfolder.

    Checks that input oud output types are the same.
    c                D   t                               | ||          }|d         j        |j        k    rZt          d|j         d|d         j         d|j         d| j        j        dt          |           dt          |                     |                     |          S )zVCalls method ``OpRunBinary.run``, catches exceptions, displays a longer error message.r   zOutput type mismatch: r7   z or z (operator z
) type(x)=z	 type(y)=)r5   r'   r3   r   r   r   r   r"   )r#   r$   r=   r%   s       r   r'   zOpRunBinaryNum.runi   s    oodAq))q6<17"""8 8 8c!fl 8 8 8 8!^48 8 GG8 8.21gg8 8  
 **3///r   Nr(   r,   r   r   rA   rA   c   s-         
	0 	0 	0 	0 	0r   rA   c                       e Zd ZdZddZd	 Zd
S )OpRunBinaryNumpyzI*numpy_fct* is a binary numpy function which
    takes two matrices.
    	numpy_fctr   	onnx_noder   
run_paramsdict[str, Any]c                L    t                               | ||           || _        d S r   )rA   __init__rE   )r#   rE   rF   rG   s       r   rJ   zOpRunBinaryNumpy.__init__z   s'     	i<<<"r   c                Z    |                      ||          f}|                     |          S r   )rE   r"   )r#   abr%   s       r   r   zOpRunBinaryNumpy._run   s,    ~~a##%**3///r   N)rE   r   rF   r   rG   rH   )r   r)   r*   r+   rJ   r   r,   r   r   rD   rD   u   sA         # # # #0 0 0 0 0r   rD   c                  4    e Zd ZdZddZd Zdd	Zd
 Zd ZdS )OpRunReduceNumpyzFImplements the reduce logic.
    It must have a parameter *axes*.
    rF   r   rG   rH   c                   t          j        | ||           t          | d          rt          | j        t
          j                  rWt          | j        j                  dk    s| j        j        d         dk    r	d | _        d S t          | j                  | _        d S | j        g dfv r	d | _        d S t          | j        t                    rt          | j                  | _        d S d S d S )Naxesr   r,   )r   rJ   hasattrr1   rQ   npndarrayr!   r;   tupler2   )r#   rF   rG   s      r   rJ   zOpRunReduceNumpy.__init__   s    tY
3334   		-$)RZ00 -ty''1,,	0Ba0G0G $DIII %di 0 0DIIIr2h&& 			DIt,, -!$),,					- 		-- -r   c                     |d u p
|j         dk    S )N)r   )r;   )r#   rQ   s     r   is_axes_emptyzOpRunReduceNumpy.is_axes_empty   s    t|1tzT11r   Fc                   t          |t                    rt          |          dk    r|sd S |S ||rdS d S t          |t          t          f          r|S t          |t          j                  s t          dt          |           d          t          |j                  dk    rt          |          S d|j        v r|rdS d S t          |	                                
                                          S )Nr   r,   zaxes must be an array, not .)r1   rU   r!   intrS   rT   r   r   r;   raveltolist)r#   rQ   noop_with_empty_axess      r   handle_axeszOpRunReduceNumpy.handle_axes   s    dE"" 	4yyA~~&:~tK<# r4dS%L)) 	K$
++ 	IG$t**GGGHHHtz??at99
??# r4TZZ\\((**+++r   c                :    t          j        |||          j        S )N)axiskeepdims)rS   sumr;   )r#   datarQ   ra   s       r   output_shapezOpRunReduceNumpy.output_shape   s    vd999??r   c                j    |                      |||          }t          j        |||j                  fS )z<Special case reduction where the output value is a constant.)r3   )rd   rS   fullr3   )r#   rc   	const_valrQ   ra   rd   s         r   reduce_constantz OpRunReduceNumpy.reduce_constant   s5    ((tX>>itzBBBDDr   N)rF   r   rG   rH   )F)	r   r)   r*   r+   rJ   rW   r^   rd   rh   r,   r   r   rO   rO      s{         - - - -2 2 2, , , ,,@ @ @E E E E Er   rO   )
__future__r   typingr   r   numpyrS   onnx.reference.op_runr   r   onnx.onnx_pbr   r
   r/   r5   r?   rA   rD   rO   r,   r   r   <module>rn      s   # " " " " " % % % % % % % %     9 9 9 9 9 9 9 9 '&&&&&&0 0 0 0 0 0 0 0.0 0 0 0 0J 0 0 0.0 0 0 0 0% 0 0 0BP P P P PK P P P0 0 0 0 0[ 0 0 0$0 0 0 0 0~ 0 0 0 1E 1E 1E 1E 1Eu 1E 1E 1E 1E 1Er   