o
    r::j                     @  s   d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dlZ	d dl
Zd dlZd dlmZmZmZmZmZmZmZ erBd dlmZ G dd dejZedkrUe  dS dS )	    )annotationsN)TYPE_CHECKING)
GraphProtoSparseTensorProtoTensorProtocheckerhelpernumpy_helpershape_inference)Sequencec                   @  s  e Zd ZedvddZ	dwdxddZdyddZdyddZdyddZdyddZ	dyddZ
dyddZdyddZdydd Zdyd!d"Zdyd#d$Zdyd%d&Zdyd'd(Zdyd)d*Zdyd+d,Zdyd-d.Zdyd/d0Zdyd1d2Zdyd3d4Zdyd5d6Zdyd7d8Zdyd9d:Zdyd;d<Zedvd=d>Zdyd?d@ZdydAdBZdydCdDZdydEdFZ dydGdHZ!dydIdJZ"dydKdLZ#dydMdNZ$dydOdPZ%dydQdRZ&dydSdTZ'dydUdVZ(dydWdXZ)dydYdZZ*dyd[d\Z+dyd]d^Z,dyd_d`Z-dadb Z.dcdd Z/dedf Z0dgdh Z1dydidjZ2dydkdlZ3dydmdnZ4dydodpZ5dydqdrZ6dydsdtZ7duS )zTestCheckerreturnr   c                 C  s4   t jddt j}tjdtjd|	d
 dS )N      test)r   r      name	data_typedimsvalsnprandomrandnastypefloat32r   make_tensorr   FLOATreshapetolistselfnp_array r$   ]/home/nk/hobo-godmode/plappi-mvp/.venv/lib/python3.10/site-packages/onnx/test/checker_test.py_sample_float_tensor      z TestChecker._sample_float_tensorspvalshapeSequence[int]valuesindices_shapeindicesr   strr   c                 C  sT   t  }|j| t|}|jt|tj	|f| |j
tdtj	|| |S )Nspind)r   r   extendlenr+   CopyFromr   r   r   INT64r-   )r"   r)   r+   r,   r-   r   sparsennzr$   r$   r%   make_sparse)   s   zTestChecker.make_sparseNonec                 C  s$   t jddgdgdd}t| d S )NReluXYr   r   r   	make_noder   
check_noder"   noder$   r$   r%   test_check_node=   s   zTestChecker.test_check_nodec                 C  sj   t jdg dgdd}t| t jddgdgdd}t| t jddgdgdd}| tjtj| d S )NGivenTensorFillr:   r   r;    r8   )r   r=   r   r>   assertRaisesValidationErrorr?   r$   r$   r%   %test_check_node_input_marked_optionalB   s   

z1TestChecker.test_check_node_input_marked_optionalc                 C  s   d}t ddt |dg}d}ddg}dg}t jd	dgd
g|dt jd	dgdg|dt jdd
dgdg|dg}t ||||||}t| d S )NlocalrC         func_nested_identity_addabcfunc_identitya1)domainb1func_add)r   make_opsetidr=   make_functionr   check_function)r"   func_domainfunc_nested_opset_importsfunc_nested_identity_add_namefunc_nested_identity_add_inputs func_nested_identity_add_outputsfunc_nested_identity_add_nodesrJ   r$   r$   r%   test_check_function_nestedO   s(   

z&TestChecker.test_check_function_nestedc                   s   t j  d _dtj i _t j d fdd}t	j
d	d
gdgdd}t	|gdt	d
tjddggt	dtjddgg}|| |j| jg d|jd _| t j|| d
|jd _|| d S )Nr   rC   gr   r   r7   c                   s   t |   d S N)r   check_graph)r]   ctxlex_ctxr$   r%   check_ir_version_3o   s   zETestChecker.test_check_graph_ir_version_3.<locals>.check_ir_version_3r8   r9   r:   r   r;   rI   r   no-existr   )r]   r   r   r7   )r   CCheckerContext
ir_versiononnxdefsonnx_opset_versionopset_importsLexicalScopeContextr   r=   
make_graphmake_tensor_value_infor   r   initializerr0   r&   r   rD   rE   )r"   rc   r@   graphr$   r`   r%   test_check_graph_ir_version_3h   s$   

