
    
Ngo                    8   d dl mZ d dlZd dlmZmZmZ d dlZd dl	m
Z
 d dlmZmZmZ d dlmZmZmZ d dlmZmZ d dlmZmZmZmZ d d	lmZmZmZmZm Z m!Z!m"Z" d
 Z# G d de$          Z% G d de$          Z& G d de'          Z( G d d          Z) G d d          Z*d-dZ+ e+            Z, G d d          Z- G d d          Z.d.dZ/d/d"Z0 G d# d$          Z1 G d% d&ej2                  Z3 G d' d(e3          Z4 G d) d*e3          Z5 G d+ d,e5          Z6dS )0    )annotationsN)AnyClassVarIterable)TensorProto)get_all_schemas_with_history
get_schemaonnx_opset_version)	make_nodemake_tensor_type_protonp_dtype_to_tensor_dtype)to_arrayunpack_int4)AttributeProto
GraphProto	NodeProto	TypeProto)bfloat16float8e4m3fnfloat8e4m3fnuz
float8e5m2float8e5m2fnuzint4uint4c                    d| v rC|                      dd          \  }}	 t          |          }n# t          $ r | d fcY S w xY w||fS | d fS )N_   )maxsplit)rsplitint
ValueError)nameprefixversvs       Q/var/www/html/ai-engine/env/lib/python3.11/site-packages/onnx/reference/op_run.py_split_class_namer'      su    
d{{{{3{33	D		AA 	 	 	:	qy:s   0 A Ac                      e Zd ZdZdS )RuntimeTypeErrorz/Raised when a type of a variable is unexpected.N__name__
__module____qualname____doc__     r&   r)   r)   &   s        9999r0   r)   c                      e Zd ZdZdS )RuntimeContextErrorzfRaised when the context is missing but an context dependent implementation is defined for an operator.Nr*   r/   r0   r&   r2   r2   *   s        ppppr0   r2   c                      e Zd ZdZdS )RuntimeImplementationErrorz8Raised when no implementation was found for an operator.Nr*   r/   r0   r&   r4   r4   .   s        BBBBr0   r4   c                      e Zd ZdZdS )DefaultNonezjDefault value for parameters when the parameter is not set but the operator has a default behavior for it.Nr*   r/   r0   r&   r6   r6   2   s        ttttr0   r6   c                  "    e Zd ZdZddZd	dZdS )
RefAttrNamez}Implements a link between a parameter of a function and an attribute in node.

    Args:
        name: name of the input
    r"   strc                    || _         d S N)r"   )selfr"   s     r&   __init__zRefAttrName.__init__=   s    			r0   returnc                0    | j         j         d| j        dS )N())	__class__r+   r"   r<   s    r&   __repr__zRefAttrName.__repr__@   s     .)::DI::::r0   N)r"   r9   r>   r9   )r+   r,   r-   r.   r=   rD   r/   r0   r&   r8   r8   6   sF            ; ; ; ; ; ;r0   r8   r>   dict[str, type]c            
     ~   i } t                      D ]}|j        | v rt|j        | |j                 j        k    r3t          d|j        d|j        d| |j                 j        d          |j        | |j                 j        k    r
