§
    2�Åjt  ã                  ó˜   — d dl mZ d dlmZ d dlmZ d dlZd dlZd dl	Zd dl
mZmZmZmZmZmZ d dlmZ d dlmZmZ  G d„ d	¦  «        ZdS )
é    )Úannotations)ÚBytesIO)ÚAnyN)ÚFunctionProtoÚ
GraphProtoÚ
ModelProtoÚ	NodeProtoÚTensorProtoÚ	TypeProto)Úop_run)ÚSymbolBindingsÚcheck_value_against_typec                  óú   — e Zd ZdZ	 	 	 	 	 d;d<d„Zd=d„Zd>d„Zd?d„Zed „ ¦   «         Z	ed!„ ¦   «         Z
ed"„ ¦   «         Zed#„ ¦   «         Zed$„ ¦   «         Zed%„ ¦   «         Zd@d&„ZdAdBd*„ZdCd+„Z	 dDdEd0„Z	 	 	 	 dFdGd:„ZdS )HÚReferenceEvaluatoraR  Computes the outputs of an ONNX proto (`ModelProto`, `FunctionProto`, `GraphProto`, `NodeProto`).

    This is a pure python implementation of ONNX specifications.
    Mismatches may remain between the official specifications and the implementation here.
    In the case of such a mismatch, the official spec overrides this implementation.

    Args:
        proto: :class:`onnx.ModelProto`, :class:`onnx.GraphProto`,
            :class:`onnx.FunctionProto`, :class:`onnx.NodeProto`,
            filename or bytes
        verbose: display intermediate results on the standard output
            during the execution
        opsets: if *proto* is an instance of *GraphProto*, opsets must
            be defined by a dictionary of
        functions: known onnx functions
        new_ops: this runtime can be used to test the implementations of
            new operators, *new_ops* is a list of classes derived from
            :class:`OpRun <onnx.reference.op_run.OpRun>`, every class
            must define the static attribute `domain`, there may be
            multiple implementations for the same operator, the first
            one in the list is used.
        check_shape_annotations: if True, every input and computed value is
            checked, as it becomes available, against its declared static
            shape annotation (see `docs/ShapeAnnotationSemantics.md
            <https://github.com/onnx/onnx/blob/main/docs/ShapeAnnotationSemantics.md>`_).
            A :class:`ShapeAnnotationError
            <onnx.reference.shape_annotation_checker.ShapeAnnotationError>`
            is raised on the first violation. This only supports today's
            single, global namespace of symbolic dimension names, and only
            validates tensor-typed values; it defaults to False, since it
            is a diagnostic capability and not part of default execution.

    The class maps every node to its associated implementation.
    When a subgraph of a function is met,
    it uses this class to execute the subgraph or the function.
    Next example shows how to run `ReferenceEvaluator` with an onnx model
    stored in file `model.onnx`.

    ::

        import numpy as np
        from onnx.reference import ReferenceEvaluator

        X = np.array(...)
        sess = ReferenceEvaluator("model.onnx")
        results = sess.run(None, {"X": X})
        print(results[0])  # display the first result

    Parameter *verbose* may be used to show intermediate results.

    ::

        import numpy as np
        from onnx.reference import ReferenceEvaluator

        X = np.array(...)
        sess = ReferenceEvaluator("model.onnx", verbose=1)
        results = sess.run(None, {"X": X})
        print(results[0])  # display the first result

    The class can use any implementation available in folder
    `ops <https://github.com/onnx/onnx/tree/main/onnx/reference/ops>`_.
    Adding an implementation requires two changes. The first one is
    the implementation itself. Any existing node can be used as a template.
    The second is one line in file `_op_list.py
    <https://github.com/onnx/onnx/tree/main/onnx/reference/ops/_op_list.py>`_
    to import the file and let the reference evaluator know it exists.

    This class can also be used to test an implementation of
    a custom operator. Let's assume this new operator
    is `InvAlpha` from domain `custom`. The implementation
    must take place in a class inheriting from
    :class:`OpRun <onnx.reference.op_run.OpRun>`.
    It must also define attribute `op_domain`.
    Here is an example which computes :math:`\\frac{1}{X + \\alpha}`.

    .. exec_code::

        from onnx.reference.op_run import OpRun

        class InvAlpha(OpRun):

            op_domain = "custom"

            def _run(self, x, alpha=None):
                # None must be the default value, it is automatically
                # replaced by class OpRun with either the default value
                # specified in the NodeProto or an attribute value defined
                # in a `FunctionProto`.
                return (1 / (x + alpha),)

    `alpha` is an attribute. It can be defined by the onnx node or
    be defined by the function using this node. It is safe to assume
    that attributes are known at the same time as the input.
    Class `ReferenceEvaluator` must know about this new implementation
    and this can be done by specified argument *new_ops*.

    ::

        sess = ReferenceEvaluator(onnx_model, new_ops=[InvAlpha])
        got = sess.run(None, {"X": x})[0]

    A specific node can be simply evaluated.

    .. exec_code::

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

        x = np.array([[0, 1], [-1, 2]], dtype=np.float32)
        y = Celu.eval(x, alpha=0.5)
        print(y)

    This can also be expressed as:

    .. exec_code::

        import numpy as np
        from onnx.reference.ops import load_op

        Celu = load_op("", "Celu")  # domain is ""
        x = np.array([[0, 1], [-1, 2]], dtype=np.float32)
        y = Celu.eval(x, alpha=0.5)
        print(y)

    It is possible to overwrite an existing operator.
    The class name must be the same. The domain does not have
    to be specified for the default domain. However, by default,
    class `OpRun` will load the most recent for this operator.
    It can be explicitly specified by adding static attribute
    `op_schema` of type :class:`OpSchema
    <onnx.onnx_cpp2py_export.defs.OpSchema>`.

    ::

        from onnx.reference.op_run.op_conv import Conv as _Conv

        class Conv(_Conv):

            op_schema = instance_of_OpSchema()

            def _run(self, ...):
                ...

        An operator may be different in a later opset. In that case,
        a new implementation needs to be registered. `Pad_11`, `Pad_18`.
        `Pad_11` is the implementation chose for opset in [11, 17].
        `Pad_18` is selected for any greater opset. Both classes must be
        imported into file `_op_list.py` to register their existence to the
        runtime.

        An operator may have a reference implementation such as `CastLike`
        and still be defined as a function. By default, the reference implementation
        is used. This behavior can be changed by adding a class to the list
        of overwritten operators. It must inherit from :class:`OpRunExpand`.

        ::

            from onnx.reference.op_run import OpRunExpand

            class CastLike(OpRunExpand):
                op_domain = ""

            ref = ReferenceEvaluator(model, new_ops=[CastLike])
            # ...

            This mechanism is used in unit test to check the function
            implementation a schema may define.
    Nr   FÚprotor   Úopsetsúdict[str, int] | NoneÚ	functionsú/list[ReferenceEvaluator | FunctionProto] | NoneÚverboseÚintÚnew_opsúlist[type[op_run.OpRun]] | NoneÚcheck_shape_annotationsÚboolÚreturnÚNonec           	     ój
  — || _         d | _        d | _        t          |t          j        j        ¦  «        r|| _        | j        j        }nd | _        t          |t          ¦  «        r=t          |d¦  «        5 }t	          j        |¦  «        }d d d ¦  «         n# 1 swxY w Y   n6t          |t          ¦  «        r!t	          j        t          |¦  «        ¦  «        }|| _        i | _        g | _        t          |t"          ¦  «        rM|j        | _        d„ |j        D ¦   «         | _        |�t-          d¦  «        ‚|�t-          d¦  «        ‚|j        }�nt          |t0          ¦  «        r3|| _        t          |t2          ¦  «        st5          d¦  «        ‚|| _        nÑt          |t6          ¦  «        rHd | _        d„ |j        D ¦   «         | _        |�t-          d¦  «        ‚t9          |j        ¦  «        | _        ntt          |t<          ¦  «        r?d | _        |j        |j        dk    rd	nt          j          !                    ¦   «         i| _        n t5          d