z)TestChecker.test_check_graph_ir_version_3c                 C  s   t jddgdgdd}t |gdt dtjddggt dtjddgg}t| |j	| j
g d|jd	 _t| d|jd	 _t| d S )
Nr8   r9   r:   r   r;   rI   r   rd   r   )r   r=   rm   rn   r   r   r   r_   ro   r0   r&   r   r"   r@   rp   r$   r$   r%   test_check_graph   s   

zTestChecker.test_check_graphc                 C  s  t jdddgdgdd}t jddgdgd	d}t ||gd
t dtjddgt dtjddggt dtjddgg}t j|d
d}| t	j
tj|d t| t ||gd
t dtjddgt dtjddggt dtjddgg}t j|d
d}| t	j
tj|d t| d S )NDivr9   r:   Ztest_divr;   IdentityWtest_identityr   rI   r   producer_nameT)r   r=   rm   rn   r   r   BOOL
make_modelrD   r
   InferenceErrorr   check_modelr_   INT32)r"   node_divnode_identityrp   modelr$   r$   r%   test_check_graph_types   s8   
z"TestChecker.test_check_graph_typesc                 C  s   t jddgdgdd}t |gdt dtjddggt dtjddgg}t| |j	| j
g d|jd	 _| tjtj| d S )
Nr8   r9   r:   r   r;   rI   r   rC   r   )r   r=   rm   rn   r   r   r   r_   ro   r0   r&   r   rD   rE   rr   r$   r$   r%   'test_check_graph_empty_initializer_name   s   
z3TestChecker.test_check_graph_empty_initializer_namec                 C  s   t jddgdgdd}t |gdt dtjddggt dtjddgg}t| | dgg d	d
gg dd}|j	
|g | tjtj| d S )Nr8   r9   r:   r   r;   rI   r   d            r   	      Q   rC   )r   r=   rm   rn   r   r   r   r_   r6   sparse_initializerr0   rD   rE   r"   r@   rp   r4   r$   r$   r%   .test_check_graph_empty_sparse_initializer_name   s   
z:TestChecker.test_check_graph_empty_sparse_initializer_namec                 C  s   t jddgdgdd}t |gdt dtjddggt dtjddgg}t| |j	| j
g d|jd _| d	gg d
dgg dd}|j	|g | tjtj| d S )Nr8   r9   r:   r   r;   rI   r   r   r   r   r   r   )r   r=   rm   rn   r   r   r   r_   ro   r0   r&   r   r6   r   rD   rE   r   r$   r$   r%   %test_check_graph_duplicate_init_names   s   
z1TestChecker.test_check_graph_duplicate_init_namesc                 C  sH   t jddgdgdd}t |gdg t dtjddgg}t| d S )NrB   rC   r:   r   r;   rI   r   )r   r=   rm   rn   r   r   r   r_   rr   r$   r$   r%   test_check_graph_optional_input   s   z+TestChecker.test_check_graph_optional_inputc              
   C  s   t jddgdgdd}t jddgdgdd}t j||gdt dtjd	d
gt dtjd	d
ggt dtjd	d
ggd}| tjtj	| d S )Nr8   r9   ru   relu1r;   r:   relu2r   rI   r   inputsoutputs
r   r=   rm   rn   r   r   rD   r   rE   r_   )r"   r   r   rp   r$   r$   r%   test_check_graph_ssa   s   	z TestChecker.test_check_graph_ssac              
   C  s   t jddgdgddd}t jddgdgdd	d}t j||gd
