o
    Uôj”  ã                   @  s¦   d Z ddlmZ ddlZddlmZ ddlZddlm  m	Z
 ddlmZmZmZmZ 			d0d1dd„Z				d2d3dd„Zdddejfd4d&d'„Zd5d.d/„Ze
jZdS )6zIonnx 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                 C  sb   t | ttfƒrt | tƒr| n|  ¡ }t ||||¡}t |¡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_strZinferred_model_str© r   úg/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/onnx/shape_inference.pyr      s   ÿ

ÿÿr   Ú Ú
model_pathústr | os.PathLikeÚoutput_pathÚNonec              
   C  s¬   t | tƒr	tdƒ‚zt | ¡} W n ty& } z
tdt| ƒ› �ƒ|‚d}~ww zt |¡}W n tyD } z
tdt|ƒ› �ƒ|‚d}~ww |dkrK| }t | ||||¡ 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   ÚosÚfspathr   r   Úinfer_shapes_path)r   r   r
   r   r   Úexpr   r   r   r#   =   s>   
ÿÿÿý€ÿÿÿý€ÿr#   Ú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                   sÆ   | j si S ˆ d u ri ‰ ˆd u ri ‰|d u ri }ndd„ |D ƒ}‡fdd„|jD ƒ}ˆD ]}	|	|vr9ˆ|	  ¡ ||	< q+‡ fdd„|jD ƒ}
‡fdd„|jD ƒ}|  | ¡ ||
|||¡}dd„ | ¡ D ƒS )Nc                 S  s   i | ]}|j |j“qS r   )ÚdomainÚversion)Ú.0Úopsetr   r   r   Ú
<dictcomp>u   s    z&infer_node_outputs.<locals>.<dictcomp>c                   s   i | ]	}|ˆ |   ¡ “qS r   ©r   ©r5   Úkey)r)   r   r   r7   x   s    ÿc                   ó"   i | ]}|ˆ v r|ˆ |   ¡ “qS r   r8   r9   )r+   r   r   r7      ó
    þc                   r;   r   r8   r9   )r-   r   r   r7   „   r<   c                 S  s   i | ]\}}|t j |¡“qS r   )r   r   Ú
FromString)r5   r:   Úoutr   r   r   r7   ’   s    )Ú%has_type_and_shape_inference_functionÚinputr   Ú_infer_node_outputsÚitems)r%   r'   r)   r+   r-   r/   r1   Zpassed_opset_importsZpassed_input_typesr:   Zpassed_input_dataZpassed_sparse_input_dataÚoutputsr   )r+   r-   r)   r   Úinfer_node_outputsc   s>   	
ÿ€
þ
þúrD   Úfunctionr   úSequence[TypeProto]Ú
attributesúSequence[AttributeProto]úlist[TypeProto]c                   sB   t  |  ¡ dd„ |D ƒdd„ |D ƒ¡}d
dd„‰ ‡ fdd„|D ƒS )zxApply type-and-shape-inference to given function body, with given input types
    and given input attribute values.
    c                 S  ó   g | ]}|  ¡ ‘qS r   r8   ©r5   Úxr   r   r   Ú
<listcomp>Ÿ   ó    z/infer_function_output_types.<locals>.<listcomp>c                 S  rJ   r   r8   rK   r   r   r   rM       rN   r   r   c                 S  s   t  ¡ }| | ¡ |S )N)r   r   ÚParseFromString)rL   Z
type_protor   r   r   Úto_type_proto£   s   
z2infer_function_output_types.<locals>.to_type_protoc                   s   g | ]}ˆ |ƒ‘qS r   r   rK   ©rP   r   r   rM   ¨   rN   N)r   r   )r   Úinfer_function_output_typesr   )rE   r)   rG   Úresultr   rQ   r   rR   •   s   ý
rR   )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+   r,   r-   r.   r/   r0   r1   r2   r   r*   )rE   r   r)   rF   rG   rH   r   rI   )Ú__doc__Ú
__future__r   r!   Útypingr   r   Z'onnx.onnx_cpp2py_export.shape_inferenceÚonnx_cpp2py_exportÚshape_inferencer   r   r   r   r   r   r#   Ú
IR_VERSIONrD   rR   ÚInferenceErrorr   r   r   r   Ú<module>   s.   ü+û*ù
2