|| |j        <   n
|| |j        <   || |j        dz   t          |j                  z   <   | S )Nz7This function assumes every operator has a unique name z even accross multiple domains z and .r   )r   r"   domainNotImplementedErrorsince_versionr9   )resschemas     r&   _build_schemasrN   D   s    C.00 D D;#}FK 0 777)hfk h h5;]h hKNv{K[Kbh h h   #c&+&6&DDD#)FK %C=CFK#F$8 9 99::Jr0   c                      e Zd ZddZd	dZdS )
OnnxType
type_protor   c                ~    t          |t                    s t          dt          |           d          || _        d S )Nztype_proto z must be of type TypeProto.)
isinstancer   	TypeErrortyperQ   )r<   rQ   s     r&   r=   zOnnxType.__init__[   sB    *i00 	YW$z*:*:WWWXXX$r0   r>   r9   c                    d| j         dS )Nz	OnnxType(rA   )rQ   rC   s    r&   rD   zOnnxType.__repr__`   s    /4?////r0   N)rQ   r   rE   )r+   r,   r-   r=   rD   r/   r0   r&   rP   rP   Z   s<        % % % %
0 0 0 0 0 0r0   rP   c                  2    e Zd ZdZdd	Zedd            ZdS )SparseTensorzcSimple representation of a sparse tensor.
    It is based on numpy but does not require scipy.
    values
np.ndarrayindicesshape
tuple[int]r>   Nonec                0    || _         || _        || _        d S r;   )rY   r[   r\   )r<   rY   r[   r\   s       r&   r=   zSparseTensor.__init__i   s     


r0   r   c                    | j         j        S r;   )rY   dtyperC   s    r&   ra   zSparseTensor.dtypep   s    {  r0   N)rY   rZ   r[   rZ   r\   r]   r>   r^   )r>   r   )r+   r,   r-   r.   r=   propertyra   r/   r0   r&   rX   rX   d   sR             ! ! ! X! ! !r0   rX   attr   c                    t          d | j        D                       }t          t          | j                  t          | j                  |          S )zHosts a sparse tensor.c              3     K   | ]}|V  d S r;   r/   ).0ds     r&   	<genexpr>z#to_sparse_tensor.<locals>.<genexpr>w   s"      &&!&&&&&&r0   )tupledimsrX   r   rY   r[   )rc   r\   s     r&   to_sparse_tensorrk   u   sF    &&SX&&&&&E,,hs{.C.CUKKKr0   tensorr   rZ   c                Z   | j         }|t          j        k    rw| j        }t	          | j                  }t          j        |t                    	                                }t          |          D ]
\  }}|||<   |                    |          S |t          j        t          j        t          j        t          j        fv rt          j        t           t          j        t"          t          j        t$          t          j        t&          i}|                     d          r| j        }n| j        }t	          | j                  }t          j        |||                   	                                }t          |          D ]
\  }}|||<   |                    |          S |t          j        t          j        fv r|                     d          r| j        }n| j        }t	          | j                  }t          j        t0          t          j        t2          i}||         }|t          j        k    }	t          j        t5          |          |          	                                }t          |          D ]
\  }}|||<   t7          |||	          }
|
                    |          S t;          |           S )zSimilar to :func:`to_array` but deals with non-numpy types bfloat16,
    float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz, uint4, int4.
    )ra   raw_data)rj   signed)	data_typer   BFLOAT16
int32_datari   rj   npemptyr   ravel	enumeratereshapeFLOAT8E4M3FNFLOAT8E4M3FNUZ
FLOAT8E5M2FLOAT8E5M2FNUZr   r   r   r   HasFieldrn   UINT4INT4r   r   lenr   astyper   )rl   	elem_typedatar\   yirg   mra   ro   unpacked_datas              r&   to_array_extendedr   {   s^     IK((( fk""HU(+++1133dOO 	 	DAqAaDDyy ""	   $l&"J&	
 ??:&& 	%?DD$Dfk""HU!I,///5577dOO 	 	DAqAaDDyy[&(8999??:&& 	%?DD$Dfk""t[%6>)k..HSYYe,,,2244dOO 	 	DAqAaDD#AE&AAA##E***Fr0   c                      e Zd ZdZddZdS )	Graphgr   r   r>   r^   c                    || _         d S r;   r   )r<   r   s     r&   r=   zGraph.__init__   s    r0   N)r   r   r>   r^   )r+   r,   r-   	__slots__r=   r/   r0   r&   r   r      s-        I     r0   r   c                  t   e Zd ZU dZdZej        d ej        d ej        d ej	        d ej
        d ej        d ej        d	 ej        d
 ej        d ej        d ej        d ej        d ej        d ej        d iZded<   	 dFdGdZd Z	 dFdHd!Zed"             ZdId$ZedJd(            ZedKd*            ZedKd+            ZedLd-            Z edLd.            Z!dMd0Z"dLd1Z#e$j%        d2             Z&dNd5Z'ddd6d7Z(e)d8             Z*e)	 	 dOdPd=            Z+e)	 	 	 dQdRdA            Z,e)dd>dBdSdE            Z-dS )TOpRuna0  Ancestor to all operators in this subfolder.

    Args:
        onnx_node: `onnx` node
        run_params: additional parameters such as `verbose`, `opsets`
            (it can be more than one if the operator has a subgraph),
            `log` for a logging function
        schema: operator schema
     c                4    t          j        | j                  S r;   )rs   float32frc   s    r&   <lambda>zOpRun.<lambda>   s    "*SU*;*; r0   c                $    d | j         D             S )Nc                6    g | ]}t          j        |          S r/   )rs   r   )rf   r   s     r&   
<listcomp>z"OpRun.<lambda>.<locals>.<listcomp>   s     +N+N+NaBJqMM+N+N+Nr0   )floatsr   s    r&   r   zOpRun.<lambda>   s    +N+N3:+N+N+N r0   c                *    t          | j                  S r;   )r   r   r   s    r&   r   zOpRun.<lambda>   s    %,, r0   c                $    d | j         D             S )Nc                ,    g | ]}t          |          S r/   )r   )rf   r   s     r&   r   z"OpRun.<lambda>.<locals>.<listcomp>   s    +I+I+IE!HH+I+I+Ir0   )graphsr   s    r&   r   zOpRun.<lambda>   s    +I+Icj+I+I+I r0   c                *    t          | j                  S r;   )r    r   r   s    r&   r   zOpRun.<lambda>   s    CE

 r0   c                $    d | j         D             S )Nc                ,    g | ]}t          |          S r/   )r    rf   r   s     r&   r   z"OpRun.<lambda>.<locals>.<listcomp>   s    )C)C)CQ#a&&)C)C)Cr0   )intsr   s    r&   r   zOpRun.<lambda>   s    )C)C#()C)C)C r0   c                *    t          | j                  S r;   )rk   sparse_tensorr   s    r&   r   zOpRun.<lambda>   s    2B3CT2U2U r0   c                $    d | j         D             S )Nc                ,    g | ]}t          |          S r/   )rk   rf   ts     r&   r   z"OpRun.<lambda>.<locals>.<listcomp>   s.     4
 4
 4
$%Q4
 4
 4
r0   )sparse_tensorsr   s    r&   r   zOpRun.<lambda>   s#     4
 4
),);4
 4
 4
 r0   c                6    | j                             d          S )Nutf-8)sdecoder   s    r&   r   zOpRun.<lambda>   s    35<<+@+@ r0   c                $    d | j         D             S )Nc                8    g | ]}|                     d           S )r   )r   )rf   r   s     r&   r   z"OpRun.<lambda>.<locals>.<listcomp>   s$    ,T,T,T1QXXg->->,T,T,Tr0   )stringsr   s    r&   r   zOpRun.<lambda>   s    ,T,T,T,T,T r0   c                *    t          | j                  S r;   )r   r   r   s    r&   r   zOpRun.<lambda>   s    +<SU+C+C r0   c                $    d | j         D             S )Nc                ,    g | ]}t          |          S r/   )r   r   s     r&   r   z"OpRun.<lambda>.<locals>.<listcomp>   s!    ,W,W,Wa->q-A-A,W,W,Wr0   )tensorsr   s    r&   r   zOpRun.<lambda>   s    ,W,W3;,W,W,W r0   c                *    t          | j                  S r;   )rP   tpr   s    r&   r   zOpRun.<lambda>   s    x/?/? r0   c                $    d | j         D             S )Nc                ,    g | ]}t          |          S r/   )rP   r   s     r&   r   z"OpRun.<lambda>.<locals>.<listcomp>   s    0V0V0V!0V0V0Vr0   )type_protosr   s    r&   r   zOpRun.<lambda>   s    0V0Vco0V0V0V r0   zClassVar[dict[Any, Any]]_attribute_conversion_functionsN	onnx_noder   
run_paramsdict[str, Any]rM   r   c           	     \   t          |t                    s t          dt          |           d          dD ])}||vr#t	          d|dt          |           d          *d|vrt          d          || _        || _        |t          | j
        d	          r| j
        j        | _        ne| j
        j        t          v rt          | j
        j                 | _        n5|j        t          v rt          |j                 | _        nd | _        n|| _        d
| _        |                                  d S )Nz$run_params must be a dictionary not rH   )opsetsnew_ops
Attribute z must be in run_params, only z was found.logz#run_params must contains key 'log'.	op_schemaF)rS   dictrT   rU   RuntimeErrorsortedKeyErrorr   r   hasattrrB   r   _schemar+   _schemasop_typehas_subgraph_load_attributes)r<   r   r   rM   rc   s        r&   r=   zOpRun.__init__   sX    *d++ 	XV4
CSCSVVVWWW( 	 	C*$$"7 7 7j))7 7 7   %
 
""@AAA"$>t~{33 $#~7(H44'(?@"h..'	(9:#!DL!r0   c                .     | j         d         |g|R   d S )Nr   )r   )r<   patternargss      r&   _logz
OpRun._log   s'    w.......r0   rc   r   ref_attAttributeProto | Noner>   c                b   |j         t          j        k    r| j                            dd          }d| j        v r-t          | j        d                                                   }nd}| j                            dd          }|J d|              ||j        | j        d         t          d| j                            dd          d	z
            |dn t          |                                          |
          S |j         t          j
        v rt          j
        |j                  |          S |=t          d|j        d|j         d| j        j        d| j        j        d| d          t          d|j        d|j         d| j        j        d| j        j        d| d| d          )z0Converts an attribute value into a python value.r   Nexisting_functionsevaluator_clsz0evaluator_cls must be specified to evaluate att=r   r   verbose   )r   r   r   	functionszUnable to convert attribute z type z from node type z	, domain 
rH   z$Unable to convert default value for )rU   r   GRAPHr   getlistrY   r   maxr   r   AttributeErrorr"   r   r   rI   )r<   rc   r   r   r   r   s         r&   _extract_attribute_valuezOpRun._extract_attribute_value   s     8~+++o)))T::G#t66 1E!F!M!M!O!OPP		 	 O//FFM))G#GG *)) =x0At229a@@1DEE 'T'..:J:J5K5K#    8u<<<8B3GGG? <sx < < < <"&."8< <./< <58< < <  
 C7< C C C C"n4C Cn+C C14C C8?C C C
 
 	
r0   c                6    |                     d | pi |          S )N
attributes)runcontextvaluer   s      r&   _evaluate_subgraphzOpRun._evaluate_subgraph  s    yyw}"yDDDr0   r^   c                   d| _         g }| j        j        D ]}|j        }|j        rt          |j                  }d| _         n|                     |          }t          | ||           |                    |           |j	        t          j        k    r9d| _        | xj         |j         z  c_         t          | d|j         |dfd           | j        r| j        j        dvr| j        j                                        D ]\  }}t#          | |          st%          |dd          r t'          d|d	| j        j        d
          t#          |d          ry|j        j	        dk    s%|j        j	        dk    r|j        j        j        dk    rd}n|                     |j        |          }t          | ||           |                    |           t/          |          | _        dS )zChecks and loads attributes.FT_run_Nc                :    t                               | ||          S r;   )r   r   r   s      r&   r   z(OpRun._load_attributes.<locals>.<lambda>1  s    %BZBZ
C C r0   >   Constantrequiredr   z3 is expected based on ONNX specifications for node rH   default_valuer      )has_linked_attributer   	attributer"   ref_attr_namer8   r   setattrappendrU   r   r   r   r   r   r   itemsr   getattrr   r   r   rp   setattributes_names_)r<   added_attributesrc   r"   r   kr%   s          r&   r   zOpRun._load_attributes  s;   $)!>+ 	 	C8D  ;#C$566,0))55c::D$&&&##D)))x>///$(!))U-GG))&CH&&*/D      < 	3DN2,FF/5577 3 31tQ'' 3q*d33 *D D D(,(>D D D   q/22 
3?/144O0A55 ! 1 ;q @ @ %)EE$($A$A!/ST$U$UEa///(//222!$%5!6!6r0   graphr   	list[str]c                2   t          | t                    s t          dt          |           d          t	                      }t	                      }| j        D ]}|                    |j                   | j        D ]}|                    |j                   | j	        D ]}|                    |j                   | j
        D ]D}|j        D ]}|                    |           |j	        D ]}||vr|                    |           Et          |          S )zReturns all varibles not registered as inputs and not produced by
        an node inside the graph. This inputs are part of the context
        existing in the graph calling this one.
        zUnexpected type rH   )rS   r   rT   rU   r   initializeraddr"   sparse_initializerinputnodeoutputr   )	r   localknowninitsparse_initinpr  or   s	            r&   implicit_inputszOpRun.implicit_inputsK  s4    %,, 	A?tE{{???@@@% 	! 	!DIIdi     3 	( 	(KIIk&''''; 	  	 CIIchJ 	! 	!D[  		!Z ! !E>>IIaLLL! E{{r0   Iterable[str]c                    | j         j        S )zReturns node attribute `input`.)r   r  rC   s    r&   r  zOpRun.inputc  s     ~##r0   c                    | j         j        S )z Returns node attribute `output`.)r   r  rC   s    r&   r  zOpRun.outputh       ~$$r0   r9   c                    | j         j        S )z!Returns node attribute `op_type`.)r   r   rC   s    r&   r   zOpRun.op_typem  s     ~%%r0   c                    | j         j        S )z Returns node attribute `domain`.)r   rI   rC   s    r&   rI   zOpRun.domainr  r  r0   boolc                    dS )zTells the runtime if this node needs the context
        (all the results produced so far) as it may silently access
        one of them (operator Scan, If, Loop).
        The default answer is `False`.
        Fr/   rC   s    r&   need_contextzOpRun.need_contextw  s	     ur0   c                p   | j         j        dz   d| j        j         g}t	          | j                                                  D ]H\  }}|dv r
d|d         cxk    rdk    r+n  |d         dk    r|                    d	| d
| d           I|                    d           d                    |          S )Nr@   z    op_type=>   descr   ar   zr   z    =,rA   r   )	rB   r+   r   r   r   __dict__r   r   join)r<   attsr   r%   s       r&   __str__zOpRun.__str__  s    '#-/Vdn>T/V/VW4=..0011 	- 	-DAq)))ad!!!!c!!!!!aesllO1OOqOOO,,,Cyyr0   c                <    t          d| j        j        d          )a  Should be overwritten.

        Args:
            *args: operator inputs
            **kwargs: optional inputs and overriden attributes, an
                attribute may be overridden if it belongs to a function,
                in this case, the same instance of OpRun can be called
                with different values of the same attribute.

        Returns:
            outputs
        z/Method '_run' must be overwritten for operator rH   )rJ   rB   r+   )r<   r   kwargss      r&   _runz
OpRun._run  s)     "Zdn>UZZZ
 
 	
r0   rL   tuple[Any, ...]c                   t          |t                    s-t          d| j        j        dt          |           d          |st          d| j        j        d          t          d |D                       r,d |D             }t          d| j        j        d|d	          t          d
 |D                       }t          d |D                       r,d |D             }t          d| j        j        d|d	          |S )z-Checks the output are from the expected type.zMethod '_run' of class z does not return a tuple but 'z'.z does not return any result.c              3  @   K   | ]}t          |t                    V  d S r;   )rS   ri   r   s     r&   rh   z/OpRun._check_and_fix_outputs.<locals>.<genexpr>  s,      11z!U##111111r0   c                ,    g | ]}t          |          S r/   rU   r   s     r&   r   z0OpRun._check_and_fix_outputs.<locals>.<listcomp>      +++!d1gg+++r0   z6One of the results returned by method '_run' of class zg is a tuple, this is no ONNX corresponding type (Map, List, Tensor, SparseTensor). All returned types: rH   c              3  j   K   | ].}t          j        |          rt          j        |          n|V  /d S r;   )rs   isscalararray)rf   xs     r&   rh   z/OpRun._check_and_fix_outputs.<locals>.<genexpr>  sL       
 
78BKNN1RXa[[[
 
 
 
 
 
r0   c              3     K   | ]<}t          |t          j        t          t          f          pt          |d            V  =dS )todenseN)rS   rs   ndarrayr   r   r   r   s     r&   rh   z/OpRun._check_and_fix_outputs.<locals>.<genexpr>  s[       
 
 A
D$788QGAy<Q<QR
 
 
 
 
 
r0   c                ,    g | ]}t          |          S r/   r&  r   s     r&   r   z0OpRun._check_and_fix_outputs.<locals>.<listcomp>  r'  r0   zr has an unexpected type, this is no ONNX correponding type (Map, List, Tensor, SparseTensor). All returned types: )rS   ri   rT   rB   r+   rU   r!   any)r<   rL   dtypess      r&   _check_and_fix_outputszOpRun._check_and_fix_outputs  s   #u%% 	p$.*Appcghkclclppp    	a$.*Aaaa   11S11111 	++s+++F3I` 3 3'-3 3 3  
  
 
<?
 
 
 
 
  
 

 
 
 
 
 		 ,+s+++F3I` 3 3'-3 3 3  
 
r0   )linked_attributesr   c                  |                                  r#| t          dt          |            d          n"| t          dt          |            d          | j        r"| t	          dt          |            d          | j        s2|0t	          dt          |            dt          |           d          i }| j        r| t          d	t          |            d          | j        D ]f}t          | |          }t          |t                    r?|j        |vr&t	          d
|d|dt          |            d          ||j                 ||<   g|                     d| j        j        t          |                     i }| j        D ]J}||v rt!          | |          s t#          d|d| j        j        d          t          | |          ||<   K| j        r.| j        r"|s t          dt          |            d          ||d<   |||d<   	 |r | j        |i ||}n | j        |i |}nd# t(          t          f$ rP}	t)          dd |D              dt+          |           dt+          |           d| j        j        d	          |	d}	~	ww xY w|                     d| j        j        |t          |          nd           |                     |          S )a  Calls method ``_run``, catches exceptions,
        displays a longer error message.

        Args:
            *args: inputs
            linked_attributes: used if this has an attriute linked to
                the attribute of the function it belongs to
            context: if this node is part of the subgraph, `context` is
                a dictionary with the values this node may use

        Returns:
            tuple of results
        NzThis node if type z needs context to be filled.z+ does not need any contextbut one is given.z
This node zK has linked attributes but None are given in parameter 'linked_attributes'.zM has no linked attribute but some are given in parameter 'linked_attributes' rH   zBOne attribute is linked but no linked value is provided, in class z,Unable to find a value for linked attribute z in z	 in node z-- begin %s.run(%d inputs)r   z is missing in operator z6A subgraph has linked attribute but none was given to r   r   zIssues with types c                ,    g | ]}t          |          S r/   r&  )rf   r   s     r&   r   zOpRun.run.<locals>.<listcomp>  s    %<%<%<!d1gg%<%<%<r0   z and attributes z and linked attributes=z (operator ).z-- done %s.run -> %d outputsr   )r  r   rU   r   r!   r   r   r   r   rS   r8   r"   r   rB   r+   r   r   	NameErrorr   r!  rT   r   r2  )
r<   r3  r   r   overridden_attributesrc   r%   r   rL   es
             r&   r   z	OpRun.run  s     	"QdQQQ     \T$ZZ\\\   $ 	):)BtT$ZZttt   ( 	->-JAT$ZZ A A'*+<'='=A A A   !#$ 	K ($. $T

. . .   - K KD#&&a-- Kv%666(53 5 5Vg 5 5'+Dzz5 5 5   2C161J)#.		.0GTSSS) 	- 	-C+++4%% \\\@W\\\   "$,,F3KK 	5( 1B "ZTRVZZZZZ   $5F<  'F9
	$ 1diI)>I&IIdi000>* 	 	 	;%<%<t%<%<%< ; ;&>>; ;:@AV:W:W; ;!^4; ; ;  		 			*N#CHHHQ	
 	
 	

 **3///s   H4 4JAJJc                    | j         }d|vr|t                      fS |                    dd          \  }}	 t          |          }n%# t          $ r | j         t                      fcY S w xY w||fS )Nr   r   )r+   r
   r   r    r!   )clsr"   r$   i_verss       r&   
infer_namezOpRun.infer_name  s    |d??+----[[a((
d	6YYFF 	6 	6 	6<!3!5!55555	6V|s   A A('A(n_inputs
int | None	n_outputsr   c                8   |                                  \  }}| j        }d}||t          |||          }|j        }||t          |||          }|j        }d t          |          D             }d t          |          D             }	t          |||	fi |}
|
S )a  Creates an ONNX node for this class based on the given information.

        Args:
            n_inputs: number of inputs (default is defined by the
                operator schema)
            n_outputs: number of outputs (default is defined by the
                operator schema)
            verbose: verbosity
            **kwargs: node attributes

        Returns:
            NodeProto

        Method :meth:`eval <onnx.reference.op_run.OpRun.eval>` creates an onnx node
        returned by method :meth:`make_node <onnx.reference.op_run.OpRun.make_node>`.

        .. exec_code::

            import numpy as np
            from onnx.reference.ops._op_list import Celu

            onnx_node = Celu.make_node(alpha=0.5)
            print(onnx_node)
        Nc                    g | ]}d | S )r+  r/   r   s     r&   r   z#OpRun.make_node.<locals>.<listcomp>G  s    555GGG555r0   c                    g | ]}d | S )r   r/   r   s     r&   r   z#OpRun.make_node.<locals>.<listcomp>H  s    777WWW777r0   )r=  	op_domainr	   	min_input
min_outputranger   )r;  r>  r@  r   r   opsetrI   rM   names_in	names_outr  s              r&   r   zOpRun.make_node  s    > ))~#GUF;;'H~#GUF;;)I55U8__55577eI&6&6777	(I@@@@r0   r   r   r    c                t    dfd} | j         ||fi |}|dd	t                      id
} | ||          }|S )a  Instantiates this class based on the given information.

        Args:
            n_inputs: number of inputs (default is defined by the
                operator schema)
            n_outputs: number of outputs (default is defined by the
                operator schema)
            verbose: verbosity
            **kwargs: node attributes

        Returns:
            NodeProto
        r   r9   r   r   r>   r^   c                V    dk    r!t          | t          |          z             d S d S )Nr   )printri   )r   r   r   s     r&   log_functionz"OpRun.create.<locals>.log_functionb  s2    {{gd+,,,,, {r0   Nr   )r   r   r   r   )r   r9   r   r   r>   r^   )r   r
   )	r;  r>  r@  r   r   rN  r  r   cls	      `     r&   createzOpRun.createL  sz    ,	- 	- 	- 	- 	- 	- s}Xy;;F;;-//0	
 

 Sz""	r0   r@  r   r   	list[Any]c                    | j         t          |          f||d|} |j        | }t          |          dk    r|d         S |S )a  Evaluates this operator.

        Args:
            *args: inputs
            n_outputs: number of outputs (default is defined by the
                operator schema)
            verbose: verbosity
            **kwargs: node attributes

        Returns:
            NodeProto
        rQ  r   r   )rP  r   r   )r;  r@  r   r   r   instrL   s          r&   evalz