t dtjddggt dtjddggd}| tjtj	| d S )NScaler9   r:          @n1scaler   ru         @n2r   rI   r   r   r   )r"   r   r   rp   r$   r$   r%   %test_check_graph_topologically_sorted  s   z1TestChecker.test_check_graph_topologically_sortedc                 C  sh   t jddgdgdd}t |gdt dtjddggt dtjddgg}t j|dd}t| d S 	Nr8   r9   r:   r   r;   rI   r   rz   )	r   r=   rm   rn   r   r   r}   r   r   r"   r@   rp   r   r$   r$   r%   test_check_model  s   zTestChecker.test_check_modelc                 C  sl   t jddgdgdd}t |gdt dtjddggt dtjddgg}t j|dd}t|	  d S r   )
r   r=   rm   rn   r   r   r}   r   r   SerializeToStringr   r$   r$   r%   test_check_serialized_model&  s   z'TestChecker.test_check_serialized_modelc                 C  s   t jddgdgdd}t |gdt dtjddggt dtjddgg}t j|dd}| }tj	j
td	t| t| W d    d S 1 sMw   Y  d S 
Nr8   r9   r:   r   r;   rI   r   rz   MAXIMUM_PROTOBUF)r   r=   rm   rn   r   r   r}   r   unittestmockpatchobjectr   r1   r   r"   r@   rp   r   
serializedr$   r$   r%   'test_check_model_protobuf_size_boundary2  s   "z3TestChecker.test_check_model_protobuf_size_boundaryc                 C  s   t jddgdgdd}t |gdt dtjddggt dtjddgg}t j|dd}| }tj	j
td	t|d  | ttj| W d    d S 1 sRw   Y  d S r   )r   r=   rm   rn   r   r   r}   r   r   r   r   r   r   r1   rD   
ValueErrorr   r   r$   r$   r%   0test_check_model_protobuf_size_over_limit_raises@  s   "z<TestChecker.test_check_model_protobuf_size_over_limit_raisesc                 C  sx   t jddgdgdd}t |gdt dtjddggt dtjddgg}t d	d}t j|d|gd
}t	| d S )NPadr9   r:   )r   r   r   r   )paddingsr   rI   r   rC   r{   rk   
r   r=   rm   rn   r   r   rS   r}   r   r   r"   r@   rp   onnx_idr   r$   r$   r%   test_check_old_modelP  s   z TestChecker.test_check_old_modelc                 C  sJ   | j }t| tjddtj}tj	
||_| tjtj| d S )Nr   r   )r&   r   check_tensorr   r   r   r   r   rh   r	   tobytes_little_endianraw_datarD   rE   )r"   tensorinput_npr$   r$   r%   test_check_tensor]  s
   
zTestChecker.test_check_tensorc                 C  sX   t  }t j|_|jd |jd t| |jd d = d|_| 	tj
tj| d S )NrI   s   Test)r   STRINGr   r   appendstring_datar   r   r   rD   rE   r"   r   r$   r$   r%   test_check_string_tensorf  s   
z$TestChecker.test_check_string_tensorc                 C  s$   | j }tj|_| tjtj| d S r^   )r&   r   r   r   rD   r   rE   r   r   r$   r$   r%   "test_check_tensor_mismatched_fieldr  s   z.TestChecker.test_check_tensor_mismatched_fieldc              
   C  s   t jddgdgddd}t jddgdgdd	d}t j||gd
g t dtjddggd}t jddgdg||d}t j|gdt dtjdgt dtjddggt dtjddggd}t| d S Nr   r9   r:   r   r   r   ru   r   r   nestedrI   r   r   Ifcond)then_branchelse_branchr   )	r   r=   rm   rn   r   r   r|   r   r_   )r"   r   r   rp   i1r$   r$   r%   test_nested_graphw  s(   
zTestChecker.test_nested_graphc              
   C  s   t jddgdgddd}t jddgdgdd	d}t }d|_t j||gd
