§
    1�ÅjÇ  ã                  óÖ   — d Z ddlmZ ddlZddlmZ ddlZddlmc m	Z
 ddlmZmZmZmZmZ erddlmZ e
j        Ze
j        Z	 	 	 d-d.d„Z	 	 	 	 d/d0d„Zdddefd1d%„Zd2d,„Ze
j        ZdS )3zIonnx shape inference. Shape inference is not guaranteed to be
complete.

é    )ÚannotationsN)ÚTYPE_CHECKING)Ú
IR_VERSIONÚAttributeProtoÚFunctionProtoÚ
ModelProtoÚ	TypeProto)ÚSequenceFÚmodelúModelProto | bytesÚ
check_typeÚboolÚstrict_modeÚ	data_propÚreturnr   c                ó„  — t          | t          t          f¦  «        rVt          | t          ¦  «        r| n|                      ¦   «         }t	          j        ||||¦  «        }t          j        |¦  «        S t          | t          t          j
        f¦  «        rt          d¦  «        ‚t          dt          | ¦  «        › �¦  «        ‚)aÞ  Apply shape inference to the provided ModelProto.

    Inferred shapes are added to the value_info field of the graph.

    If the inferred values conflict with values already provided in the
    graph, that means that the provided values are invalid (or there is a
    bug in shape inference), and the result is unspecified.

    Arguments:
        model: ModelProto.
        check_type: Checks the type-equality for input and output.
        strict_mode: Stricter shape inference, it will throw errors if any;
            Otherwise, simply stop if any error.
        data_prop: Enables data propagation for limited operators to perform shape computation.

    Returns:
        (ModelProto) model with inferred shape information
    zminfer_shapes only accepts ModelProto or bytes, For Model paths (str or os.PathLike), use infer_shapes_path().z?infer_shapes only accepts ModelProto or bytes, incorrect type: )Ú
isinstancer   ÚbytesÚSerializeToStringÚCÚinfer_shapesÚonnxÚload_from_stringÚstrÚosÚPathLikeÚ	TypeErrorÚtype)r   r   r   r   Ú	model_strÚinferred_model_strs         úEC:\Projects\Historical\venv\Lib\site-packages\onnx/shape_inference.pyr   r       sÄ   € õ0 �%�*¥eÐ,Ñ-Ô-ð 9Ý'¨­uÑ5Ô5ÐT�E�E¸5×;RÒ;RÑ;TÔ;Tˆ	Ýœ^Ø�z ;°	ñ
ô 
Ðõ Ô$Ð%7Ñ8Ô8Ð8Ý�%�#�rœ{Ð+Ñ,Ô,ð 
ÝðNñ
ô 
ð 	
õ
 ØWÍ$ÈuÉ+Ì+ÐWÐWñô ð ó    Ú Ú
