
    
Ng                         d dl mZmZ d dlZd dlmZ d dlmZ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 )    )AnyDictN)	NodeProto)OpRunRuntimeTypeErrorc                       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     R/var/www/html/ai-engine/env/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>U   s.      .L.Ls477||.L.L.L.L.L.Lr   z (binary operator r   )r   r   r   RuntimeErrorr   r2   r   shaper   r   
ValueErrorr   r    r!   )r"   r#   yr$   r%   s        r   r&   zOpRunBinary.runA   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   r4   r4   ;   s-         
0 0 0 0 0r   r4   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Dr   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: r6   z or z (operator z
) type(x)=z	 type(y)=)r4   r&   r2   r   r   r   r   r!   )r"   r#   r<   r$   s       r   r&   zOpRunBinaryNum.runh   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   r@   r@   b   s-         
	0 	0 	0 	0 	0r   r@   c                   <    e Zd ZdZdededeeef         fdZd Z	dS )OpRunBinaryNumpyzI*numpy_fct* is a binary numpy function which
    takes two matrices.
    	numpy_fct	onnx_node
run_paramsc                 L    t                               | ||           || _        d S r   )r@   __init__rD   )r"   rD   rE   rF   s       r   rH   zOpRunBinaryNumpy.__init__y   s'     	i<<<"r   c                 Z    |                      ||          f}|                     |          S r   )rD   r!   )r"   abr$   s       r   r   zOpRunBinaryNumpy._run   s,    ~~a##%**3///r   N)
r   r(   r)   r*   r   r   r   r   rH   r   r+   r   r   rC   rC   t   sa         ##)2#@DS#X# # # #0 0 0 0 0r   rC   c                   J    e Zd ZdZdedeeef         fdZd Z	d Z
d Zd Zd	S )
OpRunReduceNumpyzFImplements the reduce logic.
    It must have a parameter *axes*.
    rE   rF   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   rH   hasattrr0   rO   npndarrayr    r:   tupler1   )r"   rE   rF   s      r   rH   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 S r   r+   r"   rO   s     r   is_axes_emptyzOpRunReduceNumpy.is_axes_empty   s    t|r   c                    t          |t                    rt          |          dk    rd S |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d S t          |	                                
                                          S )Nr   zaxes must be an array, not .)r0   rS   r    intrQ   rR   r   r   r:   raveltolistrU   s     r   handle_axeszOpRunReduceNumpy.handle_axes   s    dE"" 	4yyA~~tK<4dS%L)) 	K$
++ 	IG$t**GGGHHHtz??at99
??4TZZ\\((**+++r   c                 :    t          j        |||          j        S )N)axiskeepdims)rQ   sumr:   )r"   datarO   r_   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.)r2   )rb   rQ   fullr2   )r"   ra   	const_valrO   r_   rb   s         r   reduce_constantz OpRunReduceNumpy.reduce_constant   s5    ((tX>>itzBBBDDr   N)r   r(   r)   r*   r   r   r   r   rH   rV   r\   rb   rf   r+   r   r   rM   rM      s         -) -c3h - - - -  , , ,"@ @ @E E E E Er   rM   )typingr   r   numpyrQ   onnx.onnx_pbr   onnx.reference.op_runr   r   r	   r.   r4   r>   r@   rC   rM   r+   r   r   <module>rk      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	 	 	 	 	K 	 	 	0 0 0 0 0[ 0 0 0$0 0 0 0 0~ 0 0 0 ,E ,E ,E ,E ,Eu ,E ,E ,E ,E ,Er   