tE          |¦  «        › d�¦  «        ‚| j        �rd„ | j        j#        D ¦   «         | _$        d„ | j        j#        D ¦   «         | _        d„ | j        j%        D ¦   «         | _&        d„ | j        j%        D ¦   «         | _        t9          | j        j'        ¦  «        t9          | j        j(        ¦  «        z   | _)        | j        j*        | _+        d„ | j        j#        D ¦   «         }tY          | j        d¦  «        r| j        j-        D ]}	|	j"        ||	j.        <   Œ|| _/        nct9          |j#        ¦  «        | _$        t9          |j%        ¦  «        | _&        g | _)        t          |t<          ¦  «        r	|g| _+        n|j*        | _+        |�½|D ]º}t          |t6          ¦  «        rQ|  0                    ||t9          | j         1                    ¦   «         ¦  «        ¬¦  «        | j        |j        |j.        f<   Œht          |td          ¦  «        r|j        }
|| j        |
j        |
j.        f<   Œ›t5          d
tE          |¦  «        ›d�¦  «        ‚|| _3        i | _4        |�w|D ]t}tY          |d¦  «        stk          d|› d�¦  «        ‚tm          |tn          j8        ¦  «        st5          d|› d�¦  «        ‚|j9        |j:        f}|| j4        v rŒj|| j4        |<   Œu|  ;                    ¦   «          d S )NÚrbc                ó(   — i | ]}|j         |j        “ŒS © ©ÚdomainÚversion©Ú.0Úds     úSC:\Projects\Historical\venv\Lib\site-packages\onnx/reference/reference_evaluator.pyú
<dictcomp>z/ReferenceEvaluator.__init__.<locals>.<dictcomp>ä   ó   € ÐLÐLÐL°A˜AœH a¤iÐLÐLÐLó    z+opsets must be None if proto is ModelProto.z.functions must be None if proto is ModelProto.z3opsets must be a dictionary if proto is GraphProto.c                ó(   — i | ]}|j         |j        “ŒS r!   r"   r%   s     r(   r)   z/ReferenceEvaluator.__init__.<locals>.<dictcomp>ñ   r*   r+   z.opsets must be None if proto is FunctionProto.Ú é   zUnexpected type z for proto.c                ó   — g | ]	}|j         ‘Œ
S r!   ©Úname©r&   Úis     r(   ú
<listcomp>z/ReferenceEvaluator.__init__.<locals>.<listcomp>ÿ   ó   € Ð HÐ HÐ H¨A ¤Ð HÐ HÐ Hr+   c                ó   — g | ]	}|j         ‘Œ
S r!   ©Útyper2   s     r(   r4   z/ReferenceEvaluator.__init__.<locals>.<listcomp>   r5   r+   c                ó   — g | ]	}|j         ‘Œ
S r!   r0   )r&   Úos     r(   r4   z/ReferenceEvaluator.__init__.<locals>.<listcomp>  ó   € Ð!JÐ!JÐ!J¨Q !¤&Ð!JÐ!JÐ!Jr+   c                ó   — g | ]	}|j         ‘Œ
S r!   r7   r2   s     r(   r4   z/ReferenceEvaluator.__init__.<locals>.<listcomp>  r;   r+   c                ó(   — i | ]}|j         |j        “ŒS r!   ©r1   r8   r2   s     r(   r)   z/ReferenceEvaluator.__init__.<locals>.<dictcomp>  ó   € ÐHÐHÐH¨A˜œ ¤ÐHÐHÐHr+   Ú
value_info)r   r   z for a function.Ú	op_domainzClass z# must define attribute 'op_domain'.z& must inherit from OpRun (in new_ops).)<Úcheck_shape_annotations_Úoutput_types_Úinput_types_Ú
isinstanceÚonnxÚmodel_containerÚModelContainerÚ
container_Úmodel_protoÚstrÚopenÚloadÚbytesr   Úproto_Ú
functions_Úattributes_r   ÚgraphÚonnx_graph_Úopset_importÚopsets_Ú
ValueErrorr   r   ÚdictÚ	TypeErrorr   ÚlistÚ	attributer	   r#   ÚdefsÚonnx_opset_versionr8   ÚinputÚinput_names_ÚoutputÚoutput_names_ÚinitializerÚsparse_initializerÚinits_ÚnodeÚnodes_Úhasattrr@   r1   Ú
all_types_Ú	__class__Úvaluesr   r   Únew_ops_ÚAttributeErrorÚ
issubclassr   ÚOpRunrA   Ú__name__Ú_init)Úselfr   r   r   r   r   r   ÚfÚ	all_typesÚ
shape_typeÚonxÚclÚkeys                r(   Ú__init__zReferenceEvaluator.__init__Ç   s�  € ð )@ˆÔ%Ø!ˆÔØ ˆÔå�e�TÔ1Ô@ÑAÔAð 	#ØJOˆDŒOØ”OÔ/ˆEˆEà"ˆDŒOå�e�SÑ!Ô!ð 	.Ý�e˜TÑ"Ô"ð % aÝœ	 !™œ�ð%ð %ð %ñ %ô %ð %ð %ð %ð %ð %ð %øøøð %ð %ð %ð %øå˜�uÑ%Ô%ð 	.Ý”I�g e™nœnÑ-Ô-ˆEØˆŒØEGˆŒØ&(ˆÔÝ�e�ZÑ(Ô(ð 	IØ$œ{ˆDÔØLÐL¸Ô9KÐLÑLÔLˆDŒLØÐ!Ý Ð!NÑOÔOÐOØÐ$Ý Ð!QÑRÔRÐRØœˆI‰IÝ˜�zÑ*Ô*ð 	IØ$ˆDÔÝ˜f¥dÑ+Ô+ð WÝÐ UÑVÔVÐVØ!ˆDŒLˆLÝ˜�}Ñ-Ô-ð 	IØ#ˆDÔØLÐL¸Ô9KÐLÑLÔLˆDŒLØÐ!Ý Ð!QÑRÔRÐRÝ# E¤OÑ4Ô4ˆDÔÐÝ˜�yÑ)Ô)ð 	IØ#ˆDÔà”Ø”< 2Ò%Ð%ð  ˜aå”Y×1Ò1Ñ3Ô3ðˆDŒLˆLõ ÐG­t°E©{¬{ÐGÐGÐGÑHÔHÐHØÔñ 	)Ø HÐ H°Ô1AÔ1GÐ HÑ HÔ HˆDÔØ HÐ H°Ô1AÔ1GÐ HÑ HÔ HˆDÔØ!JÐ!J°$Ô2BÔ2IÐ!JÑ!JÔ!JˆDÔØ!JÐ!J°$Ô2BÔ2IÐ!JÑ!JÔ!JˆDÔÝ˜tÔ/Ô;Ñ<Ô<½tØÔ Ô3ñ@ô @ñ ˆDŒKð Ô*Ô/ˆDŒKØHÐH°Ô1AÔ1GÐHÑHÔHˆIÝ�t”{ LÑ1Ô1ð AØ"&¤+Ô"8ð Að A�JØ1;´�I˜jœoÑ.Ð.Ø'ˆDŒOˆOå $ U¤[Ñ 1Ô 1ˆDÔÝ!% e¤lÑ!3Ô!3ˆDÔØˆDŒKÝ˜%¥Ñ+Ô+ð )Ø$˜g�”�à#œj�”ØÐ Øð 	Tð 	T�Ý˜a¥Ñ/Ô/ð TØ8<¿ºØ 7µd¸4¼?×;QÒ;QÑ;SÔ;SÑ6TÔ6Tð 9Gñ 9ô 9�D”O A¤H¨a¬fÐ$4Ñ5Ð5õ   Õ#5Ñ6Ô6ð TØœ(�CØ<=�D”O C¤J°´Ð$8Ñ9Ð9å#Ð$Rµt¸A±w´wÐ$RÐ$RÐ$RÑSÔSÐSØˆŒØCEˆŒØÐØð (ð (�Ý˜r ;Ñ/Ô/ð Ý(ØH ÐHÐHÐHñô ð õ " "¥f¤lÑ3Ô3ð YÝ#Ð$W¨RÐ$WÐ$WÐ$WÑXÔXÐXØ”l B¤KÐ/�Ø˜$œ-Ð'Ð'àØ%'�”˜cÑ"Ð"Ø�
Š
‰Œˆˆˆs   Á5BÂBÂBra   r
   ú