model_pathústr | os.PathLikeÚoutput_pathÚNonec                ó®  — t          | t          ¦  «        rt          d¦  «        ‚	 t          j        | ¦  «        } n2# t          $ r%}t          dt          | ¦  «        › �¦  «        |‚d}~ww xY w	 t          j        |¦  «        }n2# t          $ r%}t          dt          |¦  «        › �¦  «        |‚d}~ww xY w|dk    r| }t          j        | ||||¦  «         dS )zñTake model path for shape_inference.

    This function is the same as :func:`infer_shape` but supports >2GB models.
    The function outputs the inferred model to the `output_path`. The original model path
    is used if not specified.
    z_infer_shapes_path only accepts model Path (String),you can use infer_shapes for the ModelProto.z^infer_shapes_path only accepts model path as a string or PathLike, incorrect model path type: Nz`infer_shapes_path only accepts output path as a string or PathLike, incorrect output path type: r#   )r   r   r   r   Úfspathr   r   Úinfer_shapes_path)r$   r&   r   r   r   Úexps         r!   r*   r*   I   s*  € õ �*�jÑ)Ô)ð 
Ýð;ñ
ô 
ð 	
ðÝ”Y˜zÑ*Ô*ˆ
ˆ
øÝð ð ð Ýð=Ý*.¨zÑ*:Ô*:ð=ð =ñ
ô 
ð ð	øøøøðøøøð
Ý”i Ñ,Ô,ˆˆøÝð ð ð Ýð?Ý+/°Ñ+<Ô+<ð?ð ?ñ
ô 
ð ð	øøøøðøøøð �bÒÐØ ˆÝÔ˜
 K°¸[È)ÑTÔTÐTÐTÐTs-   ¦; »
A*Á A%Á%A*Á.B Â
B2Â B-Â-B2Úschemaúonnx.defs.OpSchemaÚnodeúonnx.NodeProtoÚinput_typesúdict[str, onnx.TypeProto]Ú
input_dataú"dict[str, onnx.TensorProto] | NoneÚinput_sparse_dataú(dict[str, onnx.SparseTensorProto] | NoneÚopset_importsú$list[onnx.OperatorSetIdProto] | NoneÚ
ir_versionÚintc                óª  ‡‡‡— ‰€i Š‰€i Š|€i }nd„ |D ¦   «         }ˆfd„|j         D ¦   «         }‰                     ¦   «         D ] \  }	}
|	|vr|
                     ¦   «         ||	<   Œ!ˆfd„|j         D ¦   «         }ˆfd„|j         D ¦   «         }|                      |                     ¦   «         |||||¦  «        }d„ |                     ¦   «         D ¦   «         S )Nc                ó(   — i | ]}|j         |j        “ŒS © )ÚdomainÚversion)Ú.0Úopsets     r!   ú
<dictcomp>z&infer_node_outputs.<locals>.<dictcomp>   s   € ÐWÐWÐWÀ ¤¨e¬mÐWÐWÐWr"   c                óR   •— i | ]#}|d k    ¯|‰|                               ¦   «         “Œ$S )r#   ©r   )r?   Úkeyr0   s     €r!   rA   z&infer_node_outputs.<locals>.<dictcomp>‚   s9   ø€ ð ð ð Ø69È3ÐRTÊ9È9ˆˆ[˜Ô×/Ò/Ñ1Ô1È9È9È9r"   c                óN   •— i | ]!}|‰v ¯|‰|                               ¦   «         “Œ"S r<   rC   )r?   rD   r2   s     €r!   rA   z&infer_node_outputs.<locals>.<dictcomp>‰   s@   ø€ ð ð ð àØ�*ÐÐð 	ˆZ˜Œ_×.Ò.Ñ0Ô0àÐÐr"   c                óN   •— i | ]!}|‰v ¯|‰|                               ¦   «         “Œ"S r<   rC   )r?   rD   r4   s     €r!   rA   z&infer_node_outputs.<locals>.<dictcomp>Ž   sC   ø€ ð  ð  ð  àØÐ#Ð#Ð#ð 	Ð˜sÔ#×5Ò5Ñ7Ô7à#Ð#Ð#r"   c                óT   — i | ]%\  }}|t           j                             |¦  «        “Œ&S r<   )r   r	   Ú
FromString)r?   rD   Úouts      r!   rA   z&infer_node_outputs.<locals>.<dictcomp>œ   s.   € ÐPÐPÐP±H°C¸ˆC•”×*Ò*¨3Ñ/Ô/ÐPÐPÐPr"   )ÚinputÚitemsr   Ú_infer_node_outputs)r,   r.   r0   r2   r4   r6   r8   Úpassed_opset_importsÚpassed_input_typesrD   ÚvalueÚpassed_input_dataÚpassed_sparse_input_dataÚoutputss     ```         r!   Úinfer_node_outputsrS   o   s]  øøø€ ð ÐØˆ
ØÐ ØÐØÐØ!ÐÐàWÐWÈÐWÑWÔWÐðð ð ð Ø=A¼Zðñ ô Ðð "×'Ò'Ñ)Ô)ð @ð @‰
ˆˆUØÐ(Ð(Ð(Ø&+×&=Ò&=Ñ&?Ô&?Ð˜sÑ#øðð ð ð à”:ðñ ô Ðð
 ð  ð  ð  à”:ð ñ  ô  Ðð ×(Ò(Ø×ÒÑ Ô ØØØ ØØñô €Gð QÐPÀÇÂÁÄÐPÑPÔPÐPr"   Úfunctionr   úSequence[TypeProto]Ú
attributesúSequence[AttributeProto]úlist[TypeProto]c                ó    ‡— t          j        |                      ¦   «         d„ |D ¦   «         d„ |D ¦   «         ¦  «        }dd„Šˆfd„|D ¦   «         S )zxApply type-and-shape-inference to given function body, with given input types
    and given input attribute values.
    c                ó6   — g | ]}|                      ¦   «         ‘ŒS r<   rC   ©r?   Úxs     r!   ú
<listcomp>z/infer_function_output_types.<locals>.<listcomp>©   s$   € Ð4Ð4Ð4 1ˆ×	Ò	Ñ	Ô	Ð4Ð4Ð4r"   c                ó6   — g | ]}|                      ¦   «         ‘ŒS r<   rC   r[   s     r!   r]   z/infer_function_output_types.<locals>.<listcomp>ª   s$   € Ð3Ð3Ð3 1ˆ×	Ò	Ñ	Ô	Ð3Ð3Ð3r"   r   r	   c                óV   — t          j        ¦   «         }|                     | ¦  «         |S )N)r   r	   ÚParseFromString)r\   Ú
type_protos     r!   Úto_type_protoz2infer_function_output_types.<locals>.to_type_proto­   s)   € Ý”^Ñ%Ô%ˆ
Ø×"Ò" 1Ñ%Ô%Ð%ØÐr"   c                ó&   •— g | ]} ‰|¦  «        ‘ŒS r<   r<   )r?   r\   rb   s     €r!   r]   z/infer_function_output_types.<locals>.<listcomp>²   s#   ø€ Ð-Ð-Ð- ˆMˆM˜!ÑÔÐ-Ð-Ð-r"   )r   r	   )r   Úinfer_function_output_typesr   )rT   r0   rV   Úresultrb   s       @r!   rd   rd   Ÿ   sx   ø€ õ Ô*Ø×"Ò"Ñ$Ô$Ø4Ð4¨Ð4Ñ4Ô4Ø3Ð3¨
Ð3Ñ3Ô3ñô €Fðð ð ð ð
 .Ð-Ð-Ð- fÐ-Ñ-Ô-Ð-r"   )FFF)
r   r   r   r   r   r   r   r   r   r   )r#   FFF)r$   r%   r&   r%   r   r   r   r   r   r   r   r'   )r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r   r1   )rT   r   r0   rU   rV   rW   r   rX   )Ú__doc__Ú
__future__r   r   Útypingr   r   Ú'onnx.onnx_cpp2py_export.shape_inferenceÚonnx_cpp2py_exportÚshape_inferencer   Úonnx.onnx_pbr   r   r   r   r	   Úcollections.abcr
   ÚGraphInferencerÚInferenceContextr   r*   rS   rd   ÚInferenceErrorr<   r"   r!   ú<module>rq      sv  ðð
ð ð
 #Ð "Ð "Ð "Ð "Ð "à 	€	€	€	Ø  Ð  Ð  Ð  Ð  Ð  à €€€Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð )Ø(Ð(Ð(Ð(Ð(Ð(àÔ#€ØÔ%Ð ð
 ØØð	&ð &ð &ð &ð &ðV &(ØØØð#Uð #Uð #Uð #Uð #UðT 6:ØBFØ:>Ø ð-Qð -Qð -Qð -Qð -Qð`.ð .ð .ð .ð, Ô!€€€r"   