
    wic                       d dl mZ d dlZd dlmZmZ d dlZd dl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          Z G d d          Zd&dZ e            Z G d d          Z G d d          Zd'dZd(dZ G d d          Z G d dej                  Z G d  d!e          Z G d" d#e          Z G d$ d%e          ZdS ))    )annotationsN)TYPE_CHECKINGAny)Sequencec                      e Zd ZdZdS )RuntimeTypeErrorz/Raised when a type of a variable is unexpected.N__name__
__module____qualname____doc__     e/root/.openclaw/workspace/chatterbox_venv_py311/lib/python3.11/site-packages/onnx/reference/op_run.pyr   r      s        9999r   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   r   r   r   r      s        ppppr   r   c                      e Zd ZdZdS )RuntimeImplementationErrorz8Raised when no implementation was found for an operator.Nr	   r   r   r   r   r      s        BBBBr   r   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   r   r   r   r      s        ttttr   r   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
    namestrc                    || _         d S N)r   )selfr   s     r   __init__zRefAttrName.__init__(   s    			r   returnc                0    | j         j         d| j        dS )N())	__class__r
   r   r   s    r   __repr__zRefAttrName.__repr__+   s     .)::DI::::r   N)r   r   r   r   )r
   r   r   r   r   r%   r   r   r   r   r   !   sF            ; ; ; ; ; ;r   r   r   dict[str, onnx.defs.OpSchema]c            
        i } t           j        j         j                                        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 across multiple domains z and ._)onnxdefsget_all_schemas_with_historyr   domainNotImplementedErrorsince_versionr   )resschemas     r   _build_schemasr3   /   s   )+C).%BBDD D D;#}FK 0 777)gfk g g4:Mg gJMfkJZJag g g   #c&+&6&DDD#)FK %C=CFK#F$8 9 99::Jr   c                      e Zd ZddZd	dZdS )
OnnxType
type_protoonnx.TypeProtoc                    t          |t          j                  s t          dt	          |           d          || _        d S )Nztype_proto z  must be of type onnx.TypeProto.)
isinstancer+   	TypeProto	TypeErrortyper6   )r   r6   s     r   r   zOnnxType.__init__F   sK    *dn55 	Pd:..PPP   %r   r   r   c                    d| j         dS )Nz	OnnxType(r"   )r6   r$   s    r   r%   zOnnxType.__repr__M   s    /4?////r   N)r6   r7   r&   )r
   r   r   r   r%   r   r   r   r5   r5   E   s<        % % % %0 0 0 0 0 0r   r5   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   )r@   rB   rC   )r   r@   rB   rC   s       r   r   zSparseTensor.__init__V   s     


r   r   c                    | j         j        S r   )r@   dtyper$   s    r   rH   zSparseTensor.dtype]   s    {  r   N)r@   rA   rB   rA   rC   rD   r   rE   )r   r   )r
   r   r   r   r   propertyrH   r   r   r   r?   r?   Q   sR             ! ! ! X! ! !r   r?   attonnx.AttributeProtoc                    t          d | j        D                       }t          t          j                            | j                  t          j                            | 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>d   s"      &&!&&&&&&r   )tupledimsr?   r+   numpy_helperto_arrayr@   rB   )rJ   rC   s     r   to_sparse_tensorrU   b   sa    &&SX&&&&&E""3:..""3;//  r   	attr_type!onnx.AttributeProto.AttributeTypec                
   t           j        j        d t           j        j        d t           j        j        d t           j        j        d t           j        j        d t           j        j        d t           j        j        d t           j        j	        d t           j        j
        d	 t           j        j        d
 t           j        j        d t           j        j        d t           j        j        d t           j        j        d i|          S )Nc                4    t          j        | j                  S r   )npfloat32frJ   s    r   <lambda>z0_attribute_conversion_function.<locals>.<lambda>n   s    rz#%/@/@ r   c                $    d | j         D             S )Nc                6    g | ]}t          j        |          S r   )rZ   r[   )rN   r\   s     r   