np.ndarrayc                óô   — t           j                             |¦  «        }|j        }| j        r'| j                             |¦  «        r| j        |         S | j        �t          d¦  «        ‚t          d¦  «        ‚)z#Returns a tensor saved as external.NzPReferenceEvaluator assumes a LargeContainer was loaded with its external tensor.zPAn instance of LargeContainer should be created before using ReferenceEvaluator.)rF   Úexternal_data_helperÚExternalDataInfoÚlocationrI   Ú!is_in_memory_external_initializerÚRuntimeError)rp   ra   Úinfor|   s       r(   Úretrieve_external_dataz)ReferenceEvaluator.retrieve_external_data0  sˆ   € åÔ(×9Ò9¸+ÑFÔFˆØ”=ˆØŒ?ð 	-˜tœ×PÒPØñ 
ô  
ð 	-ð ”? 8Ô,Ð,àŒ?Ð&ÝØbñô ð õ Ø^ñ
ô 
ð 	
r+   Úac           
     óÞ  — t          |t          t          t          f¦  «        r|S t          |t          j        ¦  «        rö| j        dk     rY|j        dk    r|j        › d|j	        › d�S |j        › d|j	        › d| 
                    ¦   «         › d|                     ¦   «         › d�S |                     ¦   «                              ¦   «         }t          |¦  «        dk    rE|d d…         }|j        › d|j	        › dd	                     t!          t          |¦  «        ¦  «        › d