OpRun.evalp  sT    ( sz#d))Ty'TTVTTdhos88q==q6M
r0   r;   )r   r   r   r   rM   r   )rc   r   r   r   r>   r   )r>   r^   )r   r   r>   r   )r>   r  rE   )r>   r  )rL   r"  r>   r"  NN)r>  r?  r@  r?  r   r   r>   r   )NNr   )
r>  r?  r@  r?  r   r    r   r   r>   r   )
r   rR  r@  r?  r   r    r   r   r>   r   ).r+   r,   r-   r.   rD  r   FLOATFLOATSr   GRAPHSINTINTSSPARSE_TENSORSPARSE_TENSORSSTRINGSTRINGSTENSORTENSORS
TYPE_PROTOTYPE_PROTOSr   __annotations__r=   r   r   staticmethodr   r   r
  rb   r  r  r   rI   r  r  abcabstractmethodr!  r2  r   classmethodr=  r   rP  rU  r/   r0   r&   r   r      sE          I 	;;NN66II22CC$&U&U% (
 (
 	@@ T TCC W W!#?#?"$V$V!A#    ( OS         :/ / / EI!
 !
 !
 !
 !
F E E \E+7 +7 +7 +7Z    \. $ $ $ X$ % % % X% & & & X& % % % X%       	
 
 
"   @ ,0 S0 S0 S0 S0 S0j 	 	 [	   $ $- - - - [-^   $ $	! ! ! ! [!F  !%	     [  r0   r   c                  $    e Zd ZdZ	 ddd	Zd
 ZdS )OpRunExpandz.Class any operator to avoid must inherit from.Nr   r   r   r   implr   c                B    t          dt          |            d          Nz5The reference implementation must not use this node (r6  r   rU   )r<   r   r   rk  s       r&   r=   zOpRunExpand.__init__  s*     RDJJRRR
 
 	
r0   c                B    t          dt          |            d          rm  rn  r<   inputsr   s      r&   r!  zOpRunExpand._run  s(    RDJJRRR
 
 	
r0   r;   )r   r   r   r   rk  r   r+   r,   r-   r.   r=   r!  r/   r0   r&   rj  rj    sI        88 MQ
 
 
 
 

 
 
 
 
r0   rj  c                  ,    e Zd ZdZ	 	 ddd
Zd Zd ZdS )
OpFunctionzRuns a custom function.Nr   r   r   dict[str, Any] | Nonerk  r   r   c                     | t          d|j        d|j        d          t                               ||           | _         fdt           j        d|          D              _        d S )Nz"impl cannot be None for node type  from domain rH   c                2    i | ]}|t          |          S r/   )r   )rf   r"   r<   s     r&   
<dictcomp>z'OpFunction.__init__.<locals>.<dictcomp>  s5     
 
 
 '$%%
 
 