g t dtjddggd}t jddgdg||d}t j|gdt dtj	dgt dtjddggt dtjddggd}t
| d S r   )r   r=   rh   ValueInfoProtor   rm   rn   r   r   r|   r   r_   )r"   r   r   input_xrp   r   r$   r$   r%   .test_nested_graph_without_subgraph_input_shape  s,   
z:TestChecker.test_nested_graph_without_subgraph_input_shapec                 C  s4   t jddt j}tjdtjd|	d
 dS )Nr   r   r   )r   r   r   r   r!   r$   r$   r%   _sample_0_elem_tensor  r'   z!TestChecker._sample_0_elem_tensorc                 C  s   | j }t| d S r^   )r   r   r   r   r$   r$   r%   test_check_tensor_zero_elem  s   z'TestChecker.test_check_tensor_zero_elemc                 C  s(   t jdg dgdddgd}t| d S )NConstantFillr:   r   rI   r   )r   r)   r<   r?   r$   r$   r%   "test_check_removed_experimental_op  s   z.TestChecker.test_check_removed_experimental_opc                 C  sz   t jddgdgddd}t |gdt dtjddggt dtjddgg}t dd}t j|d|gd	}t	| d S )
N
NonExistOpr9   r:   r   ztest.domain)r   rP   rI   r   r   r   r   r$   r$   r%   -test_skip_schema_check_on_non_standard_domain  s   z9TestChecker.test_skip_schema_check_on_non_standard_domainc                 C  s*   |  dgg ddgg d}t| d S )Nr   r   r   r   r6   r   check_sparse_tensorr"   r4   r$   r$   r%   test_check_sparse_tensor  s   z$TestChecker.test_check_sparse_tensorc                 C  2   |  dgg ddgg d}| tjtj| d S )Nr   r   r   )r   r      r6   rD   r   rE   r   r   r$   r$   r%   &test_check_sparse_tensor_invalid_index     z2TestChecker.test_check_sparse_tensor_invalid_indexc                 C  r   )Nr   r   r   )r   r   r   r   r   r$   r$   r%   "test_check_sparse_tensor_unordered  r   z.TestChecker.test_check_sparse_tensor_unorderedc                 C  s.   |  ddgg dddgg d}t| d S )N
   r   r   r   r   r   r         rI   r   r   r$   r$   r%   #test_check_sparse_tensor_coo_format  s    z/TestChecker.test_check_sparse_tensor_coo_formatc                 C  6   |  ddgg dddgg d}| tjtj| d S )Nr   r   r   r   )r   r   r   r   r   rI   r   r   r$   r$   r%   1test_check_sparse_tensor_coo_format_invalid_index      z=TestChecker.test_check_sparse_tensor_coo_format_invalid_indexc                 C  r   )Nr   r   r   r   r   r   r   r$   r$   r%   1test_check_sparse_tensor_coo_format_invalid_shape  r   z=TestChecker.test_check_sparse_tensor_coo_format_invalid_shapec                 C  r   )Nr   r   r   rI   )r   rI   r   r   r   r$   r$   r%   0test_check_sparse_tensor_coo_format_invalid_dim2  r   z<TestChecker.test_check_sparse_tensor_coo_format_invalid_dim2c           	      C  s   d}d}t dtj|g}| ||gg ddgg d}t jdg dg|d	}t d