<listcomp>zD_attribute_conversion_function.<locals>.<lambda>.<locals>.<listcomp>o   s     0S0S0S1A0S0S0Sr   )floatsr]   s    r   r^   z0_attribute_conversion_function.<locals>.<lambda>o   s    0S0S
0S0S0S r   c                *    t          | j                  S r   )Graphgr]   s    r   r^   z0_attribute_conversion_function.<locals>.<lambda>p   s    uSU|| r   c                $    d | j         D             S )Nc                ,    g | ]}t          |          S r   )rd   )rN   re   s     r   ra   zD_attribute_conversion_function.<locals>.<lambda>.<locals>.<listcomp>q   s    0N0N0Naq0N0N0Nr   )graphsr]   s    r   r^   z0_attribute_conversion_function.<locals>.<lambda>q   s    0N0N3:0N0N0N r   c                *    t          | j                  S r   )intir]   s    r   r^   z0_attribute_conversion_function.<locals>.<lambda>r   s    SZZ r   c                $    d | j         D             S )Nc                ,    g | ]}t          |          S r   )rj   rN   rk   s     r   ra   zD_attribute_conversion_function.<locals>.<lambda>.<locals>.<listcomp>s   s    .H.H.H!s1vv.H.H.Hr   )intsr]   s    r   r^   z0_attribute_conversion_function.<locals>.<lambda>s   s    .H.Hsx.H.H.H r   c                *    t          | j                  S r   )rU   sparse_tensorr]   s    r   r^   z0_attribute_conversion_function.<locals>.<lambda>t   s    7G8
 8
 r   c                $    d | j         D             S )Nc                ,    g | ]}t          |          S r   )rU   rN   ts     r   ra   zD_attribute_conversion_function.<locals>.<lambda>.<locals>.<listcomp>w   s.     9
 9
 9
$%Q9
 9
 9
r   )sparse_tensorsr]   s    r   r^   z0_attribute_conversion_function.<locals>.<lambda>w   s#     9
 9
),);9
 9
 9
 r   c                6    | j                             d          S )Nutf-8)sdecoder]   s    r   r^   z0_attribute_conversion_function.<locals>.<lambda>z   s    W0E0E r   c                $    d | j         D             S )Nc                8    g | ]}|                     d           S )rx   )rz   )rN   ry   s     r   ra   zD_attribute_conversion_function.<locals>.<lambda>.<locals>.<listcomp>{   s1     2
 2
 2
"#AHHW2
 2
 2
r   )stringsr]   s    r   r^   z0_attribute_conversion_function.<locals>.<lambda>{   s"     2
 2
'*{2
 2
 2
 r   c                J    t           j                            | j                  S r   )r+   rS   rT   ru   r]   s    r   r^   z0_attribute_conversion_function.<locals>.<lambda>~   s    0A0J0J350Q0Q r   c                $    d | j         D             S )Nc                L    g | ]!}t           j                            |          "S r   )r+   rS   rT   rt   s     r   ra   zD_attribute_conversion_function.<locals>.<lambda>.<locals>.<listcomp>   s6     2
 2
 2
./D&&q))2
 2
 2
r   )tensorsr]   s    r   r^   z0_attribute_conversion_function.<locals>.<lambda>   s"     2
 2
36;2
 2
 2
 r   c                *    t          | j                  S r   )r5   tpr]   s    r   r^   z0_attribute_conversion_function.<locals>.<lambda>   s    HSV4D4D r   c                $    d | j         D             S )Nc                ,    g | ]}t          |          S r   )r5   rt   s     r   ra   zD_attribute_conversion_function.<locals>.<lambda>.<locals>.<listcomp>   s+     6
 6
 6
HQKK6
 6
 6
r   )type_protosr]   s    r   r^   z0_attribute_conversion_function.<locals>.<lambda>   s"     6
 6
!$6
 6
 6
 r   )r+   AttributeProtoFLOATFLOATSGRAPHGRAPHSINTINTSSPARSE_TENSORSPARSE_TENSORSSTRINGSTRINGSTENSORTENSORS
TYPE_PROTOTYPE_PROTOS)rV   s    r   _attribute_conversion_functionr   l   s   !#@#@"$S$S!#;#;"$N$N!7!7 "H"H) ,
 ,
 	* -
 -
 	"$E$E# &
 &
 	"$Q$Q# &
 &
 	&(D(D' *
 *
-2 3 r   c                      e Zd ZdZddZdS )	rd   re   re   onnx.GraphProtor   rE   c                    || _         d S r   r   )r   re   s     r   r   zGraph.__init__   s    r   N)re   r   r   rE   )r
   r   r   	__slots__r   r   r   r   rd   rd      s-        I     r   rd   c                     e Zd ZdZdZ	 d6d7d
