
    bIg                       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	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 dd	Ze
j(                  Zy)zIonnx shape inference. Shape inference is not guaranteed to be
complete.

    )annotationsN)Sequence)AttributeProtoFunctionProto
ModelProto	TypeProtoc                0   t        | t        t        f      rOt        | t              r| n| j                         }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)model
check_typestrict_mode	data_prop	model_strinferred_model_strs         Q/var/www/html/answerous/venv/lib/python3.12/site-packages/onnx/shape_inference.pyr   r      s    0 %*e,-'u5E5;R;R;T	^^z;	
 $$%788%I
 	

 
I$u+W     c                v   t        | t              rt        d      	 t        j                  |       } 	 t        j                  |      }|dk(  r| }t        j                  | ||||       y# t        $ r}t        dt        |              |d}~ww xY w# t        $ r}t        dt        |             |d}~ww xY w)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   osfspathr   r   infer_shapes_path)
model_pathoutput_pathr   r   r   exps         r   r    r    =   s     *j);
 	
YYz*
ii, b 
K[)T  **.z*:);=
 	  ++/+<*=?
 	s.   A) B )	B2B

B	B8B33B8c                   | j                   si S |i }|i }|i }n$|D ci c]  }|j                  |j                   }}|j                  D 	ci c]  }	|	dk7  s	|	||	   j	                          }
}	|D ]  }	|	|
vs||	   j	                         |
|	<    |j                  D 	ci c]  }	|	|v r|	||	   j	                          }}	|j                  D 	ci c]  }	|	|v r|	||	   j	                          }}	| j                  |j	                         |
||||      }|j                         D 	ci c]%  \  }	}|	t        j                  j                  |      ' c}}	S c c}w c c}	w c c}	w c c}	w c c}}	w )Nr   )
%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;   c   s    77	
 !IVWemm ;WW >BZZ693RT9[//11   K((&1#&6&H&H&Js#K
 ::* 	Z_..00  :: ## 	s#5577    ((  G AHPHCC**3//PP;  X
  Qs#   E
EE!E E%(*E*c           	        t        j                  | j                         |D cg c]  }|j                          c}|D cg c]  }|j                          c}      }dd}|D cg c]
  } ||       c}S c c}w c c}w c c}w )zxApply type-and-shape-inference to given function body, with given input types
    and given input attribute values.
    c                P    t        j                         }|j                  |        |S )N)r   r   ParseFromString)x
type_protos     r   to_type_protoz2infer_function_output_types.<locals>.to_type_proto   s"    ^^%
""1%r   )returnr   )r   infer_function_output_typesr   )functionr.   
attributesr?   resultrA   s         r   rC   rC      sx     **""$(341			4(231			3F
 '--M!-- 	53 .s   A8
 A=&B)FFF)
r   zModelProto | bytesr   boolr   rG   r   rG   rB   r   )r   FFF)r!   str | os.PathLiker"   rH   r   rG   r   rG   r   rG   rB   None)r,   zonnx.defs.OpSchemar-   zonnx.NodeProtor.   dict[str, onnx.TypeProto]r/   z"dict[str, onnx.TensorProto] | Noner0   z(dict[str, onnx.SparseTensorProto] | Noner1   z$list[onnx.OperatorSetIdProto] | Noner2   intrB   rJ   )rD   r   r.   zSequence[TypeProto]rE   zSequence[AttributeProto]rB   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;   rC   InferenceError r   r   <module>rU      sZ  

 # 	   3 3 E E
 	&&& & 	&
 &V &(#U!#U"#U #U 	#U
 #U 
#UT 6:BF:>oo/Q/Q
/Q +/Q 3	/Q
 @/Q 8/Q /Q /Qd..$. ). 	., !!r   