o
    e0                     @   s  d Z ddlZddlmZmZmZmZmZmZm	Z	m
Z
 ddlm  mZ ddlZddlmZ ddlmZmZmZmZmZmZ ddlZddlZdZe Ze
e_dej  ie_!eded	ef d
Z"dee dee"ge"f fddZ#e#eefdedejddfddZ$e#eefdedejddfddZ%e#eefdedejddfddZ&e#eefdedejddfddZ'e#e	efde	dejddfddZ(efdedejddfd d!Z)d'd#eee*e+f d$e,ddfd%d&Z-ej.Z.dS )(zhonnx checker

This implements graphalities that allows us to check whether a serialized
proto is legal.
    N)ValueInfoProtoAttributeProtoTensorProtoSparseTensorProto	NodeProto
ModelProto
GraphProto
IR_VERSION)Message)TypeVarCallableAnyTypecastUnioni 5w FuncType.)bound
proto_typereturnc                    s   dt dt f fdd}|S )Npy_funcr   c                    s6   t  tfdtdtjdtf fdd}tt|S )Nprotoctxr   c                    s0   t |  std jttj|  |S )Nz0You cannot pass an object that is not of type {})
isinstanceRuntimeErrorformat__name__getattrCSerializeToString)r   r   )r   r    <D:\Projects\ConvertPro\env\Lib\site-packages\onnx/checker.pychecker/   s   

z3_create_checker.<locals>.decorator.<locals>.checker)		functoolswrapsDEFAULT_CONTEXTr
   r   CheckerContextr   r   r   )r   r"   r   )r   r!   	decorator.   s   $
z"_create_checker.<locals>.decorator)r   )r   r(   r    r'   r!   _create_checker-   s   
r)   
value_infor   c                 C      d S Nr    )r*   r   r    r    r!   check_value_info;      r-   tensorc                 C   r+   r,   r    )r/   r   r    r    r!   check_tensor@   r.   r0   attrc                 C   r+   r,   r    )r1   r   r    r    r!   check_attributeE   r.   r2   nodec                 C   r+   r,   r    )r3   r   r    r    r!   
check_nodeJ   r.   r4   graphc                 C   r+   r,   r    )r5   r   r    r    r!   check_graphO   r.   r6   sparsec                 C   s   t |  | d S r,   )r   check_sparse_tensorr   )r7   r   r    r    r!   r8   T   s   r8   Fmodel
full_checkc                 C   s   t | trt|  |rtjj| ddd dS dS t | tr | n|  }t	
|tkr/tdt| |rAtjj| ddd dS dS )zCheck the consistency of a model. An exception is raised if the test fails.

    Arguments:
        model (ModelProto): model to check
        full_check (bool): if True, the function checks shapes can be inferred
    T)Z
check_typeZstrict_modezZThis protobuf of onnx model is too large (>2GB). Call check_model with model path instead.N)r   strr   Zcheck_model_pathonnxZshape_inferenceZinfer_shapes_pathbytesr   sys	getsizeofMAXIMUM_PROTOBUF
ValueErrorcheck_modelZinfer_shapes)r9   r:   Zprotobuf_stringr    r    r!   rB   X   s   


rB   )F)/__doc__r#   r<   r   r   r   r   r   r   r   r	   Zonnx.onnx_cpp2py_export.checkerZonnx_cpp2py_exportr"   r   Z	onnx.defsZgoogle.protobuf.messager
   typingr   r   r   r   r   r   Zonnx.shape_inferencer>   r@   r&   r%   Z
ir_versionZdefsZonnx_opset_versionZopset_importsr   r)   r-   r0   r2   r4   r6   r8   r;   r=   boolrB   ZValidationErrorr    r    r    r!   <module>   s8   (  "