r0   attributes_)r   r   rI   r   r=   impl_r   rz  )r<   r   r   rk  r   s   `    r&   r=   zOpFunction.__init__  s     <5Y5F 5 5(/5 5 5   	tY
333

 
 
 

M:FF
 
 
r0   c                .     | j         | j        g|R i |S r;   )	_run_implr{  rp  s      r&   r!  zOpFunction._run  s&    t~dj<6<<<V<<<r0   c                   t          |j                  t          |          k    rEt          dt          |           dt          |j                   d| j        d| j        d	          t          t          |j        |                    }| j        	                                }|
                    |           |                    d ||          }t          |j                  t          |          k    rEt          dt          |           dt          |j                   d| j        d| j        d	          t          |          S )	Nz.Mismatch lengths between the number of inputs z# and the expected number of inputs z
 for node rw  rH   r   z/Mismatch lengths between the number of outputs z$ and the expected number of outputs )r   input_namesr   rq  r   rI   r   ziprz  copyupdater   output_namesri   )r<   rk  rq  r   feedsr   resultss          r&   r}  zOpFunction._run_impl  s~   t  CKK//JV J J585E5EJ J LJ J9=J J J  
 S)62233%**,,
&!!!((4:(>>t !!S\\11J#g,, J J69$:K6L6LJ J LJ J9=J J J  
 W~~r0   rV  )r   r   r   ru  rk  r   r   ru  )r+   r,   r-   r.   r=   r!  r}  r/   r0   r&   rt  rt    sY        !! ,0
 
 
 
 
*= = =    r0   rt  c                  $    e Zd ZdZ	 ddd	Zd
 ZdS )OpFunctionContextDependantzThe function can be instantiated but only at execution time.
    An instance of OpFunction is created everytime to node is executed.
    This is needed when the schema of an operator defines a context dependant function.
    Nr   r   r   ru  parentr   c                    t                               | ||| i            || _        |j        |j                 }t          |j        ||j                  | _        d S )N)rk  r   )rt  r=   r  r   rI   r	   r   schema_)r<   r   r   r  versions        r&   r=   z#OpFunctionContextDependant.__init__  sV     	D)ZdrRRR-	 01!)"3Wi>NOOr0   c                   g }|D ]%}	 t          |j                  }n# t          $ r}|j        t          k    rt          j        }n|j        t          k    rt          j        }n|j        t          k    rt          j	        }nv|j        t          k    rt          j        }nY|j        t          k    rt          j        }n<|j        t          k    rt          j        }n|j        t           k    rt          j        }n|Y d }~nd }~ww xY w|                    t'          ||j                             '| j                            | j        |          } || j        | j                  } | j        |j        g|R i |S r;   )r   ra   r   r   r   rx   r   ry   r   rz   r   r{   r   BLOFAT16r   r}   r   r~   r   r   r\   r  
_load_implr   r   r}  r{  )	r<   rq  r   typesr   ttyper9  rO  rT  s	            r&   r!  zOpFunctionContextDependant._run  sn     	A 	AA099   7l**'4EEW..'6EEW
**'2EEW..'6EEW(('0EEW%%'-EEW__',EEG!" LL/qw??@@@@[##DNE::r$.$/22t~dj<6<<<V<<<s   
C?CC::C?r;   )r   r   r   ru  r  r   rr  r/   r0   r&   r  r    sP          		P 	P 	P 	P 	P= = = = =r0   r  )r>   rF   )rc   r   r>   rX   )rl   r   r>   rZ   )7
__future__r   rf  typingr   r   r   numpyrs   onnxr   	onnx.defsr   r	   r
   onnx.helperr   r   r   onnx.numpy_helperr   r   onnx.onnx_pbr   r   r   r   #onnx.reference.custom_element_typesr   r   r   r   r   r   r   r'   r   r)   r2   rJ   r4   r6   r8   rN   r   rP   rX   rk   r   r   ABCr   rj  rt  r  r/   r0   r&   <module>r     s   # " " " " " 



 * * * * * * * * * *           R R R R R R R R R R S S S S S S S S S S 3 3 3 3 3 3 3 3 I I I I I I I I I I I I                   : : : : :| : : :q q q q q, q q qC C C C C!4 C C Cu u u u u u u u; ; ; ; ; ; ; ;   & >0 0 0 0 0 0 0 0! ! ! ! ! ! ! !"L L L L2 2 2 2j       Q Q Q Q QCG Q Q Qh
 
 
 
 
% 
 
 
 , , , , , , , ,^,= ,= ,= ,= ,= ,= ,= ,= ,= ,=r0   