
    h?g                       S SK Jr  S SKrS SKJrJrJr  S SKrS SK	J
r
  S SKJrJrJr  S SKJrJrJr  S SKJr  S SKJrJrJrJr  S S	KJrJrJrJrJr  S
 r  " S S\!5      r" " S S\!5      r# " S S\$5      r% " S S5      r& " S S5      r'S&S jr(\(" 5       r) " S S5      r* " S S5      r+S'S jr,S(S jr- " S S5      r. " S S\R^                  5      r0 " S  S!\05      r1 " S" S#\05      r2 " S$ S%\25      r3g))    )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)AttributeProto
GraphProto	NodeProto	TypeProto)bfloat16float8e4m3fnfloat8e4m3fnuz
float8e5m2float8e5m2fnuzc                    SU ;   a!  U R                  SSS9u  p [        U5      nX4$ U S 4$ ! [         a    U S 4s $ f = f)N_   )maxsplit)rsplitint
ValueError)nameprefixversvs       O/var/www/fran/franai/venv/lib/python3.13/site-packages/onnx/reference/op_run.py_split_class_namer$      sZ    
d{{{3{3	D	A y:  	:	s   , ==c                      \ rS rSrSrSrg)RuntimeTypeError$   z1
Raised when a type of a variable is unexpected.
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r(       r#   r&   r&   $       r0   r&   c                      \ rS rSrSrSrg)RuntimeContextError*   zh
Raised when the context is missing but an context dependent implementation is defined for an operator.
r(   Nr)   r(   r0   r#   r3   r3   *   r1   r0   r3   c                      \ rS rSrSrSrg)RuntimeImplementationError0   z:
Raised when no implementation was found for an operator.
r(   Nr)   r(   r0   r#   r6   r6   0   r1   r0   r6   c                      \ rS rSrSrSrg)DefaultNone6   zl
Default value for parameters when the parameter is not set
but the operator has a default behavior for it.
r(   Nr)   r(   r0   r#   r9   r9   6   s    r0   r9   c                  ,    \ rS rSrSrSS jrSS jrSrg)	RefAttrName=   zo
Implements a link between a parameter of a function
and an attribute in node.

:param name: name of the input
c                    Xl         g Nr   )selfr   s     r#   __init__RefAttrName.__init__E   s    	r0   c                P    U R                   R                   SU R                  < S3$ )usual())	__class__r*   r   rA   s    r#   __repr__RefAttrName.__repr__H   s$    ..))*!DII=::r0   r@   N)r   strreturnrL   )r*   r+   r,   r-   r.   rB   rJ   r/   r(   r0   r#   r<   r<   =   s    ;r0   r<   c            
        0 n [        5        H  nUR                  U ;   a  UR                  XR                     R                  :w  aB  [        SUR                  < SUR                  < SXR                     R                  < S35      eUR                  XR                     R                  :  a  XUR                  '   OXUR                  '   XUR                  S-   [        UR                  5      -   '   M     U $ )Nz7This function assumes every operator has a unique name z even accross multiple domains z and .r   )r   r   domainNotImplementedErrorsince_versionrL   )resschemas     r#   _build_schemasrV   M   s    C.0;;#}}KK 0 7 77)Mfkk_ ]55;]]4EU3{{K[KbKbJeefh  ##c++&6&D&DD#)FKK %=CFKK#F$8$8 99: 1 Jr0   c                  (    \ rS rSrSS jrSS jrSrg)OnnxTypec   c                j    [        U[        5      (       d  [        S[        U5       S35      eXl        g )Nztype_proto z must be of type TypeProto.)
isinstancer   	TypeErrortype
type_proto)rA   r^   s     r#   rB   OnnxType.__init__d   s/    *i00k$z*:);;VWXX$r0   c                $    SU R                   < S3$ )Nz	OnnxType(rG   r^   rI   s    r#   rJ   OnnxType.__repr__i   s    4??-Q//r0   ra   N)r^   r   rM   )r*   r+   r,   r-   rB   rJ   r/   r(   r0   r#   rX   rX   c   s    %
0r0   rX   c                  F    \ rS rSrSr        SS jr\SS j5       rSrg)	SparseTensorm   z\
Simple representation of a sparse tensor.
It is based on numpy but does not require scipy.
c                (    Xl         X l        X0l        g r?   )valuesindicesshape)rA   rg   rh   ri   s       r#   rB   SparseTensor.__init__s   s     
r0   c                .    U R                   R                  $ r?   )rg   dtyperI   s    r#   rl   SparseTensor.dtypez   s    {{   r0   )rh   ri   rg   N)rg   
np.ndarrayrh   rn   ri   z
tuple[int]rN   None)rN   r   )	r*   r+   r,   r-   r.   rB   propertyrl   r/   r(   r0   r#   rd   rd   m   s@    
 +5>H	 ! !r0   rd   c                    [        S U R                   5       5      n[        [        U R                  5      [        U R
                  5      U5      $ )z
Hosts a sparse tensor.
c              3  $   #    U  H  ov   M     g 7fr?   r(   ).0ds     r#   	<genexpr>#to_sparse_tensor.<locals>.<genexpr>   s     &X!Xs   )tupledimsrd   r   rg   rh   )attri   s     r#   to_sparse_tensorrz      s9     &SXX&&E,hs{{.CUKKr0   c                   U R                   nU[        R                  :X  aq  U R                  n[	        U R
                  5      n[        R                  " U[        S9R                  5       n[        U5       H	  u  pVXdU'   M     UR                  U5      $ U[        R                  [        R                  [        R                  [        R                  4;   a  [        R                  [         [        R                  ["        [        R                  [$        [        R                  [&        0nU R)                  S5      (       a  U R*                  nOU R                  n[	        U R
                  5      n[        R                  " X7U   S9R                  5       n[        U5       H	  u  pVXdU'   M     UR                  U5      $ [-        U 5      $ )zp
Similar to :func:`to_array` but deals with bfloat16,
float8e4m3fn, float8e4m3fnuz, float8e5m2, float8e5m2fnuz.
)rl   raw_data)	data_typer   BFLOAT16
int32_datarw   rx   npemptyr   ravel	enumeratereshapeFLOAT8E4M3FNFLOAT8E4M3FNUZ
FLOAT8E5M2FLOAT8E5M2FNUZr   r   r   r   HasFieldr|   r   )tensor	elem_typedatari   yirt   ms           r#   to_array_extendedr      sZ   
   IK(((  fkk"HHU(+113dODAaD $yy  """"	  $$l&&""J&&	
 ??:&&??D$$Dfkk"HHUI,/557dODAaD $yyFr0   c                  "    \ rS rSrSrSS jrSrg)Graph   gc                    Xl         g r?   r   )rA   r   s     r#   rB   Graph.__init__   s    r0   N)r   r   rN   ro   )r*   r+   r,   r-   	__slots__rB   r/   r(   r0   r#   r   r      s    Ir0   r   c                  2   \ rS rSr% SrSr\R                  S \R                  S \R                  S \R                  S \R                  S \R                  S	 \R                  S
 \R                  S \R                  S \R                   S \R"                  S \R$                  S \R&                  S \R(                  S 0rS\S'    S+     S,S jjrS r S+     S-S jjr\S 5       rS.S jr\S/S j5       r\S0S j5       r\S0S j5       r \S1S j5       r!\S1S j5       r"S2S jr#S1S  jr$\%RL                  S! 5       r'SSS".S# jr(\)S$ 5       r*\)  S3       S4S% jj5       r+\)   S5         S6S' jj5       r,\)SS&S(.         S7S) jj5       r-S*r.g)8OpRun   a  
Ancestor to all operators in this subfolder.

:param onnx_node: `onnx` node
:param 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
:param schema: operator schema
 c                B    [         R                  " U R                  5      $ r?   )r   float32fry   s    r#   <lambda>OpRun.<lambda>   s    "**SUU*;r0   c                n    U R                    Vs/ s H  n[        R                  " U5      PM     sn$ s  snf r?   )floatsr   r   )ry   r   s     r#   r   r      s"    3::+N:aBJJqM:+N+Ns    2c                ,    [        U R                  5      $ r?   )r   r   r   s    r#   r   r      s    %,r0   c                X    U R                    Vs/ s H  n[        U5      PM     sn$ s  snf r?   )graphsr   )ry   r   s     r#   r   r      s    cjj+IjE!Hj+I+I   'c                ,    [        U R                  5      $ r?   )r   r   r   s    r#   r   r      s    CEE
r0   c                X    U R                    Vs/ s H  n[        U5      PM     sn$ s  snf r?   )intsr   )ry   r   s     r#   r   r      s    #(()C(Q#a&()C)Cr   c                ,    [        U R                  5      $ r?   )rz   sparse_tensorr   s    r#   r   r      s    2B3CTCT2Ur0   c                X    U R                    Vs/ s H  n[        U5      PM     sn$ s  snf r?   )sparse_tensorsrz   ry   ts     r#   r   r      s+    ),););4
);AQ);4
 4
r   c                8    U R                   R                  S5      $ Nzutf-8)sdecoder   s    r#   r   r      s    355<<+@r0   c                b    U R                    Vs/ s H  oR                  S5      PM     sn$ s  snf r   )stringsr   )ry   r   s     r#   r   r      s!    ,T1XXg->,T,Ts   ,c                ,    [        U R                  5      $ r?   )r   r   r   s    r#   r   r      s    +<SUU+Cr0   c                X    U R                    Vs/ s H  n[        U5      PM     sn$ s  snf r?   )tensorsr   r   s     r#   r   r      s     3;;,W;a->q-A;,W,Wr   c                ,    [        U R                  5      $ r?   )rX   tpr   s    r#   r   r      s    x/?r0   c                X    U R                    Vs/ s H  n[        U5      PM     sn$ s  snf r?   )type_protosrX   r   s     r#   r   r      s    coo0Vo!o0V0Vr   zClassVar[dict[Any, Any]]_attribute_conversion_functionsNc           	        [        U[        5      (       d  [        S[        U5       S35      eS H$  nXB;  d  M
  [	        SU< S[        U5       S35      e   SU;  a  [        S5      eXl        X l        Uc  [        U R                  S	5      (       a  U R                  R                  U l        O|U R                  R                  [        ;   a#  [        U R                  R                     U l        O;UR                  [        ;   a  [        UR                     U l        OS U l        OX0l        S
U l        U R#                  5         g )Nz$run_params must be a dictionary not rP   )opsetsnew_ops
Attribute z must be in run_params, only z was found.logz#run_params must contains key 'log'.	op_schemaF)r[   dictr\   r]   RuntimeErrorsortedKeyError	onnx_node
run_paramshasattrrH   r   _schemar*   _schemasop_typehas_subgraph_load_attributes)rA   r   r   rU   ry   s        r#   rB   OpRun.__init__   s    *d++B4
CSBTTUVWW(C$" 'Dj)*+7  ) 
"@AA"$>t~~{33#~~77((H4'(?(?@""h.'	(9(9:#!L!r0   c                0    U R                   S   " U/UQ76   g )Nr   )r   )rA   patternargss      r#   _log
OpRun._log   s    w..r0   c                F   UR                   [        R                  :X  a  SSKJn  U R
                  R                  SS5      nU" UR                  U R
                  S   [        SU R
                  R                  SS5      S-
  5      Uc  SS9$ [        UR                  5       5      S9$ UR                   [        R                  ;   a#  [        R                  UR                      " U5      $ Uc[  [        S	UR                  < S
UR                   < SU R                  R                   < SU R                  R"                  < SU S35      e[        SUR                  < S
UR                   < SU R                  R                   < SU R                  R"                  < SU SU S35      e)z2
Converts an attribute value into a python value.
r   )ReferenceEvaluatorr   Nr   verbose   )r   r   r   zUnable to convert attribute z type z from node type z	, domain 
rP   z$Unable to convert default value for )r]   r   GRAPH"onnx.reference.reference_evaluatorr   r   getr   maxlistrg   r   r   AttributeErrorr   r   r   rQ   )rA   ry   ref_attr   r   s        r#   _extract_attribute_valueOpRun._extract_attribute_value   s    88~+++ oo)))T:G%x0At229a@1DE '	  6:'..:J5K	  88u<<<88B3GG? .sxxl& M""&.."8"8!; <..//2"SE< 
 27<<2B& U"nn447 8nn++.bRyC
 	
r0   c                6    UR                  S U =(       d    0 US9$ )N
attributes)runcontextvaluer   s      r#   _evaluate_subgraphOpRun._evaluate_subgraph  s    yyw}"yDDr0   c                   SU l         / nU R                  R                   H  nUR                  nUR                  (       a  [        UR                  5      nSU l         OU R                  U5      n[        XU5        UR                  U5        UR                  [        R                  :X  d  M  SU l        U =R                   UR                   -  sl         [        U SUR                   3US4S j5        M     U R                  (       Ga;  U R                  R                  S;  Ga   U R                  R                  R!                  5        H  u  pV[#        X5      (       a  M  [%        USS5      (       a(  ['        SU< S	U R                  R                  < S
35      e[#        US5      (       d  Md  UR(                  R                  S:X  d>  UR(                  R                  S:X  a'  UR(                  R*                  R,                  S:X  a  SnOU R                  UR(                  U5      n[        XU5        UR                  U5        M     [/        U5      U l        g)zChecks and loads attributes.FT_run_Nc                .    [         R                  XU5      $ r?   )r   r   r   s      r#   r   (OpRun._load_attributes.<locals>.<lambda>,  s    %BZBZ
Cr0   >   Constantrequiredr   z3 is expected based on ONNX specifications for node rP   default_valuer      )has_linked_attributer   	attributer   ref_attr_namer<   r   setattrappendr]   r   r   r   r   r   r   itemsr   getattrr   r   r   r}   setattributes_names_)rA   added_attributesry   r   r   kr"   s          r#   r   OpRun._load_attributes  s   $)!>>++C88D  #C$5$56,0)55c:D&##D)xx>///$(!))U-G-GG)CHH:&*/D  ,( <<<DNN22,F//557t''q*d33*( .((,(>(>'AD  q/22??//14OO00A5 ! 1 1 ; ;q @ %)E$($A$A!//ST$UE/(//2# 8$ "%%5!6r0   c                t   [        U [        5      (       d  [        S[        U 5      < S35      e[	        5       n[	        5       nU R
                   H  nUR                  UR                  5        M      U R                   H  nUR                  UR                  5        M      U R                   H  nUR                  UR                  5        M      U R                   HR  nUR                   H  nUR                  U5        M     UR                   H  nX;  d  M
  UR                  U5        M     MT     [        U5      $ )z
Returns 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 rP   )r[   r   r\   r]   r   initializeraddr   sparse_initializerinputnodeoutputr   )	graphlocalknowninitsparse_initinpr  or   s	            r#   implicit_inputsOpRun.implicit_inputsF  s     %,,.tE{oQ?@@%%DIIdii  & 33KIIk&&' 4;;CIIchh JJD[[		! !ZZ>IIaL    E{r0   c                .    U R                   R                  $ )zReturns node attribute `input`.)r   r  rI   s    r#   r  OpRun.input_  s     ~~###r0   c                .    U R                   R                  $ )z Returns node attribute `output`.)r   r	  rI   s    r#   r	  OpRun.outputd       ~~$$$r0   c                .    U R                   R                  $ )z!Returns node attribute `op_type`.)r   r   rI   s    r#   r   OpRun.op_typei  s     ~~%%%r0   c                .    U R                   R                  $ )z Returns node attribute `domain`.)r   rQ   rI   s    r#   rQ   OpRun.domainn  r  r0   c                    g)z
Tells 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(   rI   s    r#   need_contextOpRun.need_contexts  s     r0   c                   U R                   R                  S-   SU R                  R                   3/n[	        U R
                  R                  5       5       HF  u  p#US;   a  M  SUS   s=::  a  S::  d  M  O  M#  US   S:w  d  M.  UR                  S	U S
U S35        MH     UR                  S5        SR                  U5      $ )NrF   z    op_type=>   descr   ar   zr   z    =,rG   r   )	rH   r*   r   r   r   __dict__r   r   join)rA   attsr  r"   s       r#   __str__OpRun.__str__|  s    ''#-dnn>T>T=U/VW4==..01DA))ad!c!!aesld1#QqcO,	 2
 	Cyyr0   c                J    [        SU R                  R                  < S35      e)a,  
Should be overwritten.

:param args: operator inputs
:param 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.
:return: outputs
z/Method '_run' must be overwritten for operator rP   )rR   rH   r*   )rA   r   kwargss      r#   _run
OpRun._run  s)     "=dnn>U>U=XXYZ
 	
r0   )linked_attributesr   c                  U R                  5       (       a  Uc  [        S[        U 5       S35      eOUb  [        S[        U 5       S35      eU R                  (       a  Uc  [	        S[        U 5       S35      eU R                  (       d'  Ub$  [	        S[        U 5       S[        U5       S35      e0 nU R                  (       a  Uc  [        S	[        U 5       S35      eU R                   He  n[        X5      n[        U[        5      (       d  M%  UR                  U;  a   [	        S
U< SU< S[        U 5       S35      eXR                     XE'   Mg     U R                  SU R                  R                  [        U5      5        0 nU R                   HO  nXT;   a  M
  [!        X5      (       d(  [#        SU< SU R                  R                  < S35      e[        X5      Xu'   MQ     U R$                  (       a4  U R                  (       a  U(       d  [        S[        U 5       S35      eXS'   Ub  X'S'    U(       a  U R&                  " U0 UDUD6nOU R&                  " U0 UD6n U R                  SU R                  R                  [        U5      5        [        U[,        5      (       d0  [)        SU R                  R                  < S[        U5       S35      e[        U5      S:X  a$  [	        SU R                  R                  < S35      e[/        S U 5       5      (       aC  U Vs/ s H  n[        U5      PM     nn[)        SU R                  R                  < SU< S35      eU$ ! [(        [        4 ae  n	[)        SU V
s/ s H  n
[        U
5      PM     Os  sn
f sn
 S[+        U5       S[+        U5       SU R                  R                  < S3	5      U	eSn	A	ff = fs  snf ) ac  
Calls method ``_run``, catches exceptions,
displays a longer error message.

:param args: inputs
:param linked_attributes: used if this has an attriute linked
    to the attribute of the function it belongs to
:param context: if this node is part of the subgraph, `context`
    is a dictionary with the values this node may use
:return: 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' rP   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 z and attributes z and linked attributes=z (operator ).z-- done %s.run -> %d outputszMethod '_run' of class z does not return a tuple but r   z does not return any result.c              3  B   #    U  H  n[        U[        5      v   M     g 7fr?   )r[   rw   )rs   r   s     r#   ru   OpRun.run.<locals>.<genexpr>  s     1Sz!U##Ss   z6One of the results returned by method '_run' of class zf is a tuple, this is no onnx correponding type (Map, List, Tensor, SparseTensor). All returned types: )r  r   r]   r   r   r   r   r   r   r[   r<   r   r   rH   r*   lenr   	NameErrorr   r-  r\   r   rw   any)rA   r/  r   r   overridden_attributesry   r"   r,  rT   er   r   dtypess                r#   r   	OpRun.run  s    "(d4PQ    $T$ZL0[\  $$):)BT$ZL(st  ((->-JT$ZL )''*+<'=&>aA  !#$$ ($  $T
|1.  --D&a--vv%66(J3'QUVgUj k''+Dzl!5  2C661J). . 			.0G0GTS))C+4%% '?@W@W?ZZ[\  "$,FK * ((1B"LTRVZLXYZ  $5<  '9
	$iiI)>I&Iii00 			0$..2I2I3s8T#u%%)$..*A*A)DDabfgjbkallmn  s8q=)$..*A*A)DD`a  1S111'*+s!d1gsF+HI`I`Hc d''-j3 
 
- >* 	$t%<t!d1gt%<$==M&>""9&AV:W9X Y!^^447r; 		  ,s1   2M% M% $O%O5
O?NAOOc                    U R                   nSU;  a  U[        5       4$ UR                  SS5      u  p [        U5      nX4$ ! [         a    U R                   [        5       4s $ f = f)Nr   r   )r*   r
   r   r   r   )clsr   r!   i_verss       r#   
infer_nameOpRun.infer_name  so    ||d?+---[[a(
	6YF |  	6<<!3!555	6s   A  A%$A%c                d   U R                  5       u  pEU R                  nSnUc  Uc  [        XEU5      nUR                  nUc  Uc  [        XEU5      nUR                  n[        U5       Vs/ s H  nSU 3PM
     n	n[        U5       Vs/ s H  nSU 3PM
     n
n[        XIU
40 UD6nU$ s  snf s  snf )ad  
Creates an ONNX node for this class based on the given information.

:param n_inputs: number of inputs (default is defined by the operator schema)
:param n_outputs: number of outputs (default is defined by the operator schema)
:param verbose: verbosity
:param kwargs: node attributes
:return: 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)
Nxr   )r>  	op_domainr	   	min_input
min_outputranger   )r<  n_inputs	n_outputsr,  r   opsetrQ   rU   r   names_in	names_outr  s               r#   r   OpRun.make_node   s    6 )~#GF;''H~#GF;))I%*8_5_asG_5&+I&67&6qW&6	7I@@ 67s   *B(B-r   c                p   ^ SU4S jjnU R                   " X40 UD6nTUSS[        5       0S.nU " Xg5      nU$ )a$  
Instantiates this class based on the given information.

:param n_inputs: number of inputs (default is defined by the operator schema)
:param n_outputs: number of outputs (default is defined by the operator schema)
:param verbose: verbosity
:param kwargs: node attributes
:return: NodeProto
c                B   > TS:  a  [        U [        U5      -  5        g g )Nr   )printrw   )r   r   r   s     r#   log_function"OpRun.create.<locals>.log_function>  s     {gd+, r0   Nr   )r   r   r   r   )r   rL   r   r   rN   ro   )r   r
   )	r<  rF  rG  r   r,  rO  r  r   cls	      `     r#   createOpRun.create,  sJ    $	- }}X;F;-/0	

 "	r0   rG  r   c                   U R                   " [        U5      4XS.UD6nUR                  " U6 n[        U5      S:X  a  US   $ U$ )z
Evaluates this operator.

:param args: inputs
:param n_outputs: number of outputs (default is defined by the operator schema)
:param verbose: verbosity
:param kwargs: node attributes
:return: NodeProto
rT  r   r   )rR  r4  r   )r<  rG  r   r   r,  instrT   s          r#   eval
OpRun.evalL  sF    " zz#d)TyTVThhos8q=q6M
r0   )r   r   r   r   r   r   r?   )r   r   r   zdict[str, Any]rU   r   )ry   r   r   zAttributeProto | NonerN   r   )rN   ro   )r
  r   rN   z	list[str])rN   zIterable[str]rM   )rN   boolNN)rF  
int | NonerG  r[  r,  r   rN   r   )NNr   )
rF  r[  rG  r[  r   r   r,  r   rN   r   )
r   z	list[Any]rG  r[  r   r   r,  r   rN   r   )/r*   r+   r,   r-   r.   rB  r   FLOATFLOATSr   GRAPHSINTINTSSPARSE_TENSORSPARSE_TENSORSSTRINGSTRINGSTENSORTENSORS
TYPE_PROTOTYPE_PROTOSr   __annotations__rB   r   r   staticmethodr   r   r  rp   r  r	  r   rQ   r  r)  abcabstractmethodr-  r   classmethodr>  r   rR  rW  r/   r(   r0   r#   r   r      s    I 	;N6I2C$$&U%% (
 	@ TC W!!#?""$V!A#%= ( OS " 0> HK :/ EI
!
,A
	
@ E E+7Z  0 $ $ % % & & % % 	
 
 ,0 \| 	 	   $ $)) ) 	)
 
) )V   $ $	  	
  
 >  !%	  	
  
 r0   r   c                  ,    \ rS rSrSrSSS jjrS rSrg)	OpRunExpandid  z0
Class any operator to avoid must inherit from.
Nc                2    [        S[        U 5       S35      eNz5The reference implementation must not use this node (r1  r   r]   )rA   r   rO  impls       r#   rB   OpRunExpand.__init__i      CDJ<rR
 	
r0   c                2    [        S[        U 5       S35      erq  rr  rA   inputsr,  s      r#   r-  OpRunExpand._runn  ru  r0   r(   r?   )r   r   rO  r   rs  r   r*   r+   r,   r-   r.   rB   r-  r/   r(   r0   r#   ro  ro  d  s    


r0   ro  c                  D    \ rS rSrSr  S       S	S jjrS rS rSrg)

OpFunctionit  z
Runs a custom function.
Nc                
   Uc(  [        SUR                  < SUR                  < S35      e[        R	                  XU5        X0l        [        U R
                  SU5       Vs0 s H  nU[        X5      _M     snU l        g s  snf )Nz"impl cannot be None for node type  from domain rP   attributes_)r   r   rQ   r   rB   impl_r   r  )rA   r   rO  rs  r   r   s         r#   rB   OpFunction.__init__y  s     <4Y5F5F4I J(//2!5  	t5

  

M:F
F '$%%F
 
s   !B c                B    U R                   " U R                  /UQ70 UD6$ r?   )	_run_implr  rw  s      r#   r-  OpFunction._run  s    ~~djj<6<V<<r0   c                |   [        UR                  5      [        U5      :w  aJ  [        S[        U5       S[        UR                  5       SU R                  < SU R
                  < S3	5      e[        [        UR                  U5      5      nU R                  R                  5       nUR                  U5        UR                  S XES9n[        UR                  5      [        U5      :w  aJ  [        S[        U5       S[        UR                  5       SU R                  < SU R
                  < S3	5      e[        U5      $ )	Nz.Mismatch lengths between the number of inputs z# and the expected number of inputs z
 for node r~  rP   r   z/Mismatch lengths between the number of outputs z$ and the expected number of outputs )r4  input_namesr   rx  r   rQ   r   zipr  copyupdater   output_namesrw   )rA   rs  rx  r,  feedsr   resultss          r#   r  OpFunction._run_impl  s)   t CK/@V N5585E4F G LL+=qJ 
 S))623%%**,
&!((4(>t  !S\1A#g, P669$:K:K6L5M N LL+=qJ 
 W~r0   )r  r  rZ  )r   r   rO  r   rs  r   r   zdict[str, Any] | None)	r*   r+   r,   r-   r.   rB   r-  r  r/   r(   r0   r#   r|  r|  t  sD     ,0

 
 	

 *
*=r0   r|  c                  ,    \ rS rSrSrSSS jjrS rSrg)	OpFunctionContextDependanti  z
The 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.
Nc                    [         R                  XX 0 S9  X0l        UR                  UR                     n[        UR                  XAR                  5      U l        g )N)rs  r   )r|  rB   parentr   rQ   r	   r   schema_)rA   r   rO  r  versions        r#   rB   #OpFunctionContextDependant.__init__  sK    D\QST--	 0 01!)"3"3W>N>NOr0   c                   / nU H=  n [        UR                  5      nUR                  [        XTR                   5      5        M?     U R"                  R%                  U R&                  U5      nU" U R&                  U R(                  5      nU R*                  " UR,                  /UQ70 UD6$ ! [         a  nUR                  [        :X  a  [        R
                  n S nANUR                  [        :X  a  [        R                  n S nANUR                  [        :X  a  [        R                  n S nAGNUR                  [        :X  a  [        R                  n S nAGN;UR                  [        :X  a  [        R                  n S nAGNeUeS nAff = fr?   )r   rl   r   r   r   r   r   r   r   r   r   r   r   BLOFAT16r   r   ri   r  
_load_implr   r   r  r  )	rA   rx  r,  typesr   ttyper8  rQ  rV  s	            r#   r-  OpFunctionContextDependant._run  s    A09 LL/ww?@! " [[##DNNE:$..$//2~~djj<6<V<<!  77l*'44EWW.'66EWW
*'22EWW.'66EWW('00EGs5   B))
F
3$F$F$F/$F$FFF
)r  r  r?   )r   r   rO  r   r  r   rz  r(   r0   r#   r  r    s    P=r0   r  )rN   zdict[str, type])ry   r   rN   rd   )r   r   rN   rn   )4
__future__r   rk  typingr   r   r   numpyr   onnxr   	onnx.defsr   r	   r
   onnx.helperr   r   r   onnx.numpy_helperr   onnx.onnx_pbr   r   r   r   #onnx.reference.custom_element_typesr   r   r   r   r   r$   r   r&   r3   rR   r6   r9   r<   rV   r   rX   rd   rz   r   r   ABCr   ro  r|  r  r(   r0   r#   <module>r     s    # 
 * *   R R S S & I I | , !4  ; ; & 0 0! !$L$N lCGG l^
% 
 . .b$= $=r0   