�S |j        › d|j	        › d|› �S t#          |d¦  «        r(d                     t!          | j        |¦  «        ¦  «        S |S )Né   r   ú:z (empty)z in [ú, ú]é   ú,z...Úappend)rE   rK   r   ÚfloatÚnpÚndarrayr   ÚsizeÚdtypeÚshapeÚminÚmaxÚravelÚtolistÚlenÚjoinÚmaprf   Ú_log_arg)rp   r�   Úelementss      r(   r—   zReferenceEvaluator._log_argB  sg  € Ý�a�#�s¥EÐ*Ñ+Ô+ð 	ØˆHÝ�a�œÑ$Ô$ð 		5ØŒ|˜aÒÐØ”6˜Q’;�;ØœgÐ9Ð9¨¬Ð9Ð9Ð9Ð9Øœ'ÐGÐG A¤GÐGÐG°!·%²%±'´'ÐGÐG¸Q¿UºU¹W¼WÐGÐGÐGÐGØ—w’w‘y”y×'Ò'Ñ)Ô)ˆHÝ�8‰}Œ}˜qÒ Ð Ø# B Q Bœ<�Øœ'ÐOÐO A¤GÐOÐO¨c¯hªhµs½3ÀÑ7IÔ7IÑ.JÔ.JÐOÐOÐOÐOØ”gÐ4Ð4 ¤Ð4Ð4¨(Ð4Ð4Ð4Ý�1�hÑÔð 	4Ø—9’9�S ¤°Ñ2Ô2Ñ3Ô3Ð3Øˆr+   ÚlevelÚpatternrK   Úargsú	list[Any]c                ó|   ‡ — |‰ j         k     r/ˆ fd„|D ¦   «         }t          |t          |¦  «        z  ¦  «         d S d S )Nc                ó:   •— g | ]}‰                      |¦  «        ‘ŒS r!   )r—   )r&   r�   rp   s     €r(   r4   z+ReferenceEvaluator._log.<locals>.<listcomp>U  s%   ø€ Ð7Ð7Ð7¨Q˜Ÿš aÑ(Ô(Ð7Ð7Ð7r+   )r   ÚprintÚtuple)rp   r™   rš   r›   Únew_argss   `    r(   Ú_logzReferenceEvaluator._logS  sP   ø€ Ø�4”<ÒÐØ7Ð7Ð7Ð7°$Ð7Ñ7Ô7ˆHÝ�'�E (™OœOÑ+Ñ,Ô,Ð,Ð,Ð,ð  Ðr+   c                ó   — | j         S )zReturns the input names.)r^   ©rp   s    r(   Úinput_nameszReferenceEvaluator.input_namesX  ó   € ð Ô Ð r+   c                ó   — | j         S )z)Returns the input types if any specified.)rD   r¤   s    r(   Úinput_typeszReferenceEvaluator.input_types]  r¦   r+   c                ó   — | j         S )zReturns the output names.)r`   r¤   s    r(   Úoutput_nameszReferenceEvaluator.output_namesb  ó   € ð Ô!Ð!r+   c                ó   — | j         S )zReturns the output types.)rC   r¤   s    r(   Úoutput_typeszReferenceEvaluator.output_typesg  r«   r+   c                ó   — | j         S )zReturns the opsets.)rU   r¤   s    r(   r   zReferenceEvaluator.opsetsl  s   € ð Œ|Ðr+   c                ó>   — t          d„ | j        D ¦   «         ¦  «        S )z{Checks if the graph has a linked attribute (= an attribute whose value is defined
        by a function attribute.
        c              3  ó$   K  — | ]}|j         V — Œd S ©N)Úhas_linked_attribute)r&   rd   s     r(   ú	<genexpr>z:ReferenceEvaluator.has_linked_attribute.<locals>.<genexpr>v  s%   è è € ÐHÐH°�4Ô,ÐHÐHÐHÐHÐHÐHr+   )ÚanyÚ	rt_nodes_r¤   s    r(   r²   z'ReferenceEvaluator.has_linked_attributeq  s#   € õ
 ÐHÐH¸¼ÐHÑHÔHÑHÔHÐHr+   c                óŠ   — | j         j        › dd                     | j        ¦  «        › dd                     | j        ¦  «        › �S )Nú(r…   z) -> )rh   rn   r•   r¥   rª   r¤   s    r(   Ú__str__zReferenceEvaluator.__str__x  sB   € Ø”.Ô)ÐlÐl¨D¯IªI°dÔ6FÑ,GÔ,GÐlÐlÈdÏiÊiÐX\ÔXiÑNjÔNjÐlÐlÐlr+   Tr1   Úexcc                óº   — | j         €t          d|›d�¦  «        ‚|| j         vr,|r(t          d|›dt          | j         ¦  «        › d�¦  «        ‚d S | j         |         S )NzUnable to return type for name z. Run shape_inference first.z, it was not found in ú.)rg   r~   Úsorted)rp   r1   r¹   s      r(   Úget_result_typesz#ReferenceEvaluator.get_result_types{  sŠ   € ØŒ?Ð"ÝØV°$ÐVÐVÐVñô ð ð �t”Ð&Ð&Øð Ý"Øn°dÐnÐnÕTZÐ[_Ô[jÑTkÔTkÐnÐnÐnñô ð ð �4ØŒ˜tÔ$Ð$r+   c                óˆ  ‡ — i ‰ _         g ‰ _        ‰ j        D ]b}t          j                             |¦  «        r‰                      |¦  «        nt          j                             |¦  «        ‰ j         |j	        <   Œcˆ fd„‰ j
        ‰ j        ‰ j        ‰ j                             ¦   «         ‰ j        dœ}‰ j        �Zd„ ‰ j        j        D ¦   «         }‰ j        j        D ]}|j        ||j	        <   Œ‰ j        j        D ]}|j        ||j	        <   Œ|‰ _        n=t-          ‰ j        t0          ¦  «        rd„ ‰ j        j        D ¦   «         ‰ _        nd‰ _        ‰ j        D ]ë}	 ‰                      |¦  «        }n~# t6          j        $ rl}‰ j        r5ˆ fd„|j        D ¦   «         }	d|	v r‰ dœd„}n=‰                      ||	¦  «        }n&t7          j        d	|j        ›d