tj|g}t dddgd
g}t ||gd|g|g}t| d S )N   r   r9   )r   r   rI   r   )r      %   Constantre   )sparse_valuer:   MatMulsparse_matmul)	r   rn   r   r   r6   r=   rm   r   r_   )	r"   MNr9   sparse_tensornode1r:   node2rp   r$   r$   r%   test_check_sparse_matmul  s   z$TestChecker.test_check_sparse_matmulc           	      C  s   d}t dtj|g}t dtj|g}t dtj|g}t dd}t dddgdg}t |gd||g|g}t j|d	|gd
}| 	t
jtj|d d S Nr   r9   r:   ru   rC   r   Addtest_add_inputr   r   T)r   rn   r   r|   r   rS   r=   rm   r}   rD   r
   r~   r   r   	r"   r   r9   r:   ru   r   r@   rp   r   r$   r$   r%   'test_check_model_unsupported_input_type     z3TestChecker.test_check_model_unsupported_input_typec           	      C  s   d}t dtj|g}t dtj|g}t dtj|g}t dd}t dddgdg}t |gd||g|g}t j|d	|gd
}| 	t
jtj|d d S r   )r   rn   r   r   r   rS   r=   rm   r}   rD   r
   r~   r   r   r   r$   r$   r%   "test_check_model_inconsistent_type  r   z.TestChecker.test_check_model_inconsistent_typec           	      C  s   d}t dtj|g}t dtj|g}t dtj|g}t dd}t dddgdg}t |gd||g|g}t j|d	|gd
}| 	t
jtj|d d S r   )r   rn   r   r   r|   rS   r=   rm   r}   rD   r
   r~   r   r   r   r$   r$   r%   (test_check_model_unsupported_output_type  r   z4TestChecker.test_check_model_unsupported_output_typec                 C  s  t jt ddgdt jdt jdtjdgdt jdtjg dt jd	tjdgdt jd
tjg dt jdtjdgdgt jdtjdgdgt	j
tjdtjdddt	j
tjdgtjdd	dt	j
tjdtjdd
dt	j
tjdgtjdddgt jddgdgddtjdt jddd
gdgdddt jddgdgdddt jdg ddd gd!t jd"t jd#tjg dt jd$tjg dt jd%tjdgdt jd&tjdgdt jd'tjg dgt jd(tjg dt jd)tjdgdt jd&tjdgdgt	j
tjdtjdd'dgt jd*d%d&gd)gd+d,t jdd)gd-gd.dtjdt jdd-d'gd/gd0ddt jdd/gd(gd1ddgd2d3t jd4dgd5gd6d7gd8t jd9d5d	gdgd9d,gd2d:}tj|d;d< d S )=NrC   r   r   	test-loopinput_0rI   r)   while_maximum_iterations_0const_fold_opt__18const_fold_opt__17Const_0output_0    dtyper;         $@Castwhile_cond_158_while_Less__13_0while_cond_158_while_Less__13r   r   r   rP   toLesswhile_cond_158_while_Less_0while_cond_158_while_Lessr   r   r   rP   Squeezewhile_cond_158_while_Squeeze_0while_cond_158_while_SqueezeLoopr  r  r  r  while_loop_0while_loop_1
while_loop
while_bodywhile_while_loop_counter_0
cond__15_0while_placeholder_0while_add_const_0_0const_fold_opt__191cond___while_Identity_graph_outputs_Identity__3_0while_Identity_2_0r   	while_Addr   r   r   cond___while_Less__13_0cond___while_Less__13cond___while_Less_0cond___while_Lesscond___while_Squeezer   r   r   ro   nodesr   r   r   body	UnsqueezeReshape_tensor_0Reshape_tensorr   r   r   r   axesReshaperk   rg   rp   T
full_check)r   r}   make_operatorsetidrm   rn   r   r   r3   r   r	   
from_arrayr   arrayint64r   int32r=   r|   r   r   r"   r   r$   r$   r%   /test_loop_with_same_initializer_input_below_ir4%  s>  








	
Z 0z;TestChecker.test_loop_with_same_initializer_input_below_ir4c                 C  sf  t jt ddgdt jdt jdtjdgdt jdtjg dt jd	tjdgdt jd
tjg dt jdtjdgdgt jdtjdgdgt	j
tjdtjdddt	j
tjdgtjdd	dt	j
tjdtjdd
dt	j
tjdgtjdddgt jddgdgddtjdt jddd
gdgdddt jddgdgdddt jdg ddd gd!t jd"t jd#tjg dt jd$tjg dt jd%tjdgdt jd&tjdgdt jd	tjg dgt jd'tjg dt jd(tjdgdt jd&tjdgdgg t jd)d%d&gd(gd*d+t jdd(gd'gd,dtjdgd-d.t jd/dgd0gd1d2gd3t jd4d0d	gdgd4d+gd-d5}| tjtj|d6 d S )7NrC   r   r   r   r  rI   r  r  r  r  r  r  r  r	  r;   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r!  r"  r(  r%  r   r&  r'  r)  r-  r/  r1  r2  r3  r   r4  r6  r7  Tr   r}   r:  rm   rn   r   r   r3   r   r	   r;  r   r<  r=  r   r>  r=   r|   rD   r
   r~   r   r   r?  r$   r$   r%   4test_loop_with_different_initializer_input_below_ir4  s  








	C z@TestChecker.test_loop_with_different_initializer_input_below_ir4c                 C  s  t jt ddgdt jdt jdtjdgdt jdtjg dt jd	tjdgdt jd
tjg dt jdtjdgdgt jdtjdgdgt	j
tjdtjdddt	j
tjdgtjdd	dt	j
tjdtjdd
dt	j
tjdgtjdddgt jddgdgddtjdt jddd
gdgdddt jddgdgdddt jdg ddd gd!t jd"t jd#tjg dt jd$tjg dt jd%tjdgdt jd&tjdgdgt jd'tjg dt jd(tjdgdt jd&tjdgdgt	j
tjd)tjdd#dgt jd*d%d&gd(gd+d,t jdd(gd-gd.dtjdt jdd-d#gd/gd0ddt jdd/gd'gd1ddgd2d3t jd4dgd5gd6d7gd8t jd9d5d	gdgd9d,gd2d:}| tjtj|d; d S )<NrC   r   r   r   r  rI   r  r  r  r  r  r  r  r	  r;   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r!  r"  r$  r%  r   r   r&  r'  r(  r)  r*  r+  r,  r-  r/  r1  r2  r3  r   r4  r6  r7  TrA  r?  r$   r$   r%   /test_loop_with_same_initializer_input_above_ir4{  s<  








	
X -z;TestChecker.test_loop_with_same_initializer_input_above_ir4c                 C  s8   t jd}tj|dd t jd}tj|dd d S )Nz
            <
                ir_version: 7,
                opset_import: [ "" : 17]
            >
            agraph (float[N] x) => (int64[M] y)
            {
                y = Constant <value_ints: ints = []>()
            }
        Tr8  z
            <
                ir_version: 7,
                opset_import: [ "" : 17]
            >
            agraph (float[N] x) => (float[M] y)
            {
                y = Constant <value_floats: floats = []>()
            }
        )rh   parserparse_modelr   r   r?  r$   r$   r%   test_empty_list_attribute/  s   z%TestChecker.test_empty_list_attributec                 C  s   t dtjjdg}t dtjjdg}t ddgdg}t |gd|g|g}t j|dd}t	 }t
