
    h                    &   S r SSKJr  SSKrSSKJr  SSKrSSKJs  J	r
  SSKJrJrJrJr     S
         SS jjr    S           SS jjrSSS\R"                  4               SS jjr        SS	 jr\
R(                  rg)zIonnx shape inference. Shape inference is not guaranteed to be
complete.

    )annotationsN)Sequence)AttributeProtoFunctionProto
ModelProto	TypeProtoc                N   [        U [        [        45      (       aT  [        U [        5      (       a  U OU R                  5       n[        R
                  " XAX#5      n[        R                  " U5      $ [        U [        5      (       a  [        S5      e[        S[        U 5       35      e)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 (Union[ModelProto, bytes], bool, bool, bool) -> ModelProto
    check_type (bool): Checks the type-equality for input and output
    strict_mode (bool): Stricter shape inference, it will throw errors if any;
        Otherwise, simply stop if any error
    data_prop (bool): 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)model
check_typestrict_mode	data_prop	model_strinferred_model_strs         N/var/www/fran/franai/venv/lib/python3.13/site-packages/onnx/shape_inference.pyr   r      s    0 %*e,--'u55E5;R;R;T	^^;
 $$%788%I
 	

 
I$u+W     c                   [        U [        5      (       a  [        S5      e [        R                  " U 5      n  [        R                  " U5      nUS:X  a  U n[        R                  " XX#U5        g! [         a  n[        S[        U 5       35      UeSnAff = f! [         a  n[        S[        U5       35      UeSnAff = f)z
Take model path for shape_inference same as infer_shape; it support >2GB models
Directly output the inferred model to the output_path; Default is the original model path
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   osfspathr   r   infer_shapes_path)
model_pathoutput_pathr   r   r   exps         r   r    r    =   s     *j));
 	
YYz*
ii, b 
)T  **.z*:);=
 	  ++/+<*=?
 	s.   A0 B 0
B:BB
C$B<<Cc                   U R                   (       d  0 $ Uc  0 nUc  0 nUc  0 nO&U Vs0 s H  oR                  UR                  _M     nnUR                   V	s0 s H  oX)   R	                  5       _M     n
n	U H  n	X;  d  M
  X)   R	                  5       X'   M      UR                   V	s0 s H  n	X;   d  M
  XU	   R	                  5       _M     nn	UR                   V	s0 s H  n	X;   d  M
  XU	   R	                  5       _M     nn	U R                  UR	                  5       U
UUUU5      nUR                  5        V	Vs0 s H%  u  pU	[        R                  R                  U5      _M'     snn	$ s  snf s  sn	f s  sn	f s  sn	f s  snn	f N)
%has_type_and_shape_inference_functiondomainversioninputr   _infer_node_outputsitemsr   r   
FromString)schemanodeinput_types
input_datainput_sparse_dataopset_imports
ir_versionpassed_opset_importsopsetkeypassed_input_typespassed_input_datapassed_sparse_input_dataoutputsouts                  r   infer_node_outputsr<   a   s    77	
 !IVWemm ;W >BZZ=Gc[//11Z   (&1&6&H&H&J# 
 ::C 	1_..00   :: C# 	8s#5577    ((  G AHPHCC**3//PP;  X
  Qs)    E)E.(	E35E3	E8)E89,E=c           	        [         R                  " U R                  5       U Vs/ s H  o3R                  5       PM     snU Vs/ s H  o3R                  5       PM     sn5      nSS jnU Vs/ s H
  o5" U5      PM     sn$ s  snf s  snf s  snf )zq
Apply type-and-shape-inference to given function body, with given input types
and given input attribute values.
c                R    [         R                  " 5       nUR                  U 5        U$ r%   )r   r   ParseFromString)x
type_protos     r   to_type_proto2infer_function_output_types.<locals>.to_type_proto   s"    ^^%
""1%r   )returnr   )r   infer_function_output_typesr   )functionr/   
attributesr@   resultrB   s         r   rE   rE      s     **""$(341			4(23
1			
3F
 '--fM!f-- 	53 .s   B 
B,B
)FFF)
r   zModelProto | bytesr   boolr   rI   r   rI   rD   r   )r   FFF)r!   str | os.PathLiker"   rJ   r   rI   r   rI   r   rI   rD   None)r-   zonnx.defs.OpSchemar.   zonnx.NodeProtor/   dict[str, onnx.TypeProto]r0   z"dict[str, onnx.TensorProto] | Noner1   z(dict[str, onnx.SparseTensorProto] | Noner2   z$list[onnx.OperatorSetIdProto] | Noner3   intrD   rL   )rF   r   r/   zSequence[TypeProto]rG   zSequence[AttributeProto]rD   zlist[TypeProto])__doc__
__future__r   r   typingr   r   'onnx.onnx_cpp2py_export.shape_inferenceonnx_cpp2py_exportshape_inferencer   r   r   r   r   r   r    
IR_VERSIONr<   rE   InferenceError r   r   <module>rW      sZ  

 # 	   3 3 E E
 	&&& & 	&
 &V &(!U!!U"!U !U 	!U
 !U 
!UP 6:BF:>oo/Q/Q
/Q +/Q 3	/Q
 @/Q 8/Q /Q /Qd..$. ). 	.. !!r   