|j        ›d�¦  «        |‚Y d}~nd}~ww xY w	  |||¦  «        }
n,# t>          $ r}t?          d|›d|› d|› d�¦  «        |‚d}~ww xY w‰ j                              |
¦  «         ŒìdS )z5Loads the implementation for every node in the graph.c                ó"   •—  ‰j         d| g|¢R Ž S )Né
   )r¢   )rš   r›   rp   s     €r(   ú<lambda>z*ReferenceEvaluator._init.<locals>.<lambda>“  s   ø€ ¨)¨$¬)°B¸Ð*GÀ$Ð*GÐ*GÐ*G€ r+   )Úlogr   r   r   Úexisting_functionsÚevaluator_clsNc                ó(   — i | ]}|j         |j        “ŒS r!   r>   r2   s     r(   r)   z,ReferenceEvaluator._init.<locals>.<dictcomp>›  r?   r+   c                ó(   — i | ]}|j         |j        “ŒS r!   r>   )r&   rs   s     r(   r)   z,ReferenceEvaluator._init.<locals>.<dictcomp>©  s.   € ð ð ð àð ” ¤ðð ð r+   c                ó>   •— g | ]}‰                      |d ¬¦  «        ‘ŒS )F)r¹   )r½   )r&   r3   rp   s     €r(   r4   z,ReferenceEvaluator._init.<locals>.<listcomp>·  s,   ø€ ÐRÐRÐRÀ!˜$×/Ò/°°uÐ/Ñ=Ô=ÐRÐRÐRr+   )Úparentc                ó$   — t          j        |d| iŽS )NrÈ   )r   ÚOpFunctionContextDependant)rÈ   r›   s     r(   ru   z$ReferenceEvaluator._init.<locals>.clº  s"   € Ý#)Ô#DØ!%ð$Ø.4ð$ð $ð r+   z*No implementation was found for node type ú from domain z~. If this node has a context dependent implementation, you should run function infer_shapes before calling ReferenceEvaluator.zUnable to instantiate class z with run_params=z
 and node=r»   )!Ú	rt_inits_rµ   rc   rF   rz   Úuses_external_datar€   Únumpy_helperÚto_arrayr1   r   r   rj   rP   Úcopyrh   rS   r]   r@   r8   r_   rg   rE   rO   r   re   Ú