j|d}t|| tj|dd	 W d    d S 1 sSw   Y  d S )
NinputrI   outputrw   r   rz   u   模型モデル모델✨.onnxTr8  )r   rn   rh   r   r   r=   rm   r}   tempfileTemporaryDirectoryospathjoinsaver   r   )r"   input_tensoroutput_tensorr@   rp   r   temp_dirunicode_model_pathr$   r$   r%   &test_check_model_supports_unicode_pathM  s   
"z2TestChecker.test_check_model_supports_unicode_pathc                 C  "   t jd}| tjtj| d S )Nz
            <ir_version: 7, opset_import: [ "" : 17]>
            agraph (float[N] x) => (float[N] y, float[N] z)
            {
                y = Add(x, x)
            }
            # Error: z is not defined
        rh   rD  rE  rD   r   rE   r   r?  r$   r$   r%   test_graph_output_is_defined]     
z(TestChecker.test_graph_output_is_definedc                 C  rT  )Nap  
            <ir_version: 7, opset_import: [ "" : 17]>
            agraph (float[N] x, bool cond) => (float[N] y)
            {
                sum = Add (x, x)
                prod = Mul (x, x)
                y = If (cond) <
                    then_branch = then_graph () => (sum) {},
                    else_branch = else_graph () => (prod) {}
                >
            }
            # Error: sum/prod are accessible inside if-then-else branches, but cannot
            # be used as outputs of the then/else branch implicitly.
            # An explicit "Identity(sum)" must be used to return sum as output.
        rU  r?  r$   r$   r%   -test_graph_output_is_defined_within_sub_graphj  s   z9TestChecker.test_graph_output_is_defined_within_sub_graphc                 C  rT  )Na&  
            <ir_version: 8, opset_import: [ "" : 17, "local" : 1 ]>
            agraph (float[N] X) => (float[N] Y) {
                Y = local.foo (X)
            }
            <opset_import: [ "" : 17, "local" : 1 ], domain: "local">
            foo (x) => (y) { y = local.foo (x) }
        rU  r?  r$   r$   r%   0test_check_model_rejects_self_recursive_function~  rW  z<TestChecker.test_check_model_rejects_self_recursive_functionc                 C  rT  )Na  
            <ir_version: 8, opset_import: [ "" : 17, "local" : 1 ]>
            agraph (float[N] X) => (float[N] Y) {
                Y = local.foo (X)
            }
            <opset_import: [ "" : 17, "local" : 1 ], domain: "local">
            foo (x) => (y) { y = local.bar (x) }
            <opset_import: [ "" : 17, "local" : 1 ], domain: "local">
            bar (x) => (y) { y = local.foo (x) }
        rU  r?  r$   r$   r%   'test_check_model_rejects_indirect_cycle  s   z3TestChecker.test_check_model_rejects_indirect_cyclec                 C  s   t  }t j|_|jddg d|_d|_| tj	tj
