
    
Ng                        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 	 	 	 d,d-dZ	 	 	 	 d.d/dZdddej        fd0d$Zd1d+Ze
j        ZdS )2zIonnx shape inference. Shape inference is not guaranteed to be
complete.

    )annotationsN)Sequence)AttributeProtoFunctionProto
ModelProto	TypeProtoFmodelModelProto | bytes
check_typeboolstrict_mode	data_propreturnr   c                l   t          | t          t          f          rVt          | t                    r| n|                                 }t	          j        ||||          }t          j        |          S t          | t                    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
    zhinfer_shapes only accepts ModelProto or bytes,you can use infer_shapes_path for the model path (String).z?infer_shapes only accepts ModelProto or bytes, incorrect type: )
isinstancer   bytesSerializeToStringCinfer_shapesonnxload_from_stringstr	TypeErrortype)r	   r   r   r   	model_strinferred_model_strs         P/var/www/html/ai-engine/env/lib/python3.11/site-packages/onnx/shape_inference.pyr   r      s    0 %*e,-- 9'u55TEE5;R;R;T;T	^z;	
 
 $%7888% 
I
 
 	

 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 )zTake 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   osfspathr   r   infer_shapes_path)r    r"   r   r   r   exps         r   r'   r'   =   s*    *j)) 
;
 
 	
Yz**

   =*.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                   | j         si S 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>u   s    WWWemWWWr   c                F    i | ]}||                                          S r9   r   )r<   keyr-   s     r   r>   z&infer_node_outputs.<locals>.<dictcomp>x   s9       69[//11  r   c                N    i | ]!}|v ||                                          "S r9   r@   )r<   rA   r/   s     r   r>   z&infer_node_outputs.<locals>.<dictcomp>   s@       * 	Z_..00r   c                N    i | ]!}|v ||                                          "S r9   r@   )r<   rA   r1   s     r   r>   z&infer_node_outputs.<locals>.<dictcomp>   sC          ### 	s#5577###r   c                T    i | ]%\  }}|t           j                            |          &S r9   )r   r   
FromString)r<   rA   outs      r   r>   z&infer_node_outputs.<locals>.<dictcomp>   s.    PPPHCC**3//PPPr   )%has_type_and_shape_inference_functioninputr   _infer_node_outputsitems)r)   r+   r-   r/   r1   r3   r5   passed_opset_importspassed_input_typesrA   passed_input_datapassed_sparse_input_dataoutputss     ```        r   infer_node_outputsrP   c   sb    7 	
 !WWWWW   =AZ    K K(((&1#&6&H&H&J&J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 r9   r@   r<   xs     r   
<listcomp>z/infer_function_output_types.<locals>.<listcomp>   s$    4441				444r   c                6    g | ]}|                                 S r9   r@   rX   s     r   rZ   z/infer_function_output_types.<locals>.<listcomp>   s$    3331				333r   r   r   c                V    t          j                    }|                    |            |S )N)r   r   ParseFromString)rY   
type_protos     r   to_type_protoz2infer_function_output_types.<locals>.to_type_proto   s)    ^%%
""1%%%r   c                &    g | ]} |          S r9   r9   )r<   rY   r_   s     r   rZ   z/infer_function_output_types.<locals>.<listcomp>   s#    ---MM!---r   )r   r   )r   infer_function_output_typesr   )rQ   r-   rS   resultr_   s       @r   ra   ra      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,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r   r.   )rQ   r   r-   rR   rS   rT   r   rU   )__doc__
__future__r   r%   typingr   r   'onnx.onnx_cpp2py_export.shape_inferenceonnx_cpp2py_exportshape_inferencer   r   r   r   r   r   r'   
IR_VERSIONrP   ra   InferenceErrorr9   r   r   <module>rk      s)  
 
 # " " " " " 				        3 3 3 3 3 3 3 3 3 E E E E E E E E E E E E
 	& & & & &V &(#U #U #U #U #UT 6:BF:>o/Q /Q /Q /Q /Qd. . . ., !r   