_load_implr   ÚRuntimeContextErrorÚop_typer#   rX   r‰   )rp   ÚinitÚ
run_paramsrr   rs   r_   rd   ru   ÚeÚitÚinsts   `          r(   ro   zReferenceEvaluator._initˆ  s  ø€ àˆŒØˆŒØ”Kð 	ð 	ˆDõ Ô,×?Ò?ÀÑEÔEð6�×+Ò+¨DÑ1Ô1Ð1åÔ&×/Ò/°Ñ5Ô5ð ŒN˜4œ9Ñ%Ð%ð HÐGÐGÐGØ”kØ”|Ø”}Ø"&¤/×"6Ò"6Ñ"8Ô"8Ø!œ^ð
ð 
ˆ
ð ÔÐ'ØHÐH°Ô1AÔ1GÐHÑHÔHˆIð #Ô.Ô9ð =ð =�
Ø-7¬_�	˜*œ/Ñ*Ð*ØÔ*Ô1ð 5ð 5�Ø)/¬�	˜&œ+Ñ&Ð&Ø'ˆDŒOˆOÝ˜œ¥]Ñ3Ô3ð 
	#ð
ð à"&¤+Ô"8ðñ ô ˆDŒOˆOð
 #ˆDŒOà”Kð 	(ð 	(ˆDðØ—_’_ TÑ*Ô*��øÝÔ-ð ð ð ð ”?ð ØRÐRÐRÐRÀtÄzÐRÑRÔR�BØ˜r�z�zà-1ð ð ð ð ð ð ð
 "Ÿ_š_¨T°2Ñ6Ô6˜˜å Ô4ð>ÀTÄ\ð >ð >ÐbfÔbmð >ð >ð >ñô ð ð	øøøøøøøøøðøøøð&Ø�r˜$ 
Ñ+Ô+��øÝð ð ð Ýð@°2ð @ð @Ø",ð@ð @Ø8<ð@ð @ð @ñô ð ðøøøøðøøøð
 ŒN×!Ò! $Ñ'Ô'Ð'Ð'ð;	(ð 	(s1   ÅE/Å/G*Å>A"G%Ç%G*Ç.G;Ç;
H$ÈHÈH$rd   r	   r¨   úTypeProto | Nonec           
     óR  — |j         | j        vr(t          d|j         ›d|j        ›d| j        ›d�¦  «        ‚| j        |j                  }|j         |j        f}d}|| j        v r+| j        |         }t          |t          j        ¦  «        s|S d}|j         dk    r_dd	lm	} 	  ||j         |j        ||| j
        ¬
¦  «        S # t          j        $ r' |€‚  ||j         |j        ||||| j
        ¬¦  «        cY S w xY w|r t          d|j         › d|j        › d�¦  «        ‚|j         dk    rdd	lm	}  ||j         |j        |¦  «        S |j         dk    rdd	lm	}  ||j         |j        |¦  «        S |j         dk    rdd	lm	}	  |	|j         |j        |¦  «        S |j         dk    rdd	lm	}
  |
|j         |j        |¦  «        S || j        v r2dd	lm	} | j        |         } ||j         |j        ||| j
        ¬¦  «        S t          d|j        ›d|j         ›dt%          | j        ¦  «        › d�¦  «        ‚)z1Loads the implementation for a specified runtime.zDomain z (node type: z") is not specified. Known opsets: r»   FTr-   r   )Úload_op)ÚexpandrÄ   N)rd   r¨   rÜ   rÄ   zkExpanding an operator with its function definition is only implemented for the main opset. Remove operator rˆ   z# from the list of inlined operator.zai.onnx.previewzai.onnx.preview.trainingÚexperimentalz
ai.onnx.ml)ÚcustomrÄ   z
Node type rË   z is unknown, known functions: )r#   r   r~   rÓ   rj   rl   r   ÚOpRunExpandÚonnx.reference.opsrÛ   rh   rÒ   ÚNotImplementedErrorÚ!onnx.reference.ops.aionnx_previewÚ*onnx.reference.ops.aionnx_preview_trainingÚonnx.reference.ops.experimentalÚonnx.reference.ops.aionnxmlrP   r¼   )rp   rd   r¨   r$   rv   rÜ   ru   rÛ   Ú
load_op_ptÚload_op_expÚ
load_op_mlÚimpls               r(   rÑ   zReferenceEvaluator._load_implÏ  sŽ  € ð Œ;˜dœkÐ)Ð)ÝðD˜$œ+ð Dð D°d´lð Dð DØ37´;ðDð Dð Dñô ð ð ”+˜dœkÔ*ˆØŒk˜4œ<Ð'ˆØˆØ�$”-ÐÐð ”˜sÔ#ˆBÝ˜b¥&Ô"4Ñ5Ô5ð Ø�	àˆFàŒ;˜"ÒÐØ2Ð2Ð2Ð2Ð2Ð2ðØ�wØ”KØ”LØØ!Ø"&¤.ðñ ô ð øõ Ô-ð ð ð ØÐ&ØØ�wØ”KØ”LØØØ +Ø!Ø"&¤.ðñ ô ð ð ð ðøøøð ð 	Ý%ðSà”;ðSð Sà!%¤ðSð Sð Sñô ð ð
 Œ;Ð+Ò+Ð+ðð ð ð ð ð ð �:˜dœk¨4¬<¸ÑAÔAÐAàŒ;Ð4Ò4Ð4ðð ð ð ð ð ð �:˜dœk¨4¬<¸ÑAÔAÐAàŒ;˜.Ò(Ð(ðð ð ð ð ð ð �;˜tœ{¨D¬L¸'ÑBÔBÐBàŒ;˜,Ò&Ð&ðð ð ð ð ð ð �:˜dœk¨4¬<¸ÑAÔAÐAð �$”/Ð!Ð!Ø2Ð2Ð2Ð2Ð2Ð2à”? 3Ô'ˆDØ�7Ø”Ø”ØØØ"œnðñ ô ð õ "ðG˜œð Gð G°d´kð Gð GÝ,2°4´?Ñ,CÔ,CðGð Gð Gñ
ô 
ð 	
s   ÂB> Â>3C4Ã3C4Úfeed_inputsúdict[str, Any]Ú
attributesúdict[str, Any] | NoneÚintermediateúbool | NoneÚ	_bindingsúSymbolBindings | Noneúdict[str, Any] | list[Any]c                óÌ  ‡— |€| j         }t          | j        t          ¦  «        r	|€t          ‚|€| j        n|}|�|}n|rt          ¦   «         nd}ddiŠ‰                     | j        ¦  «         ‰                     |¦  «         | j         	                    ¦   «         D ]\  }	}
|  
                    dd|	|
¦  «         Œ| 	                    ¦   «         D ]\  }	}
|  
                    dd|	|
¦  «         Œ|�G| j        r@‰ 	                    ¦   «         D ]+\  }}|| j        v rt          | j        |         |||¦  «         Œ,| j        D �]o}|  
                    dd|j        |j        |j        ¦  «         |j        D ]N}|‰vrHt#          d|›d	t%          ‰¦  «        › d
t%          | j        ¦  «        › dt%          |¦  «        › d�	¦  «        ‚ŒOˆfd„|j        D ¦   «         }i }|j        r|r||d<   |                     ¦   «         r |j        |‰|dœ|¤Ž}n9|�*t          |t,          j        ¦  «        r |j        |d|i|¤Ž}n |j        |i |¤Ž}t1          |j        |d¬¦  «        D ]U\  }}|  
                    dd||¦  «         |‰|<   |�1| j        r*t          | j                             |¦  «        |||¦  «         ŒV�Œq|�r| j        r)t7          t1          | j        | j        d¬¦  «        ¦  «        n| j        }|r9| j        D ]1}|‰v r+t          |                     |¦  «        ‰|         ||¦  «         Œ2|r‰S |D ]0}|‰vr*t#          d|›dt%          ‰¦  «        › d| j        › �¦  «        ‚Œ1ˆfd„|D ¦   «         S )a%  Executes the onnx model.

        Args:
            output_names: requested outputs by names, None for all
            feed_inputs: dictionary `{ input name: input value }`
            attributes: attributes value if the instance runs a
                FunctionProto
            intermediate: if True, the function returns all the results,
                final ones and intermediates one in a same dictionary,
                if False, only the final results are returned in a list
            check_shape_annotations: overrides, for this call only, the
                `check_shape_annotations` constructor argument; if None
                (the default), the constructor's setting is used
            _bindings: internal parameter used to propagate the active
                `SymbolBindings` instance into a nested evaluator run
                (subgraph body of If/Loop/Scan, or a function body), so
                that a symbolic dimension shared with the caller is
                checked against the same bindings (single global
                namespace, see docs/ShapeAnnotationSemantics.md). Not
                meant to be supplied directly by external callers.

        Returns:
            list of requested outputs if intermediate is False,
            named results in a dictionary otherwise
        Nr-   é   z
 +C %s: %sz
 +I %s: %sr.   z%s(%s) -> %szUnable to find input z in known results z, self.rt_inits_ has z, feed_inputs has r»   c                ó    •— g | ]
}‰|         ‘ŒS r!   r!   )r&   r3   Úresultss     €r(   r4   z*ReferenceEvaluator.run.<locals>.<listcomp>†  s   ø€ Ð5Ð5Ð5 Q�g˜a”jÐ5Ð5Ð5r+   Úlinked_attributes)ÚcontextÚbindingsrù   F)Ústrictz	 + %s: %szUnable to find output name z in z, proto is
c                ó    •— g | ]
}‰|         ‘ŒS r!   r!   )r&   r1   rö   s     €r(   r4   z*ReferenceEvaluator.run.<locals>.<listcomp>»  s   ø€ Ð7Ð7Ð7 $�˜”Ð7Ð7Ð7r+   )rª   rE   rO   r   rX   rB   r   ÚupdaterÌ   Úitemsr¢   rg   r   rµ   rÓ   r]   r_   r~   r¼   r²   Úneed_contextÚrunr   Ú
OpFunctionÚzipÚgetrC   rW   r`   )rp   rª   rê   rì   rî   r   rð   Údo_check_shapesrù   ÚkÚvr1   Úvaluerd   r3   Úinputsr÷   Úoutputsr­   rö   s                      @r(   rÿ   zReferenceEvaluator.run0  s£  ø€ ðD ÐØÔ,ˆLÝ�d”k¥=Ñ1Ô1ð 	°jÐ6HÝˆOð 'Ð.ð Ô)Ð)à(ð 	ð Ð Ø ˆHˆHà+:ÐD•~Ñ'Ô'Ð'ÀˆHð �t�*ˆØ�Š�t”~Ñ&Ô&Ð&Ø�Š�{Ñ#Ô#Ð#Ø”N×(Ò(Ñ*Ô*ð 	-ð 	-‰DˆAˆqØ�IŠI�a˜ q¨!Ñ,Ô,Ð,Ð,Ø×%Ò%Ñ'Ô'ð 	-ð 	-‰DˆAˆqØ�IŠI�a˜ q¨!Ñ,Ô,Ð,Ð,àÐð Œð Ø#*§=¢=¡?¤?ð ð ‘K�D˜%Ø˜tœÐ.Ð.Ý0Ø œO¨DÔ1°5¸(ÀDñô ð øð
 ”Nð "	ñ "	ˆDØ�IŠI�a˜¨¬°t´zÀ4Ä;ÑOÔOÐOØ”Zð ð �Ø˜GÐ#Ð#Ý&ðB°ð Bð BÅvÈgÁÄð Bð BÝ.4°T´^Ñ.DÔ.DðBð Bå+1°+Ñ+>Ô+>ðBð Bð Bñô ð ð $ð 6Ð5Ð5Ð5¨$¬*Ð5Ñ5Ô5ˆFØ "ÐØÔ(ð D¨Zð DØ9CÐ!Ð"5Ñ6Ø× Ò Ñ"Ô"ð AØ"˜$œ(Ø W°xðð ØCTðð ��ð Ð%­*°T½6Ô;LÑ*MÔ*MÐ%ð #˜$œ( FÐS°XÐSÐARÐSÐS��à"˜$œ( FÐ@Ð.?Ð@Ð@�Ý" 4¤;°ÀÐFÑFÔFð ð ‘��eØ—	’	˜!˜[¨$°Ñ6Ô6Ð6Ø %�˜‘ØÐ'¨D¬OÐ'Ý,Øœ×+Ò+¨DÑ1Ô1°5¸(ÀDñô ð øñ	ð Ðð Ô%ð%••S˜Ô+¨TÔ-?ÈÐNÑNÔNÑOÔOÐOà”_ð ð
 ð Ø Ô.ð ð �DØ˜w��Ý0Ø(×,Ò,¨TÑ2Ô2°G¸D´MÀ8ÈTñô ð øð
 ð 	ØˆNà ð 	ð 	ˆDØ˜7Ð"Ð"Ý"Øh°$ÐhÐh½fÀW¹o¼oÐhÐhÐ[_Ô[fÐhÐhñô ð ð #ð 8Ð7Ð7Ð7¨,Ð7Ñ7Ô7Ð7r+   )NNr   NF)r   r   r   r   r   r   r   r   r   r   r   r   r   r   )ra   r
   r   rx   )r�   r   r   r   )r™   r   rš   rK   r›   rœ   r   r   )r   rK   )T)r1   rK   r¹   r   r   r   )r   r   r±   )rd   r	   r¨   rÙ   r   r   )NFNN)rê   rë   rì   rí   rî   r   r   rï   rð   rñ   r   rò   )rn   Ú