| t  }t j|_|jddg d|_d|_| tj	tj
| t  }t j|_|jdg d|_t
| dS )	z7Reject tensors with overflowing or negative dimensions.l            t    r     s                   r   N)r   r   r   r   r0   r   r   rD   r   rE   r   )r"   r   tensor2tensor3r$   r$   r%   test_check_tensor_invalid_dims  s"   z*TestChecker.test_check_tensor_invalid_dimsc                 C  s   t jt jt jfD ]6}t  }||_|jdg d|_d|_| 	t
jt
j| t  }||_|jdg d|_d|_t
| qt jt jfD ]6}t  }||_|jdg d|_d|_| 	t
jt
j| t  }||_|jdg d|_d|_t
| qEdS )zCReject packed sub-byte tensors whose raw_data payload is too small.r   r[  s       s        s     s      N)r   INT4UINT4
FLOAT4E2M1r   r   r0   r   r   rD   r   rE   r   INT2UINT2r"   r
  r   r^  r$   r$   r%   )test_check_tensor_packed_subbyte_raw_data  s6   z5TestChecker.test_check_tensor_packed_subbyte_raw_datac                 C  s   t jt jt jfD ]?}t  }||_|jdg d|_|jdg | 	t
jt
j| t  }||_|jdg d|_|jddg t
| qt jt jfD ]?}t  }||_|jdg d|_|jdg | 	t
jt
j| t  }||_|jdg d|_|jddg t
| qNdS )zEReject packed sub-byte tensors whose int32_data payload is too small.r   r[  r      N)r   ra  rb  rc  r   r   r0   r   
int32_datarD   r   rE   r   rd  re  rf  r$   r$   r%   +test_check_tensor_packed_subbyte_int32_data  s6   z7TestChecker.test_check_tensor_packed_subbyte_int32_datac                 C  sL   t jt jt jt jt jfD ]}t  }||_|jdg d|_	t
| qdS )z=Zero-element packed tensors with empty payload must be valid.r   r[  N)r   ra  rb  rc  rd  re  r   r   r0   r   r   r   )r"   r
  r   r$   r$   r%   +test_check_tensor_packed_subbyte_zero_elems  s   z7TestChecker.test_check_tensor_packed_subbyte_zero_elemsN)r   r   )r(   )r)   r*   r+   r*   r,   r*   r-   r*   r   r.   r   r   )r   r7   )8__name__
__module____qualname__propertyr&   r6   rA   rF   r\   rq   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r@  rB  rC  rF  rS  rV  rX  rY  rZ  r`  rg  rj  rk  r$   r$   r$   r%   r      sv    






.











	



	













 
7 
! 5




$$r   __main__)
__future__r   rK  rI  r   unittest.mocktypingr   numpyr   	onnx.defsrh   onnx.parserr   r   r   r   r   r	   r
   collections.abcr   TestCaser   rl  mainr$   r$   r$   r%   <module>   s2   $
         t