Zd Z	 d6d8dZed             Z	d9dZ
ed:d            Zed;d            Zed;d            Zed<d            Zed<d            Zd=d Zd<d!Zej        d"             Zd>d%Zddd&d'Zed(             Ze	 	 d?d@d-            Ze	 	 	 dAdBd1            Zedd.d2dCd5            ZdS )D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
     N	onnx_nodeonnx.NodeProto
run_paramsdict[str, Any]r2   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 r)   )opsetsnew_ops
Attribute z must be in run_params, only z was found.logz#run_params must contains key 'log'.	op_schemaF)r9   dictr;   r<   RuntimeErrorsortedKeyErrorr   r   hasattrr#   r   _schemar
   _schemasop_typehas_subgraph_load_attributes)r   r   r   r2   rJ   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!r   c                .     | j         d         |g|R   d S )Nr   )r   )r   patternargss      r   _logz
OpRun._log   s'    w.......r   rJ   rK   ref_attonnx.AttributeProto | Noner   c                J   |j         t          j        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 t          |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 
r)   z$Unable to convert default value for )r<   r+   r   r   r   getlistr@   re   maxr   AttributeErrorr   r   r   r.   )r   rJ   r   r   r   r   conversion_functions          r   _extract_attribute_valuezOpRun._extract_attribute_value   s$    8t*000o)))T::G#t66 1E!F!M!M!O!OPP		 	 O//FFM ,,H3HH -,, !=x0At229a@@1DEE 'T'..:J:J5K5K#    =SXFF*&&s+++? <sx < < < <"&."8< <./< <58< < <   C7< C C C C"n4C Cn+C C14C C8?C C C
 
 	
r   c                6    |                     d | pi |          S )N
attributes)runcontextvaluer   s      r   _evaluate_subgraphzOpRun._evaluate_subgraph   s    yyw}"yDDDr   rE   c                   d| _         g }| j        j        D ]}|j        }|j        rt          |j                  }d| _         n|                     |          }t          | ||           |                    |           |j	        t          j        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          | ||           |                    |           t1          |          | _        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>   s!    %*%=%=
& & r   >   Constantrequiredr   z3 is expected based on ONNX specifications for node r)   default_valuer      )has_linked_attributer   	attributer   ref_attr_namer   r   setattrappendr<   r+   r   r   r   r   r   r   itemsr   getattrr   r   ru   	data_typesetattributes_names_)r   added_attributesrJ   r   r   kvs          r   r   zOpRun._load_attributes   s?   $)!>+ 	 	C8D  ;#C$566,0))55c::D$&&&##D)))x4.444$(!))U-GG))&CH&&#     < 	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r   graphr   	list[str]c                <   t          | t          j                  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 variables 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 r)   )r9   r+   
GraphProtor;   r<   r   initializeraddr   sparse_initializerinputnodeoutputr   )	r   localknowninitsparse_initinpr   ork   s	            r   implicit_inputszOpRun.implicit_inputs  s6    %11 	A?tE{{???@@@% 	! 	!DIIdi     3 	( 	(KIIk&''''; 	  	 CIIchJ 	! 	!D[  		!Z ! !E>>IIaLLL! E{{r   Sequence[str]c                    | j         j        S )zReturns node attribute `input`.)r   r   r$   s    r   r   zOpRun.input/  s     ~##r   c                    | j         j        S )z Returns node attribute `output`.)r   r   r$   s    r   r   zOpRun.output4       ~$$r   r   c                    | j         j        S )z!Returns node attribute `op_type`.)r   r   r$   s    r   r   zOpRun.op_type9  s     ~%%r   c                    | j         j        S )z Returns node attribute `domain`.)r   r.   r$   s    r   r.   zOpRun.domain>  r   r   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   r$   s    r   need_contextzOpRun.need_contextC  s	     ur   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    =,r"   r   )	r#   r
   r   r   r   __dict__r   r   join)r   attsr   r   s       r   __str__zOpRun.__str__K  s    '#-/Vdn>T/V/VW4=..0011 	- 	-DAq)))ad!!!!c!!!!!aesllO1OOqOOO,,,Cyyr   c                <    t          d| j        j        d          )a  Should be overwritten.

        Args:
            *args: operator inputs
            **kwargs: optional inputs and overridden 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 r)   )r/   r#   r
   r   r   kwargss      r   _runz
OpRun._runU  s)     "Zdn>UZZZ
 
 	
r   r1   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   )r9   rQ   rt   s     r   rP   z/OpRun._check_and_fix_outputs.<locals>.<genexpr>q  s,      11z!U##111111r   c                ,    g | ]}t          |          S r   r<   rt   s     r   ra   z0OpRun._check_and_fix_outputs.<locals>.<listcomp>r      +++!d1gg+++r   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: r)   c              3  j   K   | ].}t          j        |          rt          j        |          n|V  /d S r   )rZ   isscalararray)rN   xs     r   rP   z/OpRun._check_and_fix_outputs.<locals>.<genexpr>x  sL       
 
78BKNN1RXa[[[
 
 
 
 
 
r   c              3     K   | ]<}t          |t          j        t          t          f          pt          |d            V  =dS )todenseN)r9   rZ   ndarrayr   r   r   rt   s     r   rP   z/OpRun._check_and_fix_outputs.<locals>.<genexpr>{  s[       
 
 A
D$788QGAy<Q<QR
 
 
 
 
 
r   c                ,    g | ]}t          |          S r   r  rt   s     r   ra   z0OpRun._check_and_fix_outputs.<locals>.<listcomp>  r  r   zs has an unexpected type, this is no ONNX corresponding type (Map, List, Tensor, SparseTensor). All returned types: )r9   rQ   r;   r#   r
   r<   
ValueErrorany)r   r1   dtypess      r   _check_and_fix_outputszOpRun._check_and_fix_outputsg  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  
 
r   )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' r)   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  )rN   r*   s     r   ra   zOpRun.run.<locals>.<listcomp>  s    %<%<%<!d1gg%<%<%<r   z and attributes z and linked attributes=z (operator ).z-- done %s.run -> %d outputsr   )r   r   r<   r   r  r   r   r   r   r9   r   r   r   r#   r
   lenr   	NameErrorr   r
  r;   r   r  )
r   r  r   r   overridden_attributesrJ   r   r	  r1   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          j                                        fS |                    dd          \  }}	 t          |          }n5# t          $ r( | j         t          j                                        fcY S w xY w||fS )Nr*      )r
   r+   r,   onnx_opset_versionrsplitrj   r  )clsr   versi_verss       r   
infer_namezOpRun.infer_name  s    |d??557777[[a((
d	@YYFF 	@ 	@ 	@<!=!=!?!?????	@V|s   A /BBn_inputs
int | None	n_outputsr	  c                   |                                  \  }}| j        }d}|*|!t          j                            |||          }|j        }|*|!t          j                            |||          }|j        }d t          |          D             }d t          |          D             }	t          j        j	        |||	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   rn   s     r   ra   z#OpRun.make_node.<locals>.<listcomp>  s    555GGG555r   c                    g | ]}d | S )yr   rn   s     r   ra   z#OpRun.make_node.<locals>.<listcomp>  s    777WWW777r   )
r,  	op_domainr+   r,   
get_schema	min_input
min_outputrangehelper	make_node)
r)  r-  r/  r	  r   opsetr.   r2   names_in	names_outs
             r   r:  zOpRun.make_node  s    > ))~--gufEE'H~--gufEE)I55U8__55577eI&6&6777	{$Wh	LLVLLLr   r   r   rj   c                    dfd} | j         ||fi |}|dd	t          j                                        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   r   r   r   r   rE   c                V    dk    r!t          | t          |          z             d S d S )Nr&  )printrQ   )r   r   r   s     r   log_functionz"OpRun.create.<locals>.log_function-  s2    {{gd+,,,,, {r   Nr   )r   r   r   r   )r   r   r   r   r   rE   )r:  r+   r,   r'  )r)  r-  r/  r   r	  rA  r   r   s      `    r   createzOpRun.create  s}    ,	- 	- 	- 	- 	- 	- s}Xy;;F;;497799:	
 

 s4$$$r   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
        rC  r&  r   )rB  r!  r   )r)  r/  r   r   r	  instr1   s          r   evalz
OpRun.eval:  sT    ( sz#d))Ty'TTVTTdhos88q==q6M
r   r   )r   r   r   r   r2   r   )rJ   rK   r   r   r   r   )r   rE   )r   r   r   r   )r   r   r&   )r   r   )r1   r  r   r  NN)r-  r.  r/  r.  r	  r   r   r   )NNr   )
r-  r.  r/  r.  r   rj   r	  r   r   r   )
r   rD  r/  r.  r   rj   r	  r   r   r   )r
   r   r   r   r4  r   r   r   staticmethodr   r   r   rI   r   r   r   r.   r   r  abcabstractmethodr
  r  r   classmethodr,  r:  rB  rG  r   r   r   r   r      s{         I TX         :/ / / OS%
 %
 %
 %
 %
N E E \E-7 -7 -7 -7^    \. $ $ $ X$ % % % X% & & & X& % % % X%       	
 
 
"   @ ,0 S0 S0 S0 S0 S0j 	 	 [	   $ $,M ,M ,M ,M [,M\   $ $	 %  %  %  % [ %D  !%	     [  r   r   c                      e Zd ZdZd Zd ZdS )OpRunExpandz.Class any operator to avoid must inherit from.c                B    t          dt          |            d          Nz5The reference implementation must not use this node (r   r   r<   r  s      r   r   zOpRunExpand.__init__X  (    RDJJRRR
 
 	
r   c                B    t          dt          |            d          rP  rQ  r   inputsr	  s      r   r
  zOpRunExpand._run]  rR  r   Nr
   r   r   r   r   r
  r   r   r   rN  rN  U  s8        88
 
 


 
 
 
 
r   rN  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] | Noneimplr   r   r   rE   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 r)   c                2    i | ]}|t          |          S r   )r   )rN   r   r   s     r   
<dictcomp>z'OpFunction.__init__.<locals>.<dictcomp>v  s5     
 
 
 '$%%
 
 
r   attributes_)r   r   r.   r   r   impl_r   r_  )r   r   r   rZ  r   s   `    r   r   zOpFunction.__init__f  s     <5Y5F 5 5(/5 5 5   	tY
333

 
 
 

M:FF
 
 
r   c                .     | j         | j        g|R i |S r   )	_run_implr`  rT  s      r   r
  zOpFunction._run{  s&    t~dj<6<<<V<<<r   c                   t          |j                  t          |          k    rEt          dt          |           dt          |j                   d| j        d| j        d	          t          t          |j        |d                    }| 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 r\  r)   F)strictr   z/Mismatch lengths between the number of outputs z$ and the expected number of outputs )r!  input_namesr   r   r.   r   zipr_  copyupdater   output_namesrQ   )r   rZ  rU  r	  feedsr   resultss          r   rb  zOpFunction._run_impl~  s   t  CKK//JV J J589I5J5JJ J LJ J9=J J J  
 S)6%@@@AA%**,,
&!!!((4:(>>t !!S\\11J#g,, J J69$:K6L6LJ J LJ J9=J J J  
 W~~r   rH  )
r   r   r   rY  rZ  r   r   rY  r   rE   )r
   r   r   r   r   r
  rb  r   r   r   rX  rX  c  sY        !! ,0
 
 
 
 
*= = =    r   rX  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 dependent function.
    Nr   r   r   rY  parentr   c                    t                               | ||| i            || _        |j        |j                 }t
          j                            |j        ||j                  | _	        d S )N)rZ  r   )
rX  r   rn  r   r.   r+   r,   r5  r   schema_)r   r   r   rn  versions        r   r   z#OpFunctionContextDependant.__init__  sc     	D)ZdrRRR-	 01y++w	(8
 
r   c                `   g }|D ]^}t           j                            |j                  }|                    t           j                            ||j                             _| j                            | j	        |          } || j	        | j
                  } | j        |j        g|R i |S r   )r+   r9  np_dtype_to_tensor_dtyperH   r   make_tensor_type_protorC   rn  
_load_implr   r   rb  r`  )r   rU  r	  typesru   rH   clrF  s           r   r
  zOpFunctionContextDependant._run  s      	M 	MAK88AAELL;;E17KKLLLL[##DNE::r$.$/22t~dj<6<<<V<<<r   r   )r   r   r   rY  rn  r   rV  r   r   r   rm  rm    sK          	
 
 
 
 
	= 	= 	= 	= 	=r   rm  )r   r'   )rJ   rK   r   r?   )rV   rW   )
__future__r   rJ  typingr   r   numpyrZ   r+   collections.abcr   r   r   r   r/   r   r   r   r3   r   r5   r?   rU   r   rd   ABCr   rN  rX  rm  r   r   r   <module>r}     s   # " " " " " 



 % % % % % % % %      )((((((: : : : :| : : :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! ! ! ! ! ! ! !"      :       B B B B BCG B B BJ
 
 
 
 
% 
 
 
, , , , , , , ,^= = = = = = = = = =r   