__module__Ú__qualname__Ú__doc__rw   r€   r—   r¢   Úpropertyr¥   r¨   rª   r­   r   r²   r¸   r½   ro   rÑ   rÿ   r!   r+   r(   r   r      sÐ  € € € € € ðhð hðZ )-ØEIØØ37Ø(-ðgð gð gð gð gðR
ð 
ð 
ð 
ð$ð ð ð ð"-ð -ð -ð -ð
 ð!ð !ñ „Xð!ð ð!ð !ñ „Xð!ð ð"ð "ñ „Xð"ð ð"ð "ñ „Xð"ð ðð ñ „Xðð ðIð Iñ „XðIðmð mð mð mð%ð %ð %ð %ð %ðE(ð E(ð E(ð E(ðP @Dð_
ð _
ð _
ð _
ð _
ðJ -1Ø"Ø/3Ø+/ðK8ð K8ð K8ð K8ð K8ð K8ð K8r+   r   )Ú
__future__r   Úior   Útypingr   Únumpyr‹   rF   Úonnx.model_containerÚonnx.onnx_pbr   r   r   r	   r
   r   Úonnx.referencer   Ú'onnx.reference.shape_annotation_checkerr   r   r   r!   r+   r(   ú<module>r     s&  ðð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à Ð Ð Ð à €€€Ø Ð Ð Ð ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð "Ð !Ð !Ð !Ð !Ð !ðð ð ð ð ð ð ð ð_
8ð _
8ð _
8ð _
8ð _
8ñ _
8ô _
8ð _
8ð _
8ð _
8r+   