o
    r::j@n                    @  s  U d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	 d dl
Zd dlZd dlmZ d dlmZ d dlZd dlmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlm Z m!Z!m"Z"m#Z#m$Z$m%Z% d d	l&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- d d
l.m/Z/ erd dl0m1Z1 d$ddZ2dd e3 D Z4de5d< d%ddZ6G dd dej7Z8G dd de8Z9G dd  d e8Z:e;d!krej<d"d# dS dS )&    )annotationsN)Path)TYPE_CHECKINGAny)text_format)parameterized)ONNX_ML
GraphProto
ModelProto	NodeProtoOperatorSetIdProtoSparseTensorProtoTensorProto	TypeProtoValueInfoProtocheckerdefshelpernumpy_helper)AI_ONNX_PREVIEW_DOMAINAI_ONNX_PREVIEW_TRAINING_DOMAINONNX_DOMAINONNX_ML_DOMAINOpSchemaSchemaError)make_empty_tensor_value_info
make_graph	make_nodemake_opsetidmake_tensormake_tensor_sequence_value_infomake_tensor_value_info)parse_graph)Sequenceschemar   returnset[int]c              	   C  sR   t  }t| jddD ]}z|t| j|| jj W q
 ty&   Y  |S w |S )Nr   )	setrangesince_versionaddr   
get_schemanamedomainr   )r$   versionsversion r1   e/home/nk/hobo-godmode/plappi-mvp/.venv/lib/python3.10/site-packages/onnx/test/shape_inference_test.pyget_available_versions9   s   r3   c                 C  s"   i | ]}|j |jtt|fqS r1   )r-   r.   	frozensetr3   ).0r$   r1   r1   r2   
<dictcomp>E   s    r6   z%dict[str, tuple[str, frozenset[int]]]ALL_OP_VERSIONSop_namestrlist[tuple[str, int]]c                   s8   t |  \ }|std|  t|} fdd|D S )Nz#No versions available for operator c                   s*   g | ]}|d ks t krd| |fqS )   r0   )r   )r5   r0   r.   r1   r2   
<listcomp>P   s    z$all_versions_for.<locals>.<listcomp>)r7   
ValueErrorsorted)r8   versions_setr/   r1   r<   r2   all_versions_forK   s   
rA   c                   @  s@   e Zd Z	d d!ddZd"ddZd#ddZd$ddZdd ZdS )%TestShapeInferenceHelperNseed_values5Sequence[str | tuple[str, TensorProto.DataType, Any]]nodeslist[NodeProto]
value_infolist[ValueInfoProto]initializerSequence[TensorProto] | Noner%   r	   c                 C  s   |d u rg }dd |D }g }|D ]V}t |tr%|d d \}}	t| }
n
|tj}}	t|}
||v r9||
 q||
 |td| |	d |td| tjd tdd| d| g|gg|d d	< qt	j
|d
|g ||dS )Nc                 S     h | ]}|j qS r1   r-   r5   xr1   r1   r2   	<setcomp>f       z7TestShapeInferenceHelper._make_graph.<locals>.<setcomp>   SEED_r1   UNKNOWN_SHAPE_NReshaper   test)rI   rG   )
isinstancetupler!   r   	UNDEFINEDr   appendINT64r   r   r   )selfrC   rE   rG   rI   names_in_initializerinput_value_infos
seed_value	seed_name
proto_typeseed_value_infor1   r1   r2   _make_graph]   sF   


z$TestShapeInferenceHelper._make_graphgraph_or_modelGraphProto | ModelProtokwargsr   r
   c                 K  sV   | dd}t|trd|d< tj|fi |}n|}tjj|d|d}t	| |S )N	data_propFz	onnx-testproducer_nameT)strict_moderg   )
poprW   r	   r   
make_modelonnxshape_inferenceinfer_shapesr   check_model)r\   rd   rf   rg   
orig_modelinferred_modelr1   r1   r2   	_inferred   s   

z"TestShapeInferenceHelper._inferredvisNonec           	        s   t |tr|n|j}dd |D   fdd|jD | }| j|fi |}t|jj}t|dd d}t|dd d}t|t|ksFJ t||d	d
D ]\}}| 	|j
|j
 qMd S )Nc                 S  rK   r1   rL   rM   r1   r1   r2   rO      rP   z<TestShapeInferenceHelper._assert_inferred.<locals>.<setcomp>c                   s   g | ]	}|j  vr|qS r1   rL   rM   names_in_visr1   r2   r=      s    z=TestShapeInferenceHelper._assert_inferred.<locals>.<listcomp>c                 S     | j S rT   rL   rN   r1   r1   r2   <lambda>       z;TestShapeInferenceHelper._assert_inferred.<locals>.<lambda>)keyc                 S  rw   rT   rL   rx   r1   r1   r2   ry      rz   T)strict)rW   r	   graphrG   rr   listr?   lenzip_compare_value_infostype)	r\   rd   rs   rf   r}   rq   inferred_visv
inferred_vr1   ru   r2   _assert_inferred   s   z)TestShapeInferenceHelper._assert_inferredvi_typer   inferred_vi_typec                 C  s  | dr| dsJ |j dsJ |j dsJ |jj|jjks&J |j d|j dks4J |j drt|jjjt|jjjksJJ t|jjjD ]3\}}|jjj| }|jrq|j|jkspJ d| d| dqQ|j|jksJ d| d| dqQd S d S | dr| dsJ |j	j}|j	j}| 
|| d S | dr| dsJ |jj}|jj}| 
|| d S | dr| dsJ |jj|jjksJ | 
|jj|jj d S |t kr|t ksJ d S tdt|)	Ntensor_type	elem_typeshape
sequence_typeoptional_typemap_typez6Unrecognized value info type in _compare_value_infos: )HasFieldr   r   r   r   dim	enumerate	dim_param	dim_valuer   r   r   r   key_type
value_typerl   r   NotImplementedErrorr9   )r\   r   r   dim_ir   inferred_dimviinferred_vir1   r1   r2   r      s\   





z-TestShapeInferenceHelper._compare_value_infosc                 C  s   |r	t | d S d S rT   )pytestskip)r\   	conditionreasonr1   r1   r2   skipIf   s   zTestShapeInferenceHelper.skipIfrT   )
rC   rD   rE   rF   rG   rH   rI   rJ   r%   r	   )rd   re   rf   r   r%   r
   )rd   re   rs   rH   rf   r   r%   rt   )r   r   r   r   r%   rt   )__name__
__module____qualname__rc   rr   r   r   r   r1   r1   r1   r2   rB   \   s    
1

3rB   c                   @  s4  e Zd ZdjddZdkd	d
ZeeddjddZeeddjddZ	eeddjddZ
eeddjddZeeddjddZeeddjddZeeddjddZdlddZeeddjd d!Zdmd#d$Zeeddjd%d&Zeed'djd(d)Zeed'ed*djd+d,Zeed-djd.d/Zeed0djd1d2Zeed0djd3d4Zeed0djd5d6Zeed0djd7d8Zeed0djd9d:Zeed0djd;d<Zeed=djd>d?Zeed=djd@dAZeed=djdBdCZ eed=djdDdEZ!eed=djdFdGZ"eedHdjdIdJZ#eedHdjdKdLZ$eedHdjdMdNZ%eedHdjdOdPZ&eedHdjdQdRZ'eedSdjdTdUZ(eedSdjdVdWZ)eedSdjdXdYZ*eedSdjdZd[Z+eedSdjd\d]Z,eedSdjd^d_Z-eedSdjd`daZ.eedSdjdbdcZ/eedddjdedfZ0eedddjdgdhZ1eedidjdjdkZ2eedidjdldmZ3eedidjdndoZ4eedidjdpdqZ5eedidjdrdsZ6eedtdjdudvZ7eedwdjdxdyZ8eedtdjdzd{Z9eedtdjd|d}Z:eedtdjd~dZ;eedtdjddZ<eedtdjddZ=eedtdjddZ>dnddZ?eedtdjddZ@eedtdjddZAeedtdjddZBeedtdjddZCeedtdjddZDeedtdjddZEeedtdjddZFdoddZGeedtdjddZHeedtdjddZIeedtdjddZJeeddjddZKeeddjddZLeeddjddZMeeddjddZNeeddjddZOeeddjddZPeeddjddZQeeddjddZReeddjddZSeeddjddZTeeddjddZUeeddjddÄZVeedădjddƄZWdjddȄZXeedădjddʄZYdjdd̄ZZeed̓djddτZ[eed̓djddфZ\eed҃djddԄZ]eed҃djddքZ^djdd؄Z_eedكdjddۄZ`eed܃djddބZaeed܃djddZbeeddjddZceeddjddZddjddZedjddZfdjddZgdjddZhdjddZidjddZjdjddZkdjddZldjddZmdjddZndjddZodjddZpdjddZqdjd dZrdjddZsdjddZtdjddZudjdd	Zvdjd
dZwdjddZxdjddZydjddZzdjddZ{djddZ|djddZ}djddZ~eeddpddZeeddpddZdjd d!Zdjd"d#Zdjd$d%Zdjd&d'Zdjd(d)Zdjd*d+Zdjd,d-Zdjd.d/Zed0d1d2edjfgdpd3d4Zed0d1d2edjfgdpd5d6Zeeddpd7d8Zeeddpd9d:Zeeddpd;d<Zeeddpd=d>Zeeddpd?d@ZeeddpdAdBZeedCdpdDdEZeedCdpdFdGZeedCdpdHdIZeedJdpdKdLZeedJdpdMdNZeedJdpdOdPZeedJdpdQdRZeedJdpdSdTZeedJdpdUdVZeedJdpdWdXZdjdYdZZdjd[d\Zdjd]d^Zdjd_d`ZdjdadbZdjdcddZdjdedfZdjdgdhZdjdidjZdjdkdlZdjdmdnZdjdodpZdjdqdrZdjdsdtZdjdudvZdjdwdxZdjdydzZdjd{d|Zdjd}d~ZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZÐdjddZĐdjddZŐdjddZƐdjddZǐdjddZȐdjddZɐdjddZʐdjddZːdjddZ̐djddZ͐djddZΐdjddZϐdjddZАdjddZѐdjddZҐdjdÐdĄZӐdjdŐdƄZԐdjdǐdȄZՐdjdɐdʄZ֐djdːd̄Zאdjd͐d΄ZؐdjdϐdЄZِdjdѐd҄ZڐdjdӐdԄZېdjdՐdքZܐdjdאd؄ZݐdjdِdڄZސdjdېd܄ZߐdjdݐdބZdjdߐdZdjddZdjddZdjddZdjddZdjddZdqddZdqddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjdd ZdjddZdjddZdjddZdjddZdjd	d
ZdjddZdjddZdjddZdjddZdrddZdjddZdrddZdjddZ	dsdtd!d"Zdjd#d$Zdrd%d&Z djd'd(Zdjd)d*Zdjd+d,Zdjd-d.Zdjd/d0Zdjd1d2Zdjd3d4Zdjd5d6Zdjd7d8Z	djd9d:Z
djd;d<Zdjd=d>Zdjd?d@ZdjdAdBZdjdCdDZdjdEdFZdjdGdHZdjdIdJZdjdKdLZdjdMdNZdjdOdPZdjdQdRZdjdSdTZdjdUdVZdjdWdXZdjdYdZZdjd[d\Zdjd]d^Zdjd_d`ZdjdadbZdjdcddZdjdedfZ djdgdhZ!djdidjZ"djdkdlZ#djdmdnZ$djdodpZ%djdqdrZ&djdsdtZ'djdudvZ(djdwdxZ)djdydzZ*djd{d|Z+djd}d~Z,djddZ-djddZ.djddZ/djddZ0djddZ1djddZ2djddZ3djddZ4eedCdpddZ5eedCdpddZ6djddZ7djddZ8djddZ9djddZ:djddZ;djddZ<djddZ=djddZ>djddZ?djddZ@djddZAdjddZBdjddZCdjddZDeeddpddZEeeddpddZFdjddZGdjddZHdjddZIdjddZJdjddZKdjddZLdjddZMdjddÄZNeedădpdŐdƄZOdjdǐdȄZPdjdɐdʄZQdjdːd̄ZRdjd͐d΄ZSdjdϐdЄZTdjdѐd҄ZUdjdӐdԄZVdjdՐdքZWdjdאd؄ZXdjdِdڄZYdjdېd܄ZZdjdݐdބZ[djdߐdZ\djddZ]djddZ^djddZ_djddZ`djddZadjddZbdjddZcdjddZddjddZedjddZfdjddZgdjddZhdjddZidjddZjdjddZkdjdd ZldjddZmdjddZndjddZodjddZpdjd	d
ZqdjddZrdjddZsdjddZtdjddZudjddZvdjddZwdjddZxdjddZydjddZzdjddZ{djdd Z|djd!d"Z}djd#d$Z~djd%d&Zdjd'd(Zdjd)d*Zdjd+d,Zdjd-d.Zdjd/d0Zdjd1d2Zdjd3d4Zdjd5d6Zdjd7d8Zdjd9d:Zdjd;d<Zdjd=d>Zdjd?d@ZdldAdBZdjdCdDZdmdEdFZdjdGdHZdldIdJZdjdKdLZeejjejjejjgdjdMdNZdjdOdPZdjdQdRZdjdSdTZdjdUdVZdjdWdXZed*djdYdZZeejjejjejjgdjd[d\Zdjd]d^Zdjd_d`ZdjdadbZdjdcddZdjdedfZdjdgdhZdjdidjZdjdkdlZeedmdjdndoZeedmdjdpdqZdjdrdsZdjdtduZdjdvdwZdjdxdyZdjdzd{ZejerSed|ng d}d~djddZejerned|ng d}d~djddZejered|ng d}d~djddZduddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZÐdjddZĐdjddZŐdjddZƐdjddZǐdjddZȐdjddZɐdjddZʐdjddZːdjddZ̐djddZ͐djddZΐdjddZϐdjddÄZАdjdĐdńZѐdjdƐdǄZҐdjdȐdɄZӐdjdʐd˄ZԐdjd̐d̈́ZՐdjdΐdτZ֐djdАdфZאdjdҐdӄZؐdjdԐdՄZِdjd֐dׄZڐdjdؐdلZېdjdڐdۄZܐdjdܐd݄Zݐdjdސd߄ZސdjddZߐdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjd dZdjddZdjddZdjddZdjdd	Zdjd
dZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjddZdjd d!Zdjd"d#Z djd$d%Zdjd&d'Zdjd(d)Zdjd*d+Zdjd,d-Zdjd.d/Zdjd0d1Zdjd2d3Zdjd4d5Z	djd6d7Z
djd8d9Zdjd:d;Zdjd<d=Zdjd>d?Zdjd@dAZdjdBdCZdjdDdEZdjdFdGZdjdHdIZdjdJdKZdjdLdMZdjdNdOZdjdPdQZdjdRdSZdjdTdUZdjdVdWZdjdXdYZdjdZd[Zdjd\d]Zdjd^d_Zdjd`daZdjdbdcZ djdddeZ!djdfdgZ"djdhdiZ#djdjdkZ$djdldmZ%djdndoZ&djdpdqZ'djdrdsZ(djdtduZ)djdvdwZ*dxdy Z+djdzd{Z,djd|d}Z-djd~dZ.djddZ/djddZ0djddZ1djddZ2djddZ3djddZ4djddZ5djddZ6djddZ7djddZ8djddZ9djddZ:djddZ;djddZ<djddZ=djddZ>djddZ?djddZ@djddZAdjddZBdjddZCdjddZDdjddZEdjddZFdjddZGeeddjddZHeeddjddZIeeddjddZJeeddjddZKeeddjddZLdjddZMdjddZNdjddZOdjdÐdĄZPdjdŐdƄZQdjdǐdȄZRdjdɐdʄZSdjdːd̄ZTdjd͐d΄ZUdjdϐdЄZVdjdѐd҄ZWdjdӐdԄZXdjdՐdքZYdאd؄ ZZdِdڄ Z[dېd܄ Z\dݐdބ Z]dߐd Z^dd Z_dd Z`dd Zaedd ebceddD dvddZdedd ebceddD dvddZeeg ddwddZfeg ddwddZgdjddZhdjd dZidjddZjdjddZkeddgdxdd	Zledgdxd
dZmedgdxddZndjddZodjddZpdd Zqdd Zrdd Zsdd Ztdd Zudd Zvdd Zwd d! Zxd"d# Zyeedmdjd$d%Zzeg d&d'd(gfg d&d)fd)g d*fd+geedmdjd,d-Z{eedmdjd.d/Z|eejej}ejgeedmdjd0d1Z~ed2gd3 ed4ej}d5d6gd7 ed8ej}d9d6gd: fd2gd: ed4ejd5d6gd7 ed8ej}d9d6gd: fd2gd: ed4ej}d;d6gd< ed8ej}d9d6gd: fd2gd: ed4ej}d5d6gd7 ed8ejd9d6gd: fgeedmdjd=d>Zeedmdjd?d@ZeedmdjdAdBZeedmdjdCdDZeedmdjdEdFZeg d&g d*fd+geedmdjdGdHZeedmdjdIdJZdjdKdLZdjdMdNZdjdOdPZdQdR ZdSdT ZdUdV ZdWdX ZdYdZ Zeed[d\d] Zdjd^d_Zd`da Zdbdc Zddde Zdfdg ZdjdhdiZd)S (y  TestShapeInferencer%   rt   c                 C  s(   |  dgg g }| tjj| j| d S )Ny)rc   assertRaisesrl   rm   InferenceErrorrr   r\   r}   r1   r1   r2   test_empty_graph   s   z#TestShapeInference.test_empty_graphopr9   rf   r   c                 K  sF   |  dtjdfgt|ddfi |gg }| |tdtjdg d S )NrN         r;   r   rc   r   FLOATr   r   r!   )r\   r   rf   r}   r1   r1   r2   _identity_prop      z!TestShapeInference._identity_prop	Transposec              	   C  sX   |  dtjdfgtddgdgg ddgg }| j|tdtjdgtt|gd d S 	NXrQ      r   r   Y   r   rQ   permr   rQ   r   opset_imports	rc   r   r   r   r   r!   r   r   r   r\   _r0   r}   r1   r1   r2   test_transpose   s   
z!TestShapeInference.test_transposec              	   C  sd   |  dtjdfgtddgdgg ddgtdtjd g}| j|tdtjdgtt|gd d S r   )	rc   r   r   r   r!   r   r   r   r   r   r1   r1   r2   test_transpose_preexisting     
z-TestShapeInference.test_transpose_preexistingc                 C  sP   |  dtjdfgtddgdggg }| j|tdtjdgtt|gd d S )Nr   r1   r   r   r   r   r   r1   r1   r2   test_transpose_scalar  s   
z(TestShapeInference.test_transpose_scalarc              	   C  sd   |  dtjdfgtddgdgg ddgtdtjdg}| j|tdtjdgtt	|gd	 d S )
Nr   r   r   r   r   r   )r   abr   r   )
rc   r   r   r   r!   rY   r   r   r   r   r   r1   r1   r2   test_transpose_partial!  r   z)TestShapeInference.test_transpose_partialc              	   G  sR   |  dtjdfgtddgdgg ddgtdtjdg}| tjj| j	| d S )Nr   r   r   r   r   r   )r;   r;   r;   )
rc   r   r   r   r!   r   rl   rm   r   rr   r\   r   r}   r1   r1   r2   *test_transpose_preexisting_incorrect_shape.     z=TestShapeInference.test_transpose_preexisting_incorrect_shapec              	   G  sR   |  dtjdfgtddgdgg ddgtdtjdg}| tjj	| j
| d S )Nr   r   r   r   r   r   r   )rc   r   r   r   r!   STRINGr   rl   rm   r   rr   r   r1   r1   r2   )test_transpose_preexisting_incorrect_type7  r   z<TestShapeInference.test_transpose_preexisting_incorrect_typec              	   G  sF   |  dtjdfgtddgdgg ddgg }| tjj| j| d S )Nr   r   r   r   )r   r   r   r   	rc   r   r   r   r   rl   rm   r   rr   r   r1   r1   r2   &test_transpose_incorrect_repeated_perm@  s   z9TestShapeInference.test_transpose_incorrect_repeated_permshape1Sequence[int]shape2c                 C  s   t t t ||t t ||j}| dtj|fdtj|fgt	dddgdggg }| j
|tdtj|gtt|gd d S NrN   r   MatMulzr   )npmatmularangeprodreshaper   rc   r   r   r   r   r!   r   r   r   r\   r0   r   r   expected_out_shaper}   r1   r1   r2    _make_matmul_test_all_dims_knownI  s    
z3TestShapeInference._make_matmul_test_all_dims_knownr   c                 C  s   |  |dd |  |dd |  |dd |  |dd |  |dd |  |dd |  |dd |  |dd	 |  |d
d	 |  |dd |  |dd	 d S )NrQ   r   rQ   rQ   r   )r;   rQ   rQ   r   r   rQ   rQ   r   r   r   rQ   r   rQ   r   )r   r   rQ   r;   r   r   rQ   r   r   rQ   r   )r   r\   r   r0   r1   r1   r2   test_matmul_all_dims_known[  s   z-TestShapeInference.test_matmul_all_dims_knownr   c                 C  s\   |  dtj|fdtj|fgtdddgdggg }| j|tdtj|gtt|gd d S r   r   r   r1   r1   r2   _make_matmul_test_allow_unknownj  s   
z2TestShapeInference._make_matmul_test_allow_unknownc                 C  s   |  |ddd |  |ddd |  |ddd |  |ddd |  |d	dd |  |d	d
d |  |ddd |  |ddd |  |dd d  |  |d d d  d S NrT   r1   r   r   )rQ   r   )r   r   )r   r   )r   N)Nr   r   )r   rQ   r;   r   r   r;   )r   r   r   rQ   r   r   r   r;   )r   r   r1   r1   r2   test_matmul_allow_unknownx  s   z,TestShapeInference.test_matmul_allow_unknownCastc              	   C  V   |  dtjdfgtddgdgtjdgg }| j|tdtjdgtt	|gd d S )NrN   rQ   r   r   r   r   tor   )
rc   r   r   r   UINT8r   r!   r   r   r   r   r1   r1   r2   	test_cast  s   
zTestShapeInference.test_castzIssue #5960c              	   C  sD   |  dtjdfgtddgdgtjdgg }| tjj| j	| d S )NrN   r   r   r   r   )
rc   r   r   r   
COMPLEX128r   rl   rm   r   rr   r   r1   r1   r2   test_cast_to_complex  s   z'TestShapeInference.test_cast_to_complexCastLikec                 C  s\   |  dtjdfdtjdfgtdddgdggg }| j|tdtjdgtt	|gd d S )NrN   r   tNr   r   r   )
rc   r   r   FLOAT16r   r   r!   r   r   r   r   r1   r1   r2   test_cast_like     
z!TestShapeInference.test_cast_likeBitCastc              	   C  r   )NrN   r   r   r   r   r   
rc   r   r   r   INT32r   r!   r   r   r   r   r1   r1   r2   test_bitcast_same_size     
z)TestShapeInference.test_bitcast_same_sizec              	   C  r   )NrN   r1   r   r   r   r   r  r   r1   r1   r2   test_bitcast_scalar  r  z&TestShapeInference.test_bitcast_scalarc              	   C  r   )NrN      r   r   r   r   )
rc   r   r   r   UINT32r   r!   r   r   r   r   r1   r1   r2   test_bitcast_1d  r  z"TestShapeInference.test_bitcast_1dc              	   C  r   )NrN   r   r;   r   r   r   r   )
rc   r   DOUBLEr   r[   r   r!   r   r   r   r   r1   r1   r2   test_bitcast_double_to_int64  r  z/TestShapeInference.test_bitcast_double_to_int64c              	   C  r   )NrN   r      r   r   r   r   )
rc   r   INT8r   r   r   r!   r   r   r   r   r1   r1   r2   test_bitcast_int8_to_uint8  r  z-TestShapeInference.test_bitcast_int8_to_uint8c              	   C  r   )NrN   r   r   r   r   r   )
rc   r   r   r   INT16r   r!   r   r   r   r   r1   r1   r2   test_bitcast_float16_to_int16  r  z0TestShapeInference.test_bitcast_float16_to_int16Col2Imc              
   C     | j dtjdfdtjdfdtjdfgtdg ddggg tdtjdd	tdtjdd
gd}| j|tdtjdgt	t
|gd d S )Ninput)r   r;   r;   output_shaper   kernel_shaper  r  r  r  outputr;   r;   r   r;   rI   r   r   r;   r;   r   rc   r   r   r[   r   r   r   r!   r   r   r   r   r1   r1   r2   test_col2im  &   



zTestShapeInference.test_col2imc              
   C  s   | j dtjdfdtjdfdtjdfgtdg ddgd	d	gd
gg tdtjddtdtjddgd}| j|tdtjdgt	t
|gd d S )Nr  )r   	   r   r  r   r  r  r  r  rQ   stridesr  r   r   r  r  r   r  r   r1   r1   r2   test_col2im_strides  ,   



z&TestShapeInference.test_col2im_stridesc              
   C  s   | j dtjdfdtjdfdtjdfgtdg ddgg d	d
gg tdtjddtdtjddgd}| j|tdtjdgt	t
|gd d S )Nr  )r   r;      r  r   r  r  r  r  )r   r   r   r   padsr  r  r  r  r   r  r   r1   r1   r2   test_col2im_pads9  r&  z#TestShapeInference.test_col2im_padsc              
   C  s   | j dtjdfdtjdfdtjdfgtdg ddgd	d
gdgg tdtjddtdtjddgd}| j|tdtjdgt	t
|gd d S )Nr  r   r   r;   r  r   r  r  r  r  r   r;   	dilationsr  r  rQ   rQ   r  )r   r   r  r  r   r  r   r1   r1   r2   test_col2im_dilationsU  r&  z(TestShapeInference.test_col2im_dilationsc              
   C  r  )Nr  )r   
      r  r   r  r  r  r  r   r   r;   )r   r   r;   r  r   rQ   r   r   r;   r   r  r   r1   r1   r2   test_col2im_5dq  r   z!TestShapeInference.test_col2im_5dConcatc              	   C  `   |  dtjdfdtjdfgtdddgdgddgg }| j|tdtjd	gtt|gd
 d S )NrN   r   r   )   r   r   r6  r   r   axis)r!  r   r   r   r   r   r1   r1   r2   test_concat     
zTestShapeInference.test_concatc              	   G  sP   |  dtjdfddtjdfgtdg ddgd	d
gg }| tjj| j| d S )NrN   r   r   r   NNNr6  rN   r   r   outr   r9  r   r   r1   r1   r2   test_concat_missing_shape  s   

	z,TestShapeInference.test_concat_missing_shapec              	   C  s`   |  dtjdfdtjdfgtdddgdgddgg }| j|tdtjdgtt|gd	 d S )
NrN   rQ   rQ   rQ   r   r6  r   rQ   r9  )rQ   rQ   r   r   r   r   r1   r1   r2   test_concat_3d_axis_2  r<  z(TestShapeInference.test_concat_3d_axis_2c              	   C  r7  )NrN   r   rQ   r   )r   r   r6  r   r   r9  )r   r;   r   r   r   r1   r1   r2   test_concat_param  r<  z$TestShapeInference.test_concat_paramc              	   C  sT   |  dtjdfgtddgdgddgg }| j|tdtjdgtt|gd d S )NrN   rC  r6  r   r   r9  r   r   r   r1   r1   r2   test_concat_param_single_input     
z1TestShapeInference.test_concat_param_single_inputrU   c                 C  sl   |  |dk d | dtjdfdtjdfgtdddgdggg }| j|tdtjd	gt	t
|gd
 d S )N   z'Rank inference is added from Version 14rN   r   r   r   rU   r   NNr   )r   rc   r   r   r[   r   r   r!   r   r   r   r   r1   r1   r2   %test_reshape_dynamic_shape_known_rank  s   
z8TestShapeInference.test_reshape_dynamic_shape_known_rankc                 C  s\   |  dtjdfdtjdfgtdddgdggg }| j|tdtjd gtt	|gd d S )NrN   r   r   MrU   r   r   
rc   r   r   r[   r   r   r!   r   r   r   r   r1   r1   r2   #test_reshape_dynamic_shape_symbolic  r   z6TestShapeInference.test_reshape_dynamic_shape_symbolicc                 C  s\   |  dtjdfdtjd fgtdddgdggg }| j|tdtjd gtt	|gd d S )NrN   r   r   rU   r   r   rL  r   r1   r1   r2   "test_reshape_dynamic_unknown_shape  r   z5TestShapeInference.test_reshape_dynamic_unknown_shapec              	   C  n   | j dtjdfdtjdfgtdddgdggg tdtjddgd}| j|tdtjdgt	t
|gd	 d S )
NrN   r   r   r   rU   r   r   r  r  r   rc   r   r   r[   r   r   r   r!   r   r   r   r   r1   r1   r2   test_reshape_static_shape     
z,TestShapeInference.test_reshape_static_shapec              	   C  n   | j dtjdfdtjdfgtdddgdggg tdtjddgd}| j|tdtjd	gt	t
|gd
 d S )NrN   r   r   r   rU   r   )r   r   r'   r  r   r   rQ  r   r1   r1   r2   "test_reshape_static_shape_inferred  rS  z5TestShapeInference.test_reshape_static_shape_inferredc              	   C  sn   | j dtjdfdtjdfgtdddgdggg tdtjddgd}| j|tdtjdgt	t
|gd	 d S )
NrN   r   r   r   r   r   rU   r   r   r   r   r  r   rQ  r   r1   r1   r2   test_reshape_static_shape_zero  rS  z1TestShapeInference.test_reshape_static_shape_zeroc              	   C  s   |  |dk d | jdtjdfdtjdfgtdddgdgd	d
gg tdtjddgd}| j|tdtjdgt	
t|gd d S )NrG  z"allowzero is added from Version 14rN   r   r   r   r   r   rU   r   r   	allowzerorW  r  r   )r   rc   r   r   r[   r   r   r   r!   r   r   r   r   r1   r1   r2   #test_reshape_static_shape_allowzero  s   

	
z6TestShapeInference.test_reshape_static_shape_allowzeroc                 C  sz   |  dtjdfgtdg dgtdtjdddtdddgd	ggg }| j|tdtjdtd	tjdgt	t
|gd
 d S )NrN   r   Constantr   r   rP  valuerU   r   r   )rc   r   r   r   r   r[   r   r!   r   r   r   r   r1   r1   r2   "test_reshape_static_shape_constant/  s&   	
z5TestShapeInference.test_reshape_static_shape_constantUpsamplec              	     s  dkr0 dtjdfgtddgdgg ddgg  j tdtjdgttgd	 d S j dtjdfd
tj	dfgtddd
gdggg t
d
tj	ddgd  fdd}dkrc|  d S tjj}|  W d    n1 sxw   Y  |j}dt|v sJ d S )Nr8  rN   rQ   r   r   r;   ra  r         ?皙??ffffff?scalesrQ   r   r   r!  r   ri  r   r  c                     *   j  tdtjdgttgd d S Nr   rj  r   r   r!   r   r  r   r   r   r1   r}   r\   r0   r1   r2   call_inferencea  
   
z8TestShapeInference.test_upsample.<locals>.call_inferencer!  Upsample is deprecated)rc   r   r  r   r   r!   r   r   r   r   r   r   rl   r   ValidationError	exceptionr9   r\   r   r0   rp  cmrt  r1   ro  r2   test_upsampleG  s8   



z TestShapeInference.test_upsamplec                   s*  dkr0 dtjdfgtddgdgg ddgg  j tdtjdgttgd	 d S j dtjd
fdtj	dfgtdddgdggg t
dtj	dtjg ddd ddgd  fdd}dkrn|  d S tjj}|  W d    n1 sw   Y  |j}dt|v sJ d S )Nr8  rN   r   ra  r          @re  gffffff@rg  rh  rQ   r   r!  r!  r   rb  ri  rk  rc  <f4dtypeTvalsrawr  c                     rl  rm  rn  r1   ro  r1   r2   rp    rq  zATestShapeInference.test_upsample_raw_data.<locals>.call_inferencer!  rr  )rc   r   r  r   r   r!   r   r   r   r   r   r   arraytobytesr   rl   r   rs  rt  r9   ru  r1   ro  r2   test_upsample_raw_dataq  sD   



z)TestShapeInference.test_upsample_raw_dataExpandc              	   C  rT  )NrN   r   r   r   r   r  r   )rQ   r   r  r  rQ   r   r  r   rc   r   r  r[   r   r   r   r!   r   r   r   r   r1   r1   r2   test_expand  rS  zTestShapeInference.test_expandc              	   C  rO  )
NrN   r1   r   r   r  r   )r   r  r  r   r  r   r1   r1   r2   test_expand_scalar_input  rS  z+TestShapeInference.test_expand_scalar_inputc                 C  s   | j dtjdfdtjdfgtdddgdggg tdtjdtjddgd	d
 ddgd}| j	|t
dtjdgtt|gd d S )NrN   r  r   r   r  r   r   r   <i8r|  Tr~  r  r   r   r   )rc   r   r  r[   r   r   r   r  r  r   r!   r   r   r   r   r1   r1   r2   test_expand_raw_data  s$   
z'TestShapeInference.test_expand_raw_datac                 C  s`   | j dtjdfdtjdfgtdddgdggg g d}| j|tdtjdgtt	|gd	 d S )
NrN   r   rQ   Nr   r   r  r   r  )NrQ   Nr   
rc   r   r  r[   r   r   r!   r   r   r   r   r1   r1   r2   test_expand_dynamic_shape  s   

	
z,TestShapeInference.test_expand_dynamic_shapec                 C  s`   | j dtjdfdtjdfgtdddgdggg g d}| j|tdtjd gtt	|gd d S )	NrN   r  r   )unk__0r  r   r  r   r  r   r1   r1   r2   test_expand_symbolic_shape  s   



z-TestShapeInference.test_expand_symbolic_shapeResizec              	   C  sx  |dkr;| j dtjdfdtjdfgtdddgdggg tdtjddgd	}| j|tdtjd
gt	t
|gd d S |dkr| j dtjdfdtjdfdtjdfdtjdfgtdg ddggg tdtjddgd	}| j|tdtjdgt	t
|gd d S | j dtjdfdtjdfdtjdfgtdg ddggg tdtjddgd	}| j|tdtjdgt	t
|gd d S )Nr1  rN   rb  ri  rk  r  r   rc  r  rj  r      roir  sizesrN   r  ri  r  )r   r;   r  r8  rN   r   r  )rc   r   r  r   r   r   r   r!   r   r   r   r[   r   r1   r1   r2   test_resize_size  s^   











z#TestShapeInference.test_resize_sizeRMSNormalizationc              	   C  s`   |  dtjdfdtjdfgtdddgdgddgg }| j|tdtjdgtt|gd	 d S )
Nr   r   CHWscale)r  r  r  r   rQ   r9  r   r   r   r1   r1   r2   test_rms_normalization/  s   


z)TestShapeInference.test_rms_normalizationc              	   C     |  |dk d | jdtjdfdtjdfdtjdfgtd	g d
dgddgg tdtjddgd}| j|t	dtjdgt
t|gd d S )N   axes is from Version 18rN   rb  r  rk  r  r   r  r  r   r   axesr  r8  r  )rQ   r   r  r8  r   r   rc   r   r  r   r[   r   r   r   r!   r   r   r   r   r1   r1   r2   test_resize_size_axes_2_3?     




z,TestShapeInference.test_resize_size_axes_2_3c              	   C  r  )Nr  r  rN   rb  r  rk  r  r   r  r  r   r   rQ   r  r  r  )rQ   r   r8  r  r   r  r   r1   r1   r2   test_resize_size_axes_3_2R  r  z,TestShapeInference.test_resize_size_axes_3_2c              	   C  r  )Nr  +keep_aspect_ratio_policy is from Version 18rN   r
  r  rk  r  r   r  r  r   
not_largerkeep_aspect_ratio_policyr.  r  r  r   r  r   r1   r1   r2   test_resize_size_not_largere  0   



z.TestShapeInference.test_resize_size_not_largerc              	   C     |  |dk d | jdtjdfdtjdfdtjdfgtd	g d
dgdddgg tdtjddgd}| j|t	dtjdgt
t|gd d S )Nr  3axes & keep_aspect_ratio_policy are from Version 18rN   rb  r  rk  r  r   r  r  r   r   r  r  r  r.  r  )rQ   r   r   r  r   r  r   r1   r1   r2   $test_resize_size_axes_2_3_not_larger  2   


	
z7TestShapeInference.test_resize_size_axes_2_3_not_largerc              	   C  r  )Nr  r  rN   r
  r  rk  r  r   r  r  r   not_smallerr  r.  r  )r  r1  r   r  r   r1   r1   r2   test_resize_size_not_smaller  r  z/TestShapeInference.test_resize_size_not_smallerc              	   C  r  )Nr  r  rN   rb  r  rk  r  r   r  r  r   r   r  r  r.  r  )rQ   r   r  r1  r   r  r   r1   r1   r2   %test_resize_size_axes_2_3_not_smaller  r  z8TestShapeInference.test_resize_size_axes_2_3_not_smallerr0   intpolicydimstuple[int, ...]r  expectedc              	   C  s   | j dtj|fdtjdt| ffdtjt|ffgtdg ddg|dgg tdtjt|f|gd	}| j|t	dtj|gt
t|gd
 d S )NrN   r  rQ   r  r  r  r   r  r  r   )rc   r   r  r   r   r[   r   r   r   r!   r   r   r   )r\   r0   r  r  r  r  r}   r1   r1   r2   "_check_keep_aspect_ratio_precision  s(   

z5TestShapeInference._check_keep_aspect_ratio_precisionc                 C  (   |  |dk d | j|ddddd d S )Nr  r  r    r  r  r  r  r   r  r   r1   r1   r2   2test_resize_keep_aspect_ratio_precision_not_larger     
zETestShapeInference.test_resize_keep_aspect_ratio_precision_not_largerc                 C  r  )Nr  r  r  r  r  r  r   r1   r1   r2   3test_resize_keep_aspect_ratio_precision_not_smaller  s   
zFTestShapeInference.test_resize_keep_aspect_ratio_precision_not_smallerc                 C  s(   |  |dk d | j|ddddd d S )Nr  r  r  )r  )i  r  r  r   r1   r1   r2   6test_resize_keep_aspect_ratio_precision_non_unit_scale  r  zITestShapeInference.test_resize_keep_aspect_ratio_precision_non_unit_scalec              	   C  s   |  |dk d | jdtjdfdtjdfdtjdfgtd	g d
dggg tdtjddgd}| j|tdtjdgt	
t|gd d S )Nr  roi input is from Version 11rN   rb  r  r  ri  rk  r  rN   r  ri  r   rc  r  rj  r   r   rc   r   r  r   r   r   r   r!   r   r   r   r   r1   r1   r2   test_resize_scale'  s    



z$TestShapeInference.test_resize_scalec              	   C     |  |dk d | jdtjdfdtjdfdtjdfgtd	g d
dgddgg tdtjddgd}| j|tdtjdgt	
t|gd d S )Nr  r  rN   rb  r  r  ri  r   r  r  r   r   r  )rf  rg  r  rj  r   r  r   r1   r1   r2   test_resize_scale_axes_2_3<  r  z-TestShapeInference.test_resize_scale_axes_2_3c              	   C  r  )Nr  r  rN   rb  r  r  ri  r   r  r  r   r  r  )rg  rf  r  rj  r   r  r   r1   r1   r2   test_resize_scale_axes_3_2O  r  z-TestShapeInference.test_resize_scale_axes_3_2c                 C  s   |  |dk d | jdtjdfdtjdfdtjdfgtd	g d
dggg tdtjdtjg ddd	 ddgd}| j
|tdtjdgtt|gd d S )Nr  r  rN   r   r  r  ri  rk  r  r  r   rx  r{  r|  Tr~  r  rz  r   )r   rc   r   r  r   r   r   r   r  r  r   r!   r   r   r   r   r1   r1   r2   test_resize_scale_raw_datab  s,   



z-TestShapeInference.test_resize_scale_raw_datari  tuple[float, ...]expected_last_dimc              	   C  s   |dkrdt jdfdt jdfdt jdfg}tdg d	d
g}ndt jdfdt jdfg}tdddgd
g}| j||gg tdt jd|gd}| j|td
t jddd|fgt	t
|gd d S )Nr  rN   )r   r   r   r  r  r  ri  rk  r  r  r   r  r   r   )r   r  r   r   rc   r   r   r!   r   r   r   )r\   r0   ri  r  inputsnoder}   r1   r1   r2   _check_resize_scale_precision}  s0   	





z0TestShapeInference._check_resize_scale_precisionc              	   C  s,   dD ]}|  |dddt|fd|  qd S )Nr   rd  r  )r  float)r\   r   r0   r  r1   r1   r2   %test_resize_scale_precision_large_dim  s
   z8TestShapeInference.test_resize_scale_precision_large_dimc                 C  s   |  |dk d | jdtjdfdtjdfdtjdfd	tjd
fgtdg ddggg tdtjdtj	g ddd
 ddtd	tjd
tj	g dd
 ddgd}| j|tdtjdgtt|gd d S )Nr  r  rN   r   r  r  ri  rk  r  r   r  r  r   rx  r{  r|  Tr~  r  r  rz  r   )r   rc   r   r  r   r[   r   r   r   r  r  r   r!   r   r   r   r   r1   r1   r2   +test_resize_scale_and_size_but_one_is_empty  s<   




z>TestShapeInference.test_resize_scale_and_size_but_one_is_emptyc                 C  s   |  |dkd | jdtjdfdtjdfdtjdfd	tjd
fgtdg ddggg td	tjd
tj	g ddd
 ddgd}| j|tdtjdgtd|gd d S )Nr  z#This test only works for Version 11rN   r   r  r  ri  r  r  rk  r  r  r   )rQ   r  r  r1  r  r|  Tr~  r  r  r   )r   rc   r   r  r   r[   r   r   r   r  r  r   r!   r   r   r   r1   r1   r2   #test_resize_opset11_scales_is_empty  s4   




z6TestShapeInference.test_resize_opset11_scales_is_emptyShapec                 C  P   |  dtjdfgtddgdggg }| j|tdtjdgtt	|gd d S )NrN   r   r  r   r   r   
rc   r   r   r   r   r!   r[   r   r   r   r   r1   r1   r2   
test_shape  s   
zTestShapeInference.test_shapec              	   C  d   |  |dk d | dtjdfgtddgdgddgg }| j|tdtjd	gt	t
|gd
 d S )Nr'  !start and end are from Version 15rN   r   r  r   r   startr   r   r   rc   r   r   r   r   r!   r[   r   r   r   r   r1   r1   r2   test_shape_start_1     
z%TestShapeInference.test_shape_start_1c              	   C  r  )Nr'  r  rN   r   r  r   r   endr   r   r  r   r1   r1   r2   test_shape_end_1
  r  z#TestShapeInference.test_shape_end_1c              	   C  r  )Nr'  r  rN   r   r  r   r'   r  r  r   r  r   r1   r1   r2   test_shape_negative_start  r  z,TestShapeInference.test_shape_negative_startc              	   C  r  )Nr'  r  rN   r   r  r   r  r   r   r  r   r1   r1   r2   test_shape_clip1&  r  z#TestShapeInference.test_shape_clip1c              	   C  r  )Nr'  r  rN   r   r  r   r1  r  r   r   r  r   r1   r1   r2   test_shape_clip24  r  z#TestShapeInference.test_shape_clip2Sizec                 C  r  )NrN   r   r  r   r1   r   r  r   r1   r1   r2   	test_sizeB  s   
zTestShapeInference.test_sizeGatherc                 C  s\   |  dtjdfdtjdfgtdddgdggg }| j|tdtjdgtt	|gd d S )	NrN   r   r   ir   r  r   r   r   
rc   r   r   r[   r   r   r!   r   r   r   r   r1   r1   r2   test_gatherM  r   zTestShapeInference.test_gatherc              	   C  s`   |  dtjdfdtjdfgtdddgdgddgg }| j|tdtjd	gtt	|gd
 d S )NrN   )r   r   r;   r  r   r  r   r   r9  )r   r   rQ   r;   r   r  r   r1   r1   r2   test_gather_axis1Z  r<  z$TestShapeInference.test_gather_axis1c                 C  s\   |  dtjdfdtjdfgtdddgdggg }| j|tdtjdgtt	|gd d S )NrN   r   r  r1   r  r   r   r  r   r1   r1   r2   test_gather_into_scalarg  r   z*TestShapeInference.test_gather_into_scalarGatherElementsc              	   C  s`   |  dtjdfdtjdfgtdddgdgddgg }| j|tdtjdgtt	|gd d S )	NrN   r/  r  r  r   r   r9  r   r  r   r1   r1   r2   test_gather_elementst  r<  z'TestShapeInference.test_gather_elementsc              	   C  s`   |  dtjdfdtjdfgtdddgdgddgg }| j|tdtjdgtt	|gd	 d S )
NrN   r$  r  r   r  r   r   r9  r   r  r   r1   r1   r2   test_gather_elements_axis0  r<  z-TestShapeInference.test_gather_elements_axis0Scatterc                 C  h   |dkr-|  tjj}| | W d    n1 sw   Y  |j}dt|v s+J d S | | d S Nr  zScatter is deprecated)r   rl   r   rs  _test_scatterrt  r9   r\   r   r0   rv  rt  r1   r1   r2   test_scatter     zTestShapeInference.test_scatterc                 C  sf   |  dtjdfdtjdfdtjdfgtdg ddggg }| j|tdtjdgtt	|gd	 d S )
NrN   r$  r  r   ur  rN   r  r  r   r   r  r\   r0   r}   r1   r1   r2   r    s   


	
z TestShapeInference._test_scatterc                 C  r  r  )r   rl   r   rs  _test_scatter_axis1rt  r9   r  r1   r1   r2   test_scatter_axis1  r   z%TestShapeInference.test_scatter_axis1c              	   C  sj   |  dtjdfdtjdfdtjdfgtdg ddgd	d
gg }| j|tdtjdgtt	|gd d S )NrN   r  r  r   r  r  r  r   r   r9  r   r  r  r1   r1   r2   r    s   


	
z&TestShapeInference._test_scatter_axis1ScatterElementsc                 C  sf   |  dtjdfdtjdfdtjdfgtdg ddggg }| j|tdtjdgtt	|gd	 d S )
NrN   r$  r  r   r  r  r  r   r   r  r   r1   r1   r2   test_scatter_elements     


	
z(TestShapeInference.test_scatter_elementsc              	   C  sj   |  dtjdfdtjdfdtjdfgtdg ddgd	d
gg }| j|tdtjdgtt	|gd d S )NrN   r  r  r   r  r  r  r   r   r9  r   r  r   r1   r1   r2   test_scatter_elements_axis1  s   


	
z.TestShapeInference.test_scatter_elements_axis1	ScatterNDc                 C  sf   |  dtjdfdtjdfdtjdfgtdg dd	ggg }| j|td	tjdgtt	|gd
 d S )NrN   r   r;   r  indicesr   r   rQ   updatesr   r   r  r
  )rN   r  r  r   r   r  r   r1   r1   r2   test_scatternd  r  z!TestShapeInference.test_scatterndc                 C  s   |  dtjdfdtjdfdtjdfdtjdfgtd	ddgd
gtdg ddggg }| j|td
tjd tdtjd gtt	|gd d S )NrN   r  r  r  r  r  r   rJ  rU   
x_reshapedr
  )r  r  r  r   r   r  r   r1   r1   r2   test_scatternd_noshape  s$   




z)TestShapeInference.test_scatternd_noshapec              	   C  sj   |  dtjdfdtjdfdtjdfgtdg dd	gd
dgg }| j|td	tjdgtt	dgd d S )N
past_cacherQ   r     @   update)rQ   r  r1  r  write_indicesr   TensorScatter)r  r  r  present_cacherQ   r9     r   r  r   r1   r1   r2   test_tensor_scatter  s,   



z&TestShapeInference.test_tensor_scatterSqueezec              	   C  s   |dkr.|  dtjdfgtdddg ddgg }| j|tdtjdgtt|gd	 d S | j dtjdfd
tj	dfgtddd
gdgg t
d
tj	ddgd}| j|tdtjdgtt|gd	 d S )Nr  rN   r   r   r   r   rQ   r   r  r   )r   rQ   r   r;   r  r  r   r  rk  r  )rc   r   r   r   r   r!   r   r   r   r[   r   r   r1   r1   r2   test_squeeze,  s2   



zTestShapeInference.test_squeezeStringConcatc                 C  sZ   |  dtjdfdtjdfgtdddgdgg }| j|tdtjdgtt|gd d S )NrN   r   r   r   r   r   	rc   r   r   r   r   r!   r   r   r   r   r1   r1   r2   test_stringconcatK     


z$TestShapeInference.test_stringconcatc                 C  sZ   |  dtjdfdtjdfgtdddgdgg }| j|tdtjdgtt|gd d S )NrN   r   r   )r   r   r   r   r   r   r!  r   r1   r1   r2   test_stringconcat_broadcasting[  r#  z1TestShapeInference.test_stringconcat_broadcastingRegexFullMatchc              	   C  T   |  dtjdfgtddgdgddgg }| j|tdtjdgtt	|gd d S )NrN   rj  r%  r   ^[A-Z][a-z]*$patternr   
rc   r   r   r   r   r!   BOOLr   r   r   r   r1   r1   r2   test_regex_full_matchk  rF  z(TestShapeInference.test_regex_full_matchc              	   C  r&  )NrN   r1   r%  r   r'  r(  r   r*  r   r1   r1   r2   !test_regex_full_match_empty_shapex  rF  z4TestShapeInference.test_regex_full_match_empty_shapec                 C  sR   |  dtjdfgtddgdgg }t }d|_d|_| |tdtjdg d S )NrN   r  r  r   r  r  r  	rc   r   r   r   r   r.   r0   r   r!   r\   r}   operatorsetidr1   r1   r2   test_squeeze_no_axes_opset11  s   
z/TestShapeInference.test_squeeze_no_axes_opset11c                 C  sX   |  dtjdfgtddgdgg }t }d|_d|_| j|tdtjd g|gd d S )NrN   )r   r   r   NrQ   r   r  r   r  r  r   r.  r/  r1   r1   r2   *test_squeeze_no_axes_dynamic_input_opset11  s   

z=TestShapeInference.test_squeeze_no_axes_dynamic_input_opset11c              	   C  ^   | j dtjdfdtjdfgtdddgdgg tdtjddgd}| |tdtjd	g d S )
NrN   r  r  rk  	Unsqueezer   )r   r   r   r;   r  )r   r   r   r   rQ   r   rc   r   r   r[   r   r   r   r!   r   r1   r1   r2   test_unsqueeze_regular     z)TestShapeInference.test_unsqueeze_regularc              	   C  r3  )
NrN   r3  r  r   r4  r   )r   r   r  r   r   r   r;   r   r5  r   r1   r1   r2   test_unsqueeze_unsorted_axes  r7  z/TestShapeInference.test_unsqueeze_unsorted_axesc              	   C  r3  )
NrN   r3  r  r   r4  r   )r   r'   r  r8  r5  r   r1   r1   r2   test_unsqueeze_negative_axes  r7  z/TestShapeInference.test_unsqueeze_negative_axesc              	   C  s^   | j dtjdfdtjdfgtdddgdgg tdtjddgd}| |tdtjdg d S )	NrN   r1   r  r4  r   r'   r  r  r5  r   r1   r1   r2   test_unsqueeze_scalar  r7  z(TestShapeInference.test_unsqueeze_scalarc                 C  sX   |  dtjdfdtjdfdtjdfgtdg ddggg }| |tdtjd	g d S )
NrN   )r   rQ   r   startsr  endsSlicerN   r=  r>  r   r=  rc   r   r   r[   r   r   r!   r   r1   r1   r2   test_slice_without_input_shape     


	z1TestShapeInference.test_slice_without_input_shapec                 C  s   | j dtjdfdtjdfdtjdfgtdg ddggg tdtjdtjd	d
gdd ddtdtjddgd}| 	|t
dtjdg d S )NrN   r  r=  r   r>  r?  r@  r   r   r   r  r|  Tr~  r/  r  r   rc   r   r   r[   r   r   r   r  r  r   r!   r   r1   r1   r2   test_slice_with_input_shape  s(   


z.TestShapeInference.test_slice_with_input_shapec              
   C  sx   | j dtjdfdtjdfdtjdfgtdg ddggg tdtjdd	tdtjdd
gd}| |tdtjdg d S )NrN   )r   r   r   r=  r   r>  r?  r@  r   )r   r   r   rV  r  )r   Nr   r5  r   r1   r1   r2   1test_slice_with_input_shape_containing_dim_params     


zDTestShapeInference.test_slice_with_input_shape_containing_dim_paramsc                 C  s   | j dtjdfdtjdfdtjdfdtjd fdtjdfgtdg d	d
ggg tdtjddtdtjddtdtjddgd}| |td
tjdg d S )NrN   r;   r  r8  r=  r   r>  r  stepsr?  rN   r=  r>  r  rI  r   rY  )rQ   r  r  )r   r   r   r  r   rQ   rQ   r5  r   r1   r1   r2   !test_slice_with_input_shape_steps	  "   




z4TestShapeInference.test_slice_with_input_shape_stepsc                 C  s   | j dtjdfdtjdfdtjdfdtjdfdtjd fgtdg d	d
ggg tdtjddtdtjddtdtjddgd}| |td
tjdg d S )NrN   )r   r  rQ   r=  r   r>  r  rI  r?  rJ  r   r   r   r/  )r   rQ   r  )r   r  rQ   r5  r   r1   r1   r2    test_slice_with_input_shape_axes  rM  z3TestShapeInference.test_slice_with_input_shape_axesc                 C  s   | j dtjdfdtjdfdtjdfdtjdfgtdg dd	gg tdtjdd
tdtjddtdtjdd
gd}| |td	tjdg d S )NrN   r  r=  r   r>  r  r?  rN   r=  r>  r  r   rN  r/  r  r   r5  r   r1   r1   r2   test_slice_unsorted_axes3      



z+TestShapeInference.test_slice_unsorted_axesc                 C     | j dtjdfdtjdfdtjdfdtjdfgtdg dd	gg tdtjdd
tdtjddtdtjddgd}| |td	tjdg d S NrN   r  r=  r   r>  r  r?  rP  r   rN  )   iU  r   r   r  r/  r5  r   r1   r1   r2   test_slice_giant_numberG  rR  z*TestShapeInference.test_slice_giant_numberc                 C     | j dtjdfdtjdfdtjdfdtjdfdtjdfgtdg d	d
gg tdtjddtdtjddtdtjddtdtjddgd}| |td
tjdg d S )NrN   r  r=  r   r>  r  rI  r?  rJ  r   rN  )rU  rU  rV  )r   rU  r  r   r5  r   r1   r1   r2   test_slice_giant_step[  s$   




z(TestShapeInference.test_slice_giant_stepc                 C  rS  )NrN   r  r=  r   r>  r  r?  rP  r   rN  )rU  r'   rV  r  r   r5  r   r1   r1   r2   test_slice_negative_endq  s$   




z*TestShapeInference.test_slice_negative_endc                 C  rS  )NrN   r  r=  r   r>  r  r?  rP  r   )r   )rU  r   rV  r  r/  r5  r   r1   r1   r2   test_slice_negative_start  s$   




z,TestShapeInference.test_slice_negative_startc                 C  rX  )NrN   r  r=  r   r>  r  rI  r?  rJ  r   r   r   )rU  r   rV  )r   r'   r  r   r5  r   r1   r1   r2   test_slice_negative_step  s(   





z+TestShapeInference.test_slice_negative_stepc                 C  s   | j dtjdfdtjdfdtjdfdtjdfgtdg dd	gg tdtjddtdtjdd
tdtjddgd}| |td	tjdg d S )NrN   rC  r=  r  r>  r  r?  rP  r   )rU  r  )r   r   r5  r   r1   r1   r2   test_slice_variable_copy  rR  z+TestShapeInference.test_slice_variable_copyc                 C  rS  rT  )rc   r   r  r  r   r   r   r!   r   r1   r1   r2   test_slice_variable_input_types  rR  z2TestShapeInference.test_slice_variable_input_typesc                 C  s   | j dtjdfdtjdfdtjdfdtjdfdtjdfgtdg d	d
gg tdtjddtdtjddtdtjddtdtjddgd}| |td
tjdg dS )zGSlice on empty dimension with positive step should produce dim_value=0.rN   r   r  r=  r  r>  r  rI  r?  rJ  r   r  r  Nr5  r   r1   r1   r2   "test_slice_empty_dim_positive_step  $   




z5TestShapeInference.test_slice_empty_dim_positive_stepc                 C  s   | j dtjdfdtjdfdtjdfdtjdfdtjdfgtdg d	d
gg tdtjddtdtjddtdtjddtdtjddgd}| |td
tjdg dS )zIRegression test for issue #7735: std::clamp UB on empty dim with step=-1.rN   ra  r=  r  r>  r  rI  r?  rJ  r   r  r;  r  Nr5  r   r1   r1   r2   "test_slice_empty_dim_negative_step  rc  z5TestShapeInference.test_slice_empty_dim_negative_stepc                 C  s   | j dtjdfdtjdfdtjdfdtjdfdtjdfgtddgd	gtd
g ddggg tdtjddtdtjddtdtjddtdtjddgd}| |td	tjdtdtjdg dS )zEShape(scalar) produces 0-length output; Slice on it should not crash.rN   r1   r=  r  r>  r  rI  r  r   r?  )r   r=  r>  r  rI  r   r  r  Nr5  r   r1   r1   r2   test_slice_scalar_shape_output	  s.   




z1TestShapeInference.test_slice_scalar_shape_outputc                 C  s`   |  dtjdfdtjdfgtdddgdg dg dg d	d
gg }| |tdtjdg d S )NrN   r   r   r;   r  r8  r   r;   r   rQ   r   r   Convr   r   r   r   r   r   r   rK  r   r   rQ   r)  r-  r#  r   r;   r   r   r   r   r   r1   r1   r2   	test_conv)	  $   


zTestShapeInference.test_convc              	   C  R   |  dtjdfdtjdfgtdddgddgdgg }| |tdtjd	g d S )
NrN   r   r   )2   r   rQ   rh  r   r   r,  )r   rp  r   r   r   r1   r1   r2   test_conv_1d_simple?	     

z&TestShapeInference.test_conv_1d_simplec              	   C  T   |  dtjdfdtjdfgtdddgdg ddgg }| |tdtjd	g d S )
NrN   r   r   r  r  r  r   rp  r   r   r   r   rh  r   r   rQ   r   r,  r   rp  r  r   rQ   r   r   r1   r1   r2   test_conv_dilationsL	     

z&TestShapeInference.test_conv_dilationsc              	   C  rs  )
NrN   rt  r   ru  rh  r   rv  r"  r   rp  r  r   rQ   r   r   r1   r1   r2   test_conv_stridesY	  ry  z$TestShapeInference.test_conv_stridesrh  r   c              	   C  ^   |  dtjdfdtjdfgtdddgdddgd	gg }| jtjj| j|t	
t|gd
 d S )NrN   r  r   r   r   r   r   rh  r   r   r   r"  r   rc   r   r   r   r   rl   rm   r   rr   r   r   r   r   r1   r1   r2   test_conv_zero_stridesf	     


z)TestShapeInference.test_conv_zero_stridesc              	   C  r|  )NrN   r  r   r}  rh  r   r'   r   r"  r   r~  r   r1   r1   r2   test_conv_negative_stridesw	  r  z-TestShapeInference.test_conv_negative_stridesc              	   C  rs  )
NrN   r   r   r8  r  r   r   ru  rh  r   r   r   rQ   r   r   rQ   r(  r   rp  r  r  r  r   r   r1   r1   r2   test_conv_pads	  ry  z!TestShapeInference.test_conv_padsc              	   C  P   |  dtjdfdtjdfgtdddgdddgg }| |tdtjd	g d S )
NrN   r  r   rp  r   r   r   rQ   rh  r   
SAME_UPPER)auto_pad)r   rp  r8  r  r   r   r   r1   r1   r2   test_conv_auto_pad	     

z%TestShapeInference.test_conv_auto_padc              
   C  V   |  dtjdfdtjdfgtdddgddg dd	gg }| |tdtjd
g d S )NrN   r  r   r  rh  r   r  rQ   rQ   r   r  r#  )r   rp  r   r   r   r   r   r1   r1   r2   test_conv_auto_pads	  s   

z&TestShapeInference.test_conv_auto_padsc              
   C  r  )NrN   )r   r   A   r  ?   r   r  rh  r   r  r   )r  r-  )r   rp  r  r  r  r   r   r1   r1   r2   test_conv_auto_pad_dilation	  s   

z.TestShapeInference.test_conv_auto_pad_dilationc              	   C  r  )
NrN   rt  r   r   r   r  r  r  rh  r   r   groupr   r   r   r   r   r   r   r1   r1   r2   test_conv_group	  r  z"TestShapeInference.test_conv_groupc              	   C  ro  )
NrN   r   r   )rp  r   r;   rh  r   rQ   r"  )r   rp  r   r   r   r1   r1   r2   test_conv_only_one_pos	  rr  z)TestShapeInference.test_conv_only_one_posc              	   C  rs  )
NrN   r   r   Nr  r   r   ru  rh  r   r  r(  r   rp  Nr  r  r   r   r1   r1   r2   test_conv_partial_missing_shape	  s   

z2TestShapeInference.test_conv_partial_missing_shapec              	   C  sT   |  dtjdfdtjdfgtdddgdg ddgg }| |tdtjd g d S )	NrN   r  r   rp  r   Nr   r   rh  r   r  r(  r   r   r1   r1   r2   &test_conv_partial_missing_weight_shape	  ry  z9TestShapeInference.test_conv_partial_missing_weight_shape)opset1_to_10r1  )opset19   latestc              	   C  X   |  dtjdfdtjdfgtdddgdgg }| jtjjd| j|t	
t|gd d S )	NrN   )r   r   r  r  w)r;   r   r   r   r   rh  r   weight tensorr   rc   r   r   r   assertRaisesRegexrl   rm   r   rr   r   r   r   r   r1   r1   r2   4test_conv_weight_more_spatial_dims_than_input_raises	     


zGTestShapeInference.test_conv_weight_more_spatial_dims_than_input_raisesc              	   C  r  )	NrN   )r   r   r  r  r  r  )r;   r   r   r   rh  r   r  r   r  r   r1   r1   r2   5test_conv_weight_fewer_spatial_dims_than_input_raises
  r  zHTestShapeInference.test_conv_weight_fewer_spatial_dims_than_input_raisesc              	   C  r|  )NrN   r  r   r}  rh  r   r   r   r,  r   r~  r   r1   r1   r2   test_conv_zero_dilations:
  r  z+TestShapeInference.test_conv_zero_dilationsc              	   C  r|  )NrN   r  r   r}  rh  r   r'   r   r,  r   r~  r   r1   r1   r2   test_conv_negative_dilationsK
  r  z/TestShapeInference.test_conv_negative_dilationsc              	   C  ^   |  dtjdfdtjdfgtdddgdg ddgg }| jtjj| j|t	
t|gd	 d S )
NrN   r  r   r}  rh  r   r'   r   r   r   r(  r   r~  r   r1   r1   r2   test_conv_negative_pads\
  r  z*TestShapeInference.test_conv_negative_padsc                 C  V   |  dtjdfdtjdfgtdddgdgg }| jtjj| j|t	
t|gd d S )NrN   )r   r   r   )r   r   r   rh  r   r   r~  r   r1   r1   r2   test_conv_input_too_few_dimsm
  s   


z/TestShapeInference.test_conv_input_too_few_dimsc              	   C  r|  )NrN   r  r   r}  rh  r   r   r   r  r   r~  r   r1   r1   r2   test_conv_zero_kernel_shape~
  r  z.TestShapeInference.test_conv_zero_kernel_shapec              	   C  r|  )NrN   r  r   r}  rh  r   r'   r   r  r   r~  r   r1   r1   r2   test_conv_negative_kernel_shape
  r  z2TestShapeInference.test_conv_negative_kernel_shapeMaxPoolc              	   C  sT   |  dtjdfgtddgdgddgdgg }| jtjj| j|t	
t|gd d S )	Nr   r  r  r   r   r   r  r   r~  r   r1   r1   r2   test_maxpool_zero_kernel_shape
  s   
z1TestShapeInference.test_maxpool_zero_kernel_shapec              
   C  sl   |dk r	|  d | dtjdfgtddgdgddgdd	gd
gg }| jtjj| j	|t
t|gd d S )Nr1  z)dilations not supported before MaxPool-10r   r  r  r   r   r'   r   r  r-  r   )skipTestrc   r   r   r   r   rl   rm   r   rr   r   r   r   r   r1   r1   r2   test_maxpool_negative_dilations
  s(   
	
z2TestShapeInference.test_maxpool_negative_dilationsc              
   C  sZ   |  dtjdfgtddgdgddgg ddgg }| jtjj| j|t	
t|gd d S )	Nr   r  r  r   r   r  r  r)  r   r~  r   r1   r1   r2   test_maxpool_negative_pads
  $   	
z-TestShapeInference.test_maxpool_negative_padsConvTransposec                 C  r  )NrN   r   r   r   r   r  r   r   r   r   r   r  r   r   r~  r   r1   r1   r2   0test_conv_transpose_weight_spatial_rank_mismatch
  s   


zCTestShapeInference.test_conv_transpose_weight_spatial_rank_mismatchc              	   C  r|  )NrN   r  r  r}  r  r   r'   r   r,  r   r~  r   r1   r1   r2   &test_conv_transpose_negative_dilations
  r  z9TestShapeInference.test_conv_transpose_negative_dilationsc              	   C  r|  )NrN   r  r  r}  r  r   r   r   r"  r   r~  r   r1   r1   r2    test_conv_transpose_zero_strides   r  z3TestShapeInference.test_conv_transpose_zero_stridesc              	   C  r  )
NrN   r  r  r}  r  r   r  r(  r   r~  r   r1   r1   r2   !test_conv_transpose_negative_pads  r  z4TestShapeInference.test_conv_transpose_negative_padsc              
   C  sd   |  dtjdfdtjdfgtdddgdddgdd	gd
gg }| jtjj| j|t	
t|gd d S )NrN   r  r  r}  r  r   rQ   r'   r   )r#  output_paddingr   r~  r   r1   r1   r2   +test_conv_transpose_negative_output_padding"  s(   

	
z>TestShapeInference.test_conv_transpose_negative_output_paddingc              	   C  r|  )NrN   r  r  r}  r  r   r'   r  )r  r   r~  r   r1   r1   r2   )test_conv_transpose_negative_output_shape;  s&   


z<TestShapeInference.test_conv_transpose_negative_output_shapec              	   C  r|  )NrN   r  r  r}  r  r   r   r   r  r   r~  r   r1   r1   r2   %test_conv_transpose_zero_kernel_shapeS  r  z8TestShapeInference.test_conv_transpose_zero_kernel_shapec                 C  X   |  dtjdfdtjdfdtjdfgtdg dd	ggg }| |td	tjd
g d S )NQ)Bq_num_headsq_seq_length	head_sizeK)r  kv_num_heads
kv_seq_lenr  V)r  r  r  v_head_size	Attentionr  r  r  r   )r  r  r  r  r   r   r1   r1   r2   test_attention_4dd  s>   z$TestShapeInference.test_attention_4dc                 C  4   t jd}| |tdtjdtdtjdg d S )Naj  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4,64] Q, float[2,4,64] K, float[2,4,64] V)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=4, kv_num_heads=4, update_rule="linear"
                > (Q, K, V)
            }
            r  rQ   r   r  present_staterQ   r      r  rl   parserparse_modelr   r!   r   r   r\   modelr1   r1   r2   test_linear_attention_basic_mha     z2TestShapeInference.test_linear_attention_basic_mhac                 C  r  )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4,64] Q, float[2,4,64] K, float[2,4,64] V,
               float[2,4,64] decay, float[2,4,4] beta)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=4, kv_num_heads=4, update_rule="gated_delta"
                > (Q, K, V, "", decay, beta)
            }
            r  r  r  r  r  r  r1   r1   r2   !test_linear_attention_gated_delta     z4TestShapeInference.test_linear_attention_gated_deltac                 C  r  )Nak  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4,128] Q, float[2,4,32] K, float[2,4,32] V)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=8, kv_num_heads=2, update_rule="linear"
                > (Q, K, V)
            }
            r  )rQ   r   r  r  )rQ   rQ   r  r  r  r  r1   r1   r2   test_linear_attention_gqa  s   z,TestShapeInference.test_linear_attention_gqac                 C  r  )Naj  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4,64] Q, float[2,4,16] K, float[2,4,16] V)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=4, kv_num_heads=1, update_rule="linear"
                > (Q, K, V)
            }
            r  r  r  )rQ   r   r  r  r  r  r1   r1   r2   test_linear_attention_mqa  r  z,TestShapeInference.test_linear_attention_mqac                 C  s4   t jd}| |tdtjdtdtjdg d S )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,1,64] Q, float[2,1,64] K, float[2,1,64] V,
               float16[2,4,16,16] past_state,
               float[2,1,64] decay, float[2,1,4] beta)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=4, kv_num_heads=4, update_rule="gated_delta"
                > (Q, K, V, past_state, decay, beta)
            }
            r  )rQ   r   r  r  r  )rl   r  r  r   r!   r   r   r   r  r1   r1   r2   %test_linear_attention_with_past_state  s   z8TestShapeInference.test_linear_attention_with_past_statec                 C  r  )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,3,16] Q, float[2,3,16] K, float[2,3,16] V,
               float[2,3,2] decay)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=2, kv_num_heads=2, update_rule="gated"
                > (Q, K, V, "", decay)
            }
            r  rQ   r   r  r  rQ   rQ   r  r  r  r  r1   r1   r2   $test_linear_attention_per_head_decay  r  z7TestShapeInference.test_linear_attention_per_head_decayc                 C  r  )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,3,16] Q, float[2,3,16] K, float[2,3,16] V,
               float[2,3,16] decay)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=2, kv_num_heads=2, update_rule="gated"
                > (Q, K, V, "", decay)
            }
            r  r  r  r  r  r  r1   r1   r2   &test_linear_attention_per_keydim_decay%  r  z9TestShapeInference.test_linear_attention_per_keydim_decayc                 C  r  )Naj  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[B,T,64] Q, float[B,T,64] K, float[B,T,64] V)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=4, kv_num_heads=4, update_rule="linear"
                > (Q, K, V)
            }
            r  )r  Tr  r  )r  r   r  r  r  r  r1   r1   r2   test_linear_attention_dynamic_T>  s   z2TestShapeInference.test_linear_attention_dynamic_Tc                 C  r  )Nam  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4,64] Q, float[2,4,64] K, float[2,4,VLast] V)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=4, kv_num_heads=4, update_rule="linear"
                > (Q, K, V)
            }
            r  rQ   r   Nr  )rQ   r   r  Nr  r  r1   r1   r2   ,test_linear_attention_unknown_value_last_dimV  r  z?TestShapeInference.test_linear_attention_unknown_value_last_dimc                 C  sx   |  dtjd fdtjd fdtjd fdtjdfgtdg ddd	gd
d
ddgg }| |tdtjdtd	tjdg d S )Nr  r  r  
past_stater  LinearAttention)r  r  r  r  r  r  r   linear)r  r  update_rule)rQ   Nr  r   r   r1   r1   r2   1test_linear_attention_unknown_qkv_with_past_stateo  s2   




zDTestShapeInference.test_linear_attention_unknown_qkv_with_past_statec                 C  $   t jd}| t jj| j| d S )Nal  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4,4,16] Q, float[2,4,64] K, float[2,4,64] V)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=4, kv_num_heads=4, update_rule="linear"
                > (Q, K, V)
            }
            rl   r  r  r   rm   r   rr   r  r1   r1   r2   &test_linear_attention_query_rank_not_3     z9TestShapeInference.test_linear_attention_query_rank_not_3c                 C  r  )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,1,64] Q, float[2,1,64] K, float[2,1,64] V,
               float[2,4,16] past_state)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=4, kv_num_heads=4, update_rule="linear"
                > (Q, K, V, past_state)
            }
            r  r  r1   r1   r2   +test_linear_attention_past_state_rank_not_4     z>TestShapeInference.test_linear_attention_past_state_rank_not_4c                 C  r  )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,3,16] Q, float[2,3,16] K, float[2,3,16] V,
               float[2,3] decay)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=2, kv_num_heads=2, update_rule="gated"
                > (Q, K, V, "", decay)
            }
            r  r  r1   r1   r2   &test_linear_attention_decay_rank_not_3  r  z9TestShapeInference.test_linear_attention_decay_rank_not_3c                 C  r  )Naj  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4,96] Q, float[2,4,64] K, float[2,4,64] V)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=6, kv_num_heads=4, update_rule="linear"
                > (Q, K, V)
            }
            r  r  r1   r1   r2   %test_linear_attention_gqa_indivisible     z8TestShapeInference.test_linear_attention_gqa_indivisiblec                 C  r  )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4,64] Q, float[2,4,64] K, float[2,4,64] V,
               float[2,4,4] beta)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=4, kv_num_heads=4, update_rule="gated_delta"
                > (Q, K, V, "", "", beta)
            }
            r  r  r1   r1   r2   /test_linear_attention_gated_delta_missing_decay  r  zBTestShapeInference.test_linear_attention_gated_delta_missing_decayc                 C  r  )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4,64] Q, float[2,4,64] K, float[2,4,64] V,
               float[2,4,64] decay)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=4, kv_num_heads=4, update_rule="gated_delta"
                > (Q, K, V, "", decay)
            }
            r  r  r1   r1   r2   .test_linear_attention_gated_delta_missing_beta  r  zATestShapeInference.test_linear_attention_gated_delta_missing_betac                 C  r  )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4,64] Q, float[2,4,64] K, float[2,4,64] V,
               float[2,4,64] decay)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=4, kv_num_heads=4, update_rule="linear"
                > (Q, K, V, "", decay)
            }
            r  r  r1   r1   r2   'test_linear_attention_linear_with_decay  r  z:TestShapeInference.test_linear_attention_linear_with_decayc                 C  r  )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4,64] Q, float[2,4,64] K, float[2,4,64] V,
               float[2,4,4] beta)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=4, kv_num_heads=4, update_rule="linear"
                > (Q, K, V, "", "", beta)
            }
            r  r  r1   r1   r2   &test_linear_attention_linear_with_beta	  r  z9TestShapeInference.test_linear_attention_linear_with_betac                 C  r  )Nao  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4,64] Q, float[2,4,64] K, float[2,4,64] V)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=4, kv_num_heads=4, update_rule="forza inter"
                > (Q, K, V)
            }
            r  r  r1   r1   r2   )test_linear_attention_unknown_update_rule  r  z<TestShapeInference.test_linear_attention_unknown_update_rulec                 C  r  )Naj  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,3,16] Q, float[2,3,16] K, float[2,3,16] V)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=0, kv_num_heads=2, update_rule="linear"
                > (Q, K, V)
            }
            r  r  r1   r1   r2   &test_linear_attention_q_num_heads_zero*  r  z9TestShapeInference.test_linear_attention_q_num_heads_zeroc                 C  r  )Naj  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,3,15] Q, float[2,3,16] K, float[2,3,16] V)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=2, kv_num_heads=2, update_rule="linear"
                > (Q, K, V)
            }
            r  r  r1   r1   r2   'test_linear_attention_qpack_indivisible;  r  z:TestShapeInference.test_linear_attention_qpack_indivisiblec                 C  r  )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,3,64] Q, float[2,3,64] K, float[2,3,64] V,
               float[2,3,7] decay)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=4, kv_num_heads=4, update_rule="gated"
                > (Q, K, V, "", decay)
            }
            r  r  r1   r1   r2   *test_linear_attention_decay_last_dim_wrongL     z=TestShapeInference.test_linear_attention_decay_last_dim_wrongc                 C  r  )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,3,64] Q, float[2,3,64] K, float[2,3,64] V,
               float[2,3,4] decay, float[2,3,3] beta)
                => (output, present_state)
            {
                output, present_state = LinearAttention <
                    q_num_heads=4, kv_num_heads=4, update_rule="gated_delta"
                > (Q, K, V, "", decay, beta)
            }
            r  r  r1   r1   r2   )test_linear_attention_beta_last_dim_wrong^  r  z<TestShapeInference.test_linear_attention_beta_last_dim_wrongc                 C  r  )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4,8] input, float[4,1,4] weight)
                => (output, present_state)
            {
                output, present_state = CausalConvWithState (input, weight)
            }
            r  rQ   r   r  r  r   r  r  r1   r1   r2   "test_causal_conv_with_state_staticp     
z5TestShapeInference.test_causal_conv_with_state_staticc                 C  r  )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[B,C,L] input, float[C,1,4] weight)
                => (output, present_state)
            {
                output, present_state = CausalConvWithState (input, weight)
            }
            r  )r  r  Lr  )r  r  r   r  r  r1   r1   r2   *test_causal_conv_with_state_dynamic_length     
z=TestShapeInference.test_causal_conv_with_state_dynamic_lengthc                 C  r  )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4,8] input, float[4,1,k] weight)
                => (output, present_state)
            {
                output, present_state = CausalConvWithState (input, weight)
            }
            r  r  r  r  r  r  r1   r1   r2   *test_causal_conv_with_state_dynamic_kernel  r  z=TestShapeInference.test_causal_conv_with_state_dynamic_kernelc                 C  r  )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4] input, float[4,1,4] weight)
                => (output, present_state)
            {
                output, present_state = CausalConvWithState (input, weight)
            }
            r  r  r1   r1   r2   -test_causal_conv_with_state_input_rank2_fails     
z@TestShapeInference.test_causal_conv_with_state_input_rank2_failsc                 C  r  )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4,8] input, float[4,1,0] weight)
                => (output, present_state)
            {
                output, present_state = CausalConvWithState (input, weight)
            }
            r  r  r1   r1   r2   -test_causal_conv_with_state_kernel_zero_fails  r  z@TestShapeInference.test_causal_conv_with_state_kernel_zero_failsc                 C  r  )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4,8] input, float[4,4] weight)
                => (output, present_state)
            {
                output, present_state = CausalConvWithState (input, weight)
            }
            r  r  r1   r1   r2   .test_causal_conv_with_state_weight_rank2_fails  r  zATestShapeInference.test_causal_conv_with_state_weight_rank2_failsc                 C  r  )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4,8] input, float[4,1,1] weight)
                => (output, present_state)
            {
                output, present_state = CausalConvWithState (input, weight)
            }
            r  r  r  )rQ   r   r   r  r  r1   r1   r2   +test_causal_conv_with_state_kernel_size_one  r  z>TestShapeInference.test_causal_conv_with_state_kernel_size_onec                 C  r  )Na  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float16[2,4,8] input, float16[4,1,4] weight)
                => (output, present_state)
            {
                output, present_state = CausalConvWithState (input, weight)
            }
            r  r  r  r   )rl   r  r  r   r!   r   r   r  r1   r1   r2   1test_causal_conv_with_state_fp16_type_propagation  r  zDTestShapeInference.test_causal_conv_with_state_fp16_type_propagationc                 C  r  )Na}  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4,8] input, float[4,1,4] weight,
               float[4] bias, float[2,4,3] past_state)
                => (output, present_state)
            {
                output, present_state = CausalConvWithState (
                    input, weight, bias, past_state
                )
            }
            r  r  r  r   r  r  r1   r1   r2   /test_causal_conv_with_state_all_optional_inputs  s   zBTestShapeInference.test_causal_conv_with_state_all_optional_inputsc                 C  r  )Na+  
            <ir_version: 10, opset_import: ["" : 27]>
            g (float[2,4,8] input, float[4,1,4] weight)
                => (output, present_state)
            {
                output, present_state = CausalConvWithState <activation = "forza inter"> (input, weight)
            }
            r  r  r1   r1   r2   4test_causal_conv_with_state_unknown_activation_fails  s   
zGTestShapeInference.test_causal_conv_with_state_unknown_activation_failsc              	   C  p   |  dtjdfdtjdfdtjdfgtdg dd	gtd
gg }| j|td	tjdgttdttdgd dS )zBTest FlexAttention basic shape inference with symbolic dimensions.r  )r  Hqr	  Dqkr  )r  HkvSr  r  )r  r  r  DvFlexAttentionr  r   r<   )r  r  r	  r     r   r   N	rc   r   r   r   r   r   r!   r   r   r   r1   r1   r2   test_flex_attention_basic  *   



z,TestShapeInference.test_flex_attention_basicc              	   C  p   |  dtjdfdtjdfdtjdfgtdg ddgtd	gg }| j|tdtjdgttd
ttdgd dS )z<Test FlexAttention shape inference with concrete dimensions.r  r  r  rQ   r     r  r  r  r  r   r<   r  r   r   Nr  r   r1   r1   r2   !test_flex_attention_concrete_dims:  r  z4TestShapeInference.test_flex_attention_concrete_dimsc              	   C  r  )z:Test FlexAttention with different head sizes for Q/K vs V.r  r  r  r!  r  rQ   r  r"  r  r  r  r   r<   )rQ   r  r  r  r  r   r   Nr  r   r1   r1   r2   )test_flex_attention_different_v_head_sizeU  r  z<TestShapeInference.test_flex_attention_different_v_head_sizec              	   C  r   )z0Test FlexAttention with Grouped Query Attention.r  r  r  )rQ   rQ   r"  r  r  r  r  r   r<   r  r   r   Nr  r   r1   r1   r2   test_flex_attention_gqa_enabledp  r  z2TestShapeInference.test_flex_attention_gqa_enabledc              	   C  r   )z5Test FlexAttention shape inference with FLOAT16 type.r  r  r  r!  r  r  r  r   r<   r  r   r   N)	rc   r   r   r   r   r   r!   r   r   r   r1   r1   r2   test_flex_attention_float16  r  z.TestShapeInference.test_flex_attention_float16c              	   C  r   )z6Test FlexAttention shape inference with BFLOAT16 type.r  r  r  r!  r  r  r  r   r<   r  r   r   N)	rc   r   BFLOAT16r   r   r   r!   r   r   r   r1   r1   r2   test_flex_attention_bfloat16  r  z/TestShapeInference.test_flex_attention_bfloat16c              	   C  r   )z4Test FlexAttention shape inference with DOUBLE type.r  r  r  r!  r  r  r  r   r<   r  r   r   N)	rc   r   r  r   r   r   r!   r   r   r   r1   r1   r2   test_flex_attention_double  r  z-TestShapeInference.test_flex_attention_doublec              
   C  sr   |  dtjdfdtjdfdtjdfgtdg ddgd	td
gg }| j|tdtjdgttdttdgd dS )z1Test FlexAttention with explicit scale attribute.r  r  r  r!  r  r  r  r   g      ?)r  r.   r  r   r   Nr  r   r1   r1   r2   test_flex_attention_with_scale  s,   


	
z1TestShapeInference.test_flex_attention_with_scalec              
   C     t tddgdggdtdtjdgtdtjdg}| dtjdfdtjd	fd
tjd	fgtdg ddg|tdgg }| j|tdtjdgt	t
dt	tdgd dS )z+Test FlexAttention with score_mod subgraph.Identityscores
scores_out	score_modr  r  r	  r  r  r  r  r!  r  r  r  r   )r0  r.   r  r   r   Nr   r   r   r!   r   r   rc   r   r   r   r   )r\   score_mod_graphr}   r1   r1   r2   "test_flex_attention_with_score_mod  D   


	
z5TestShapeInference.test_flex_attention_with_score_modc              
   C  r,  )z*Test FlexAttention with prob_mod subgraph.r-  probs	probs_outprob_modr1  r  r  r  r!  r  r  r  r   )r8  r.   r  r   r   Nr2  )r\   prob_mod_graphr}   r1   r1   r2   !test_flex_attention_with_prob_mod$  r5  z4TestShapeInference.test_flex_attention_with_prob_modc                 C  s   t tddgdggdtdtjdgtdtjdg}t tddgdggdtdtjdgtdtjdg}| d	tjd
fdtjdfdtjdfgtdg ddg||tdgg }| j|tdtjd
gt	t
dt	tdgd dS )z/Test FlexAttention with all modifier subgraphs.r-  r.  r/  r0  r1  r6  r7  r8  r  r  r  r!  r  r  r  r   )r0  r8  r.   r  r   r   Nr2  )r\   r3  r9  r}   r1   r1   r2   &test_flex_attention_with_all_modifiersP  s^   




z9TestShapeInference.test_flex_attention_with_all_modifiersc              	   C  l   |  dtjdfdtjdfdtjdfgtdg ddgtd	gg }| jtjj| j	|t
td
t
tdgd dS )z2Test FlexAttention fails when input rank is not 4.r  )rQ   r  r  r  r!  r  r  r  r   r<   r  r   r   Nrc   r   r   r   r   r   rl   rm   r   rr   r   r   r   r1   r1   r2   $test_flex_attention_rank_not_4_fails  ,   



z7TestShapeInference.test_flex_attention_rank_not_4_failsc              	   C  sl   |  dtjdfdtjdfdtjdfgtdg ddgtd	gg }| jtjj	| j
|ttd
ttdgd dS )zCTest FlexAttention fails when Q, K, V have different element types.r  r  r  r!  r  r  r  r   r<   r  r   r   N)rc   r   r   r   r   r   r   rl   rm   r   rr   r   r   r   r1   r1   r2   .test_flex_attention_mismatched_elem_type_fails  r?  zATestShapeInference.test_flex_attention_mismatched_elem_type_failsc              	   C  r<  )z9Test FlexAttention fails when Hq is not divisible by Hkv.r  r  r  )rQ   r   r"  r  r  r  r  r   r<   r  r   r   Nr=  r   r1   r1   r2   +test_flex_attention_gqa_not_divisible_fails  r?  z>TestShapeInference.test_flex_attention_gqa_not_divisible_failsc              	   C  l   |  dtjdfdtjdfdtjdfgtdg dd	gtd
gg }| jtjj| j	|t
tdt
tdgd dS )zFTest FlexAttention fails when K and V have different sequence lengths.r  r  r  r!  r  )rQ   r  i   r  r  r  r   r<   r  r   r   Nr=  r   r1   r1   r2   /test_flex_attention_mismatched_kv_seq_len_fails  r?  zBTestShapeInference.test_flex_attention_mismatched_kv_seq_len_failsc              	   C  rB  )zATest FlexAttention fails when K and V have different head counts.r  r  r  r!  r  )rQ   r   r"  r  r  r  r   r<   r  r   r   Nr=  r   r1   r1   r2   -test_flex_attention_mismatched_kv_heads_fails  r?  z@TestShapeInference.test_flex_attention_mismatched_kv_heads_failsc              	   C  rB  )z@Test FlexAttention fails when Q and K have different head sizes.r  r  r  r$  r  r!  r  r  r   r<   r  r   r   Nr=  r   r1   r1   r2   1test_flex_attention_mismatched_qk_head_size_fails  r?  zDTestShapeInference.test_flex_attention_mismatched_qk_head_size_failsc                 C  sP   |  dtjdfgtddgddg dg ddgg }| |tdtjd	g d S )
NrN   r  AveragePoolr   r  )r   r   rQ   r  r  r  r#  )r   r   r   r   r   r   r   r1   r1   r2   test_average_pool_auto_pads5  s    
z.TestShapeInference.test_average_pool_auto_padsc              
   C  P   |  dtjdfgtddgdgddgddgdgg }| |tdtjdg d S )Nr   r;   r   r   r   rF  r   rQ   r  r;   r   rQ   rQ   r   r   r1   r1   r2    test_average_pool_with_dilationsH     	z3TestShapeInference.test_average_pool_with_dilationsc                 C  X   |  dtjdfgtddgdgdddgddgddgdgg }| |tdtjd	g d S )
Nr   rJ  rF  r   r  rQ   r   r  r  r#  r-  rK  r   r   r1   r1   r2   Atest_average_pool_with_same_upper_padding_and_stride_and_dilationV  "   zTTestShapeInference.test_average_pool_with_same_upper_padding_and_stride_and_dilationc                 C     |  d d S )NRelur   r\   r1   r1   r2   	test_reluj     zTestShapeInference.test_reluc                 C  rR  )Nr-  rT  rU  r1   r1   r2   test_identitym  rW  z TestShapeInference.test_identityc                 C  sr   |  dtjdfdtjdfdtjdfgtdg ddgtd	dgd
ggg }| |tdtjdtd
tjdg d S )Ninput1r   input2input3rQ   r;   r   SequenceConstructrY  rZ  r[  in_sequencer-  output_sequencerQ   Nr   rc   r   r   r   r   r    r   r1   r1   r2   test_identity_sequencep  s,   


z)TestShapeInference.test_identity_sequencec                 C  sp   |  dtjdfgtddgdgtddgdggg }ttjd}t|}| |td|td|g d S )N	in_tensorr   Optionalin_optionalr-  output_optional)	rc   r   r   r   r   make_tensor_type_protomake_optional_type_protor   make_value_info)r\   r}   tensor_type_protooptional_type_protor1   r1   r2   test_identity_optional  s   


z)TestShapeInference.test_identity_optionalc              	   C  s   |  dtjdfdtjdfdtjdfgtdg ddgtd	dgd
gtdd
gdggg }ttjd}t|}t|}| |t	d|t	d
|t	d|g d S )NrY  r   rZ  r[  r\  r]  r^  r_  re  rf  r-  rg  ra  )
rc   r   r   r   r   rh  make_sequence_type_protori  r   rj  )r\   r}   rk  sequence_type_protorl  r1   r1   r2   test_identity_optional_sequence  s2   







z2TestShapeInference.test_identity_optional_sequencec                 C  L   |  dtjdfdtjdfgtdddgdgg }| |tdtjdg d S )NrN   r   r   Addr   r   r   r1   r1   r2   test_add     

zTestShapeInference.test_addc                 C  rq  )NrN   r   r   Powr   r   r   r1   r1   r2   test_pow  rt  zTestShapeInference.test_powc              	   C  sP   |  dtjdfdtjdfgtdddgdddgg }| |tdtjdg d S )NrN   rQ   r   r   r   BitShiftr   RIGHT	directionrc   r   r  r   r   r!   r   r1   r1   r2   test_bitshift  r  z TestShapeInference.test_bitshiftc              	   C  sP   |  dtjdfdtjdfgtdddgdddgg }| |tdtjdg d S )	NrN   )r  r   r   r   r  rx  r   ry  rz  r|  r   r1   r1   r2    test_bitshift_broadcast_to_first     z3TestShapeInference.test_bitshift_broadcast_to_firstc              	   C  sP   |  dtjdfdtjdfgtdddgdddgg }| |tdtjdg d S )	NrN   r  r   rw  rx  r   ry  rz  r|  r   r1   r1   r2   !test_bitshift_broadcast_to_second  r  z4TestShapeInference.test_bitshift_broadcast_to_secondc                 C  rR  )NSumrT  rU  r1   r1   r2   test_sum_single  rW  z"TestShapeInference.test_sum_singlec                 C  X   |  dtjdfdtjdfdtjdfgtdg ddggg }| |tdtjdg d S )NrN   r   r   r   r  r>  r?  r   r   r1   r1   r2   test_sum_multi  rC  z!TestShapeInference.test_sum_multic                 C  r  )NrN   )r   r   r;   r   r   r   r   r   )r   r   r  r>  r?  r   r   r   r1   r1   r2   test_sum_multi_broadcasting  rC  z.TestShapeInference.test_sum_multi_broadcastingc                 C  N   |  dtjdfdtjdfgtdddgdggg }| |tdtjdg d S )NrN   )r   r   r;   r   r  r  r?  r   r   r   r1   r1   r2   test_sum_broadcasting_param     

z.TestShapeInference.test_sum_broadcasting_paramc              
   C  s>   |  g tdg dgtjddgg }| |tdtjdg d S )NRandomNormalr?  r3  )r}  r   )rc   r   r   r  r   r!   r   r1   r1   r2   test_random_normal#  s   	z%TestShapeInference.test_random_normalc                 C  B   |  dtjdfgtddgdggg }| |tdtjdg d S )Nr   r   RandomNormalLiker?  r   r   r1   r1   r2   test_random_normal_like5     z*TestShapeInference.test_random_normal_likec              	   C  H   |  dtjdfgtddgdgtjdgg }| |tdtjdg d S )Nr   r   r  r?  r|  rc   r   r   r   r  r   r!   r   r1   r1   r2   "test_random_normal_like_with_dtype?     z5TestShapeInference.test_random_normal_like_with_dtypec                 C  r  )NrN   r  	Bernoullir?  r   r   r1   r1   r2   test_bernoulliP  r  z!TestShapeInference.test_bernoullic              	   C  r  )NrN   r   r  r?  r|  r  r   r1   r1   r2   test_bernoulli_with_dtypeZ  r  z,TestShapeInference.test_bernoulli_with_dtype
input_typeTensorProto.DataTypec                 C  sH   |  d|dfd|dfgt|ddgdgg }| |tdtjdg d S )NrN   r   r   r   rc   r   r   r!   r   r+  r\   r   r  r}   r1   r1   r2   _logical_binary_opk  s   z%TestShapeInference._logical_binary_opc                 C  sH   |  d|dfd|dfgt|ddgdgg }| |tdtjdg d S )NrN   r  r   r   r   r  r  r1   r1   r2   $_logical_binary_op_with_broadcastingu  s   z7TestShapeInference._logical_binary_op_with_broadcastingc                 C      |  dtj | dtj d S )NAndr  r   r+  r  rU  r1   r1   r2   test_logical_and     z#TestShapeInference.test_logical_andc                 C  r  )NOrr  rU  r1   r1   r2   test_logical_or  r  z"TestShapeInference.test_logical_orc                 C  r  )NXorr  rU  r1   r1   r2   test_logical_xor  r  z#TestShapeInference.test_logical_xorc                 C  r  )NGreaterr  rU  r1   r1   r2   test_greater  r  zTestShapeInference.test_greaterc                 C  r  )NLessr  rU  r1   r1   r2   	test_less  r  zTestShapeInference.test_lessc                 C  r  NEqualr  rU  r1   r1   r2   
test_equal  r  zTestShapeInference.test_equalc                 C  r  r  )r  r   r   r  rU  r1   r1   r2   test_equal_string  r  z$TestShapeInference.test_equal_stringc                 C  @   |  dtjdfgtddgdgg }| |tdtjdg d S )NrN   r   Notr   )rc   r   r+  r   r   r!   r   r1   r1   r2   test_logical_not     z#TestShapeInference.test_logical_notc                 C  r  )NLessOrEqualr  rU  r1   r1   r2   test_less_or_equal  r  z%TestShapeInference.test_less_or_equalc                 C  r  )NGreaterOrEqualr  rU  r1   r1   r2   test_greater_or_equal  r  z(TestShapeInference.test_greater_or_equalc              	   C  F   |  dtjdfgtddgdgddgg }| |tdtjdg d S )NrN   rQ   r   r   r;   Flattenr   rQ   r9  )r     r   r   r1   r1   r2   test_flatten  r   zTestShapeInference.test_flattenc                 C  B   |  dtjdfgtddgdggg }| |tdtjdg d S )NrN   r  r  r   )rQ   <   r   r   r1   r1   r2   test_flatten_default_axis  r  z,TestShapeInference.test_flatten_default_axisc              	   C  r  )NrN   r  r  r   r   r9  )r   x   r   r   r1   r1   r2   test_flatten_zero_axis  r   z)TestShapeInference.test_flatten_zero_axisc              	   C  r  )NrN   )rQ   r   r   r;   r  r   rQ   r9  )Nr  r   r   r1   r1   r2   test_flatten_unknown_dim  r   z+TestShapeInference.test_flatten_unknown_dimc              	   C  J   d}|  dtjdfgtddgdg|dgg }| |tdtjdg d S )Nr1  rN   rQ   r   d   r  SpaceToDepthr   	blocksizerQ   ,  r1  r1  r   r\   r   r}   r1   r1   r2   test_space_to_depth     z&TestShapeInference.test_space_to_depthc              	   C  r  )Nr1  rN   )rQ   r   r  r  r  r   r  )rQ   Nr1  r1  r   r  r1   r1   r2   test_space_to_depth_unknown_dim  r  z2TestShapeInference.test_space_to_depth_unknown_dimc              
   C  sL   d}|  dtjdfgtddgdg|ddgg }| |tdtjdg d S )	Nr1  rN   r  DepthToSpacer   DCR)r  moder  r   r  r1   r1   r2   test_depth_to_space  s   z&TestShapeInference.test_depth_to_spaceseqlen	batchsizeinpsize
hiddensizec              
   C  s   |  dtj|||ffdtjd||ffdtjd||ffgtdg dddg|d	gg }| |tdtj|d||ftdtjd||fg d S )
NrN   r  r   rRNNrN   r  r  alllasthidden_sizer   r\   r  r  r  r  r}   r1   r1   r2   _rnn_forward  s*   zTestShapeInference._rnn_forwardc                 C     |  dddd d S Nr      r1  r   )r  rU  r1   r1   r2   test_rnn_forward     z#TestShapeInference.test_rnn_forwardc              
   C  s   |  dtj|||ffdtjd||ffdtjd||ffgtdg dddg|d	d
gg }| |tdtj|d||ftdtjd||fg d S )NrN   r  rQ   r  r  r  r  r  bidirectional)r  r{  r   r  r1   r1   r2   _rnn_bidirectional  s2   	z%TestShapeInference._rnn_bidirectionalc                 C  s&   |  dddd |  ddddd d S )Nr  r  r1  r   r  )_rnn_layoutrU  r1   r1   r2   test_rnn_layout5  s   z"TestShapeInference.test_rnn_layoutforwardr{  c                 C  s   |  dtj|||ffdtjd||ffdtjd||ffgtdg dddg|d|d	gg }|d
kr3d}nd}| |tdtj||||ftdtj|||fg d S )NrN   r  r   r  r  r  r  r  )r  layoutr{  r  rQ   r   )r\   r  r  r  r  r{  r}   num_directionsr1   r1   r2   r  9  s>   

zTestShapeInference._rnn_layoutc                 C  r  r  )r  rU  r1   r1   r2   test_rnn_bidirectionale  r  z)TestShapeInference.test_rnn_bidirectionalc                 C  s   |  dtj|||ffdtjdd| |ffdtjdd| |ffgtdg dg d|d	gg }| |td
tj|d||ftdtjd||ftdtjd||fg d S )NrN   r  r   r   r  LSTMr  )r  hiddenr  r  r  r  r  r   r  r1   r1   r2   _lstm_forwardh  s6   z TestShapeInference._lstm_forwardc                 C  r  r  )r  rU  r1   r1   r2   test_lstm_forward  r  z$TestShapeInference.test_lstm_forwardc                 C  s   dD ]K\}}}t t|g dg ddgdtdtjdtdtj|td	tj|gg }| tjj	 | j
|t td
gd W d    n1 sHw   Y  qd S )N))r  r+  )r   r   r   )GRU)r   r2  r;   )r   r2  r   )r  )r   r  r;   )r   r  r   r  r   r  rV   rN   r   r;   r  r  r  r   )r   r   r   r!   r   r   r   rl   rm   r   rr   r   r   )r\   r   w_shaper_shaper}   r1   r1   r2   'test_rnn_opset1_to_6_invalid_input_rank  s"   
z:TestShapeInference.test_rnn_opset1_to_6_invalid_input_rankc              	   C  sd   | j dtjdfgtdddgddggg tdtjddgd	}| |tdtjd
tdtjd
g d S )NrN   r   r   r;   r1  TopKkr   r   r  r   r  )r   r   r;   rQ   rc   r   r   r   r   r[   r   r!   r   r1   r1   r2   test_topk_default_axis  s   z)TestShapeInference.test_topk_default_axisc              	   C  sh   | j dtjdfgtdddgddgddgg tdtjd	d
gd}| |tdtjdtdtjdg d S )NrN   r  r  r  r   r   rQ   r9  r  r   r  )r   r   rQ   r1  r  r   r1   r1   r2   	test_topk  s   zTestShapeInference.test_topkc                 C  s|   | j dtjdfgtdddgddgddgg tdtjd	tjd
gdd ddgd}| 	|t
dtjdt
dtjdg d S )NrN   r  r  r  r   r   rQ   r9  r  r   r  r|  Tr~  r  )r   r   r   r1  )rc   r   r   r   r   r[   r   r  r  r   r!   r   r1   r1   r2   test_topk_raw_data  s&   z%TestShapeInference.test_topk_raw_datac              	   C  s`   |  dtjdfdtjdfgtdddgddgdd	gg }| |tdtjd
tdtjd
g d S )NrN   r  r  r  r  r   r   rQ   r9  )NNNNrA  r   r1   r1   r2   +test_topk_missing_k_value_output_rank_check  s   z>TestShapeInference.test_topk_missing_k_value_output_rank_checkc                 C  sX   |  dtjdfdtjdfdtjd fgtdg ddggg }| |tdtjd	g d S )
NrN   r8  r;   r   r;   r  r   Gemmr>  r?  r8  r  r   r   r1   r1   r2   	test_gemm  rC  zTestShapeInference.test_gemmc              	   C  \   |  dtjdfdtjdfdtjd fgtdg ddgd	d
gg }| |tdtjdg d S )NrN   r;   r8  r   r  r   r  r>  r?  r   )transAr  r   r   r1   r1   r2   test_gemm_transA     


	z#TestShapeInference.test_gemm_transAc              	   C  r  )NrN   r  r   r  r;   r   r  r>  r?  r   )transBr  r   r   r1   r1   r2   test_gemm_transB  r  z#TestShapeInference.test_gemm_transBc              
   C  s^   |  dtjdfdtjdfdtjd fgtdg ddgd	d	d
gg }| |tdtjdg d S )NrN   r  r   r  r   r  r>  r?  r   )r  r  r  r   r   r1   r1   r2   test_gemm_transA_and_transB  s   


	z.TestShapeInference.test_gemm_transA_and_transBc                 C  r  )NrN   )   r8  r   )r8     r  r?  )r
  r  r   r   r1   r1   r2   test_gemm_no_bias#     z$TestShapeInference.test_gemm_no_biasc              	   C  n   | j dtjdfgtddddddgg tdtjd	dgd
}t }d|_d|_| j	|t
dtjdg|gd d S )NrN   r  r   r  ReduceL1r   r   r   r  keepdimsr  r   r  r  r
  r  r   rc   r   r   r   r   r[   r   r.   r0   r   r!   r/  r1   r1   r2   #test_reduce_op_shape_2_axis_opset13-  s   
z6TestShapeInference.test_reduce_op_shape_2_axis_opset13c              	   C  z   | j dtjdfdtjdfgtdddgdddgg tdtjdd	gd
}t }d|_d|_| j	|t
dtjdg|gd d S )NrN   r  r  r   r  r   r   r  r   r  r  r  r  r   rc   r   r   r[   r   r   r   r.   r0   r   r!   r/  r1   r1   r2   #test_reduce_op_shape_2_axis_opset18>  s   
z6TestShapeInference.test_reduce_op_shape_2_axis_opset18c              	   C  sZ   | j dtjdfgtddddddgg g d}td	d
d}| j|tdtjdg|gd d S )NrN   r  r   r  r  r   r  r   r  r  r  r
  r.   r0   r  r   r  r   )rc   r   r   r   r   r   r!   r/  r1   r1   r2    test_reduce_op_empty_set_opset13O  s   
z3TestShapeInference.test_reduce_op_empty_set_opset13c              	   C  st   | j dtjdfdtjdfgtdddgdddgg tdtjddgd	}td
dd}| j|tdtjdg|gd d S )NrN   r  r  r  r  r   r   r  r  r  r  r  r  r   )	rc   r   r   r[   r   r   r   r   r!   r/  r1   r1   r2    test_reduce_op_empty_set_opset18]  s   
z3TestShapeInference.test_reduce_op_empty_set_opset18c              	   C  r  )NrN   r  r  r   r   r   r  r  r   r  r  r
  r  r   r   r   r  r/  r1   r1   r2   &test_reduce_op_shape_keep_dims_opset13k  s   
z9TestShapeInference.test_reduce_op_shape_keep_dims_opset13c              	   C  r  )NrN   r  r  r   r  r   r   r  r   r  r  r  r  r   r  r/  r1   r1   r2   &test_reduce_op_shape_keep_dims_opset18{  s   
z9TestShapeInference.test_reduce_op_shape_keep_dims_opset18c                 C  s>   |  dtjdfgtdddgg }| |tdtjdg d S )NrN   r  r  r   rV  r   r   r1   r1   r2   "test_reduce_op_shape_default_value  s   z5TestShapeInference.test_reduce_op_shape_default_valuec              	   C  sB   |  dtjdfgtdddddgg }| |tdtjdg d S )NrN   r  r  r   r   r  r1   r   r   r1   r1   r2   -test_reduce_op_shape_no_axes_do_not_keep_dims  r  z@TestShapeInference.test_reduce_op_shape_no_axes_do_not_keep_dimsc              	   C  r3  )
NrN   r  r  r   r  r   )r'   r[  r  r  r5  r   r1   r1   r2   "test_reduce_op_shape_negative_axis  r7  z5TestShapeInference.test_reduce_op_shape_negative_axisc              
   C  D   |  dtjdfgtddddddgg }| |tdtjdg d S )NrN   r  ArgMaxr   r   r:  r  r  rc   r   r   r   r   r!   r[   r   r1   r1   r2   test_argmax_shape     z$TestShapeInference.test_argmax_shapec              
   C  r%  )NrN   r  r&  r   r   r'  )r   r  r(  r   r1   r1   r2   test_argmax_shape_keepdims  r*  z-TestShapeInference.test_argmax_shape_keepdimsc                 C  s>   |  dtjdfgtdddgg }| |tdtjdg d S )NrN   r  r&  r   )r   r   r  r(  r   r1   r1   r2   test_argmax_shape_default_value  s   z2TestShapeInference.test_argmax_shape_default_valuec              	   C  sB   |  dtjdfgtdddddgg }| |tdtjdg d S )NrN   r  r&  r   r[  r9  r  r(  r   r1   r1   r2   test_argmax_shape_negative_axis  r  z2TestShapeInference.test_argmax_shape_negative_axisc                 C  sN   |  dtjdfdtjdfgtdddgdggg }| |tdtjdg d S )Ndatar3  ratior1   Dropoutr?  r   r   r1   r1   r2   test_dropout  s&   
	zTestShapeInference.test_dropoutc                 C  s   | j ddddd d S )NLRN      ?r   )alphabetasizerT  rU  r1   r1   r2   test_LRN  s   zTestShapeInference.test_LRNc              	   C  l   |  dtjdfdtjdfdtjdfdtjdfdtjdfgtdg d	d
ggg }| |td
tjdg d S )NrN   rf  r  rk  r   meanvarBatchNormalizationrN   r  r   r9  r:  r?  r   r   r1   r1   r2   test_batch_norm      




z"TestShapeInference.test_batch_normc              	   C  r8  )NrN   r  r  r  r   r9  r:  r;  r<  r?  r   r   r1   r1   r2   test_batch_norm_rank1  r>  z(TestShapeInference.test_batch_norm_rank1c              	   C  sh   |  dtjdfdtjdfdtjdfdtjdfdtjdfgtd	g d
dggg }| tjj| j| d S )NrN   r?  r  r   r   r  r9  r:  r;  r<  r?  r   r   r1   r1   r2   test_batch_norm_invalid  s   




z*TestShapeInference.test_batch_norm_invalidc              
   C  V   |  dtjdfgtddgddgdddgg }| |tdtjd	tdtjd	g d S )
NrN   r   Splitr   r   r'   rQ   r:  num_outputsr/  r   r   r1   r1   r2   test_split_negative_axis-     z+TestShapeInference.test_split_negative_axisc              	   C  sr   | j dtjdfdtjdfgtdddgddgdd	gg tdtjdd
gd}| |tdtjdtdtjdg d S )NrN   r   splitr   rC  r   r   r   r9  r  r  r   r   r5  r   r1   r1   r2   test_split_with_split_attribute;  s   z2TestShapeInference.test_split_with_split_attributec              	   C  sr   | j dtjdfdtjdfgtdddgddgdd	gg tdtjdd
gd}| |tdtjdtdtjdg d S )NrN   )rQ   r   r   rH  r   rC  r   r   r   r9  r  r  )rQ   Nr   r5  r   r1   r1   r2   1test_split_with_split_attribute_unknown_split_dimJ  s   

	zDTestShapeInference.test_split_with_split_attribute_unknown_split_dimc              
   C  rB  )
NrN   rH  rC  r   r   r   rQ   rD  r;   r   r8  r   r   r1   r1   r2   test_split_from_GLU\  rG  z&TestShapeInference.test_split_from_GLUc              
   C  b   |  dtjdfgtddgg ddddgg }| |tdtjd	td
tjd	tdtjdg d S )NrN   )r  rQ   rC  r   r   r   r   r   rD  r   r  r   r   r/  r   r   r1   r1   r2   test_split_uneven_split_2dj     z-TestShapeInference.test_split_uneven_split_2dc              
   C  rM  )NrN   )rQ   r8  r   rC  rN  r   r   rD  r   rQ   r   r   r   r   rQ   r   r   r   r   r1   r1   r2   test_split_uneven_split_3dy  rP  z-TestShapeInference.test_split_uneven_split_3dc              
   C  sp   |  dtjdfgtddgddgdddtd	dgd
ggg }| |tdtjdtdtjdtd
tjdg d S )NrN   rH  rC  r   r   r   rQ   rD  Sigmoidr   rK  r   r   r1   r1   r2   test_GLU_partial  s   z#TestShapeInference.test_GLU_partialc              
   C  s   |  dtjdfgtddgddgdddtd	dgd
gtddd
gdggg }| |tdtjdtdtjdtd
tjdtdtjdg d S )NrN   rH  rC  r   r   r   rQ   rD  rT  r   Mulr   rK  r   r   r1   r1   r2   test_GLU  s    	zTestShapeInference.test_GLUc                 C  r  )NrN   r  Softmaxr   r   r   r1   r1   r2   test_softmax_2d  r  z"TestShapeInference.test_softmax_2dc                 C  r  )NrN   r  rX  r   r   r   r1   r1   r2   test_softmax_3d     z"TestShapeInference.test_softmax_3dc                 C  <   |  dtjdfgtddgdgg }| tjj| j| d S )NrN   r1   rX  r   r   r   r1   r1   r2   test_softmax_scalar_invalid     z.TestShapeInference.test_softmax_scalar_invalidc                 C  r  )NrN   r  Hardmaxr   r   r   r1   r1   r2   test_hardmax_2d  r  z"TestShapeInference.test_hardmax_2dc                 C  r  )NrN   r  r_  r   r   r   r1   r1   r2   test_hardmax_3d  r[  z"TestShapeInference.test_hardmax_3dc                 C  r\  )NrN   r1   r_  r   r   r   r1   r1   r2   test_hardmax_scalar_invalid  r^  z.TestShapeInference.test_hardmax_scalar_invalidc                 C  r  )NrN   r  
LogSoftmaxr   r   r   r1   r1   r2   test_logsoftmax_2d  r[  z%TestShapeInference.test_logsoftmax_2dc                 C  r  )NrN   r  rc  r   r   r   r1   r1   r2   test_logsoftmax_3d  r[  z%TestShapeInference.test_logsoftmax_3dc                 C  r\  )NrN   r1   rc  r   r   r   r1   r1   r2   test_logsoftmax_scalar_invalid  r^  z1TestShapeInference.test_logsoftmax_scalar_invalidc              	   C  sD   |  dtjdfgtddgdddgg }| |tdtjdg d S )NrN   r  rc  r   r'   r9  r   r   r1   r1   r2    test_logsoftmax_3d_negative_axis  r*  z3TestShapeInference.test_logsoftmax_3d_negative_axisc              	   C  J   |  dtjdfgtddgdgddgdgg }| |tdtjdg d S )Nr   rJ  r  r   rQ   r  r;   r   r   r   r   r   r1   r1   r2   test_maxpool     zTestShapeInference.test_maxpoolc              	   C  sX   |  dtjdfgtddgddgddgdgg }| |tdtjdtdtjdg d S )	Nr   rJ  r  r   ZrQ   r  ri  r(  r   r1   r1   r2   test_maxpool_with_indices  s   z,TestShapeInference.test_maxpool_with_indicesc              	   C  J   |  dtjdfgtddgdgg ddgg }| |tdtjdg d S )Nr   r;   r   r   r   r   r  r   rA  r  r;   r   r   r   r   r   r   r1   r1   r2   test_maxpool_3D  rk  z"TestShapeInference.test_maxpool_3Dc              
   C  P   |  dtjdfgtddgdgddgg ddgg }| |tdtjdg d S )	Nr   rJ  r  r   rQ   r   r   rQ   rQ   r  r;   r   r  r  r   r   r1   r1   r2   test_maxpool_with_padding$  rM  z,TestShapeInference.test_maxpool_with_paddingc                 C  V   |  dtjdfgtddgdgddgg dddgdgg }| |tdtjdg d S )	Nr   rJ  r  r   rQ   rs  r  r)  r#  ri  r   r   r1   r1   r2   $test_maxpool_with_padding_and_stride2      
z7TestShapeInference.test_maxpool_with_padding_and_stridec              
   C  Z   |  dtjdfgtddgdgddgddgdgg }| jtjj| j|t	
t|gd d S )	Nr   rJ  r  r   rQ   r   r  r#  r   r~  r   r1   r1   r2   test_maxpool_zero_stridesE  r  z,TestShapeInference.test_maxpool_zero_stridesc              
   C  rz  )	Nr   rJ  r  r   rQ   r'   r{  r   r~  r   r1   r1   r2   test_maxpool_negative_strides[  r  z0TestShapeInference.test_maxpool_negative_stridesc                 C  R   |  dtjdfgtddgdgddgddgddgg }| |tdtjdg d S )	Nr   r     #   r  r  r   rQ   Fr  r#  	ceil_mode)r  r  r  r  r   r   r1   r1   r2   test_maxpool_with_floor_modeq      
z/TestShapeInference.test_maxpool_with_floor_modec                 C  r~  )	Nr   r  r  r   rQ   Tr  )r  r  r  r  r   r   r1   r1   r2   test_maxpool_with_ceil_mode  r  z.TestShapeInference.test_maxpool_with_ceil_modec                 C  R   |  dtjdfgtddgdgddgddgddgg }| |tdtjd	g d S )
Nr   r  r  r   r   rQ   Tr  rs  r   r   r1   r1   r2   test_maxpool_ceil  r  z$TestShapeInference.test_maxpool_ceilc              
   C  rI  )Nr   rJ  r  r   rQ   r  rK  r   r   r1   r1   r2   test_maxpool_with_dilations     z.TestShapeInference.test_maxpool_with_dilationsc                 C  R   |  dtjdfgtddgdgdddgddgdgg }| |tdtjdg d S )	Nr   rJ  r  r   r  rQ   rG  rK  r   r   r1   r1   r2   /test_maxpool_with_same_upper_padding_and_stride      
zBTestShapeInference.test_maxpool_with_same_upper_padding_and_stridec                 C  rN  )
Nr   rJ  r  r   r  rQ   r   rO  rK  r   r   r1   r1   r2   <test_maxpool_with_same_upper_padding_and_stride_and_dilation  rQ  zOTestShapeInference.test_maxpool_with_same_upper_padding_and_stride_and_dilationc                 C  sR   |  dtjdfgtddgdgdddgddgdgg }| |tdtjdg d S )	Nr   rJ  r  r   r  rQ   r   rG  r   r   r1   r1   r2   3test_maxpool_with_same_upper_padding_and_stride_one  r  zFTestShapeInference.test_maxpool_with_same_upper_padding_and_stride_onec                 C  r  )	Nr   r;   r   r!  r!  r  r   
SAME_LOWERrQ   rG  r;   r   r;   r;   r   r   r1   r1   r2   /test_maxpool_with_same_lower_padding_and_stride  r  zBTestShapeInference.test_maxpool_with_same_lower_padding_and_stridec                 C  rN  )
Nr   r  r  r   r  rQ   r   rO  r  r   r   r1   r1   r2   <test_maxpool_with_same_lower_padding_and_stride_and_dilation  rQ  zOTestShapeInference.test_maxpool_with_same_lower_padding_and_stride_and_dilationc                 C  sR   |  dtjdfgtddgdgdddgddgdgg }| |tdtjd	g d S )
Nr   rJ  r  r   r  rQ   r   rG  r;   r   r   r   r   r   r1   r1   r2   3test_maxpool_with_same_lower_padding_and_big_stride  r  zFTestShapeInference.test_maxpool_with_same_lower_padding_and_big_stridec              	   C  rh  )Nr   rJ  rF  r   rQ   r  ri  r   r   r1   r1   r2   test_averagepool(  rk  z#TestShapeInference.test_averagepoolc              	   C  rn  )Nr   ro  rF  r   rA  r  rp  r   r   r1   r1   r2   test_averagepool_3D2  rk  z&TestShapeInference.test_averagepool_3Dc              
   C  rr  )	Nr   rJ  rF  r   rQ   rs  r  rt  r   r   r1   r1   r2   test_averagepool_with_padding<  rM  z0TestShapeInference.test_averagepool_with_paddingc                 C  rv  )	Nr   rJ  rF  r   rQ   rs  rw  ri  r   r   r1   r1   r2   (test_averagepool_with_padding_and_strideJ  ry  z;TestShapeInference.test_averagepool_with_padding_and_striderF  c              
   C  Z   |  dtjdfgtddgdgddgddgdgg }| jtjj| j|t	
t|gd d S )	Nr   rJ  rF  r   rQ   r   r{  r   r~  r   r1   r1   r2   test_averagepool_zero_strides]  r  z0TestShapeInference.test_averagepool_zero_stridesc              
   C  r  )	Nr   rJ  rF  r   rQ   r'   r{  r   r~  r   r1   r1   r2   !test_averagepool_negative_stridess  r  z4TestShapeInference.test_averagepool_negative_stridesc                 C  r  )
Nr   r  rF  r   r   rQ   Tr  rs  r   r   r1   r1   r2   test_averagepool_ceil  r  z(TestShapeInference.test_averagepool_ceilc              	   C  rh  )Nr   rJ  LpPoolr   rQ   r  ri  r   r   r1   r1   r2   test_lppool  rk  zTestShapeInference.test_lppoolc              	   C  rn  )Nr   ro  r  r   rA  r  rp  r   r   r1   r1   r2   test_lppool_3D  rk  z!TestShapeInference.test_lppool_3Dc              
   C  rr  )	Nr   rJ  r  r   rQ   rs  r  rt  r   r   r1   r1   r2   test_lppool_with_padding  r  z+TestShapeInference.test_lppool_with_paddingc                 C  rv  )	Nr   rJ  r  r   rQ   rs  rw  ri  r   r   r1   r1   r2   #test_lppool_with_padding_and_stride  ry  z6TestShapeInference.test_lppool_with_padding_and_stridec              
   C  rI  )Nr   rJ  r  r   rQ   r  rK  r   r   r1   r1   r2   test_lppool_with_dilations  r  z-TestShapeInference.test_lppool_with_dilationsc                 C  rN  )
Nr   rJ  r  r   r  rQ   r   rO  rK  r   r   r1   r1   r2   ;test_lppool_with_same_upper_padding_and_stride_and_dilation  rQ  zNTestShapeInference.test_lppool_with_same_upper_padding_and_stride_and_dilationc              	   C  sV   |  dtjdfdtjdfgtdddgdgddgdgg }| |tdtjd	g d S )
Nr   rJ  roisrQ   r;   
MaxRoiPoolr   rQ   pooled_shape)rQ   r   rQ   rQ   rA  r   r1   r1   r2   test_roipool  s   

zTestShapeInference.test_roipoolr  c              	   C  s`   |  dtjdfdtjdfgtdddgdgddgd	gg }| jtjj| j	|t
t|gd
 d S )Nr   rJ  r  r  r  r   r'   rQ   r  r   )rc   r   r   r[   r   r   rl   rm   r   rr   r   r   r   r   r1   r1   r2   "test_roipool_negative_pooled_shape  s   


z5TestShapeInference.test_roipool_negative_pooled_shapec                 C  r  )NrN   rf  LpNormalizationr?  r   r   r1   r1   r2   test_lp_norm	  r  zTestShapeInference.test_lp_normc                 C  sX   |  dtjdfdtjdfdtjdfgtdg ddggg }| |tdtjdg d S )	NrN   rf  r  rk  r   InstanceNormalization)rN   r  r   r?  r   r   r1   r1   r2   test_instance_norm  rC  z%TestShapeInference.test_instance_normc                 C  r  )Nr   rJ  GlobalMaxPoolr   r  r   r   r1   r1   r2   test_global_maxpool!  r  z&TestShapeInference.test_global_maxpoolc                 C  r  )Nr   rJ  GlobalAveragePoolr   r  r   r   r1   r1   r2   test_global_averagepool+  r  z*TestShapeInference.test_global_averagepoolc                 C  r  )Nr   rJ  GlobalLpPoolr   r  r   r   r1   r1   r2   test_global_lppool5  r  z%TestShapeInference.test_global_lppoolc              	   C  sT   |  dtjdfdtjdfgtdddgdddgdgg }| |tdtjd	g d S )
Nr      0   r  r  r  r  r  r   r   r  r   rQ   r"  )r  r  !   r  r   r   r1   r1   r2   test_conv_transpose?  ry  z&TestShapeInference.test_conv_transposec              
   C  sZ   |  dtjdfdtjdfgtdddgdddgg dd	gg }| |tdtjd
g d S )Nr   r  r  r  r  r   rQ   rs  )r#  r)  r  r  r   r   r   r   r1   r1   r2   test_conv_transpose_with_padsL     

z0TestShapeInference.test_conv_transpose_with_padsc                 C  `   |  dtjdfdtjdfgtdddgdddgg dd	d	gd
gg }| |tdtjdg d S )Nr   r  r  r  r  r   rQ   rs  $   )r#  r)  r  )r  r  r  r  r   r   r1   r1   r2   %test_conv_transpose_with_output_shape]  rn  z8TestShapeInference.test_conv_transpose_with_output_shapec                 C  s`   |  dtjdfdtjdfgtdddgdddgddgg d	d
gg }| |tdtjdg d S )Nr   r  r  )r  r  NNr  r   r   rQ   rs  )r  r#  r)  r  r   r   r1   r1   r2   %test_conv_transpose_with_kernel_shapes  rn  z8TestShapeInference.test_conv_transpose_with_kernel_shapec                 C  r  )Nr   r  r  r  r  r   rQ   rs  r   )r#  r)  r-  )r  r  "   r  r   r   r1   r1   r2   "test_conv_transpose_with_dilations  rn  z5TestShapeInference.test_conv_transpose_with_dilationsc                 C  s\   |  dtjdfdtjdfgtdddgdddgg ddd	gg }| |tdtjd
g d S )Nr   r  r  r  r  r   rQ   rs  )r#  r)  r  )r  r  r   r   r   r   r1   r1   r2   test_conv_transpose_with_group  s$   


z1TestShapeInference.test_conv_transpose_with_groupc                 C  sb   |  dtjdfdtjdfgtdddgdddgg ddd	d	gd
gg }| |tdtjdg d S )Nr   r  r  r  r  r   rQ   rs  r  )r#  r)  r  r  )r  r  r  r  r   r   r1   r1   r2   /test_conv_transpose_with_group_and_output_shape  s&   

zBTestShapeInference.test_conv_transpose_with_group_and_output_shapec                 C  sn   |  dtjdfdtjdfdtjdfgtdg dd	d
ddgg ddgg }| jtjjtjjt	
|dd d S )Nr   rs  r  r}  r  r  r  )r   r  r  r   r  r   )r   r   r   r   )r  r#  r)  Tri   )rc   r   r   r   r   rl   rm   r   rn   r   rk   r   r1   r1   r2   +test_conv_transpose_with_pads_and_auto_pads  s,   




z>TestShapeInference.test_conv_transpose_with_pads_and_auto_padsc              
   C  sV   |  dtjdfdtjdfgtdddgddddgd	gg }| |tdtjd
g d S )Nr   r  r  r  r  r   r  rQ   r  )r  r  r  r  r   r   r1   r1   r2   test_conv_transpose_auto_pads  s"   

	z0TestShapeInference.test_conv_transpose_auto_padsc              	   C  sF   |  dtjdfgtdddg ddgg }| |tdtjdg d S )Nr   r  MeanVarianceNormalizationr   )r   rQ   r   r  r   r   r1   r1   r2   test_mvn_function_output_shape  r   z1TestShapeInference.test_mvn_function_output_shapec           	   
   C  s   d}d}d}d}t dtjd t dtjd g}t dtjd t dtjd g}ttd	dgdgtd	dgdggd
||}| dtj||ffdtj|||ffgtdg dddgd|dgg }| j|t dtj||ft dtj|||fgt	t
dgd d S )Nr   sequencerQ   r   loop_state_inr  loop_state_outr  r-  subgraphloop_state_orig
scan_inputScan)r  r  r  loop_state_finalscan_outputnum_scan_inputsbodyr  r   r!   r   rY   r   r   r   rc   r   r   r   r   )	r\   
batch_sizeseq_len
input_sizeloop_state_sizer^   output_value_infosr  r}   r1   r1   r2   	test_scan  sV   
	
zTestShapeInference.test_scanc              
   C  s   d}d}d}t dtjd t dtjd g}t dtjd t dtjd g}ttddgdgtddgdggd	||}| d
tj|ffdtj||ffgtdd
dgddgd|dgg }| j|t dtj|ft dtj||fgt	t
dgd d S )Nr  rQ   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   r1   r2   test_scan_opset9@  sT   
	

z#TestShapeInference.test_scan_opset9c           	      C  s   d}d}d}d}t dtjd t dtjd g}t dtjd t dtjd g}ttd	dgdgtd	dgdggd
||}| dtj|ffdtj|||ffgtdddgddgd|dgdgg }| j|t dtj|ft dtj|||fgt	t
dgd d S )Naxis0r  rQ   r   r  r  r  r  r-  r  r  r  r  r  r  r   )r  r  scan_input_axesr!  r   r  	r\   
axis_0_lenr  r  r  r^   r  r  r}   r1   r1   r2   test_scan_opset9_axesy  sX   



z(TestShapeInference.test_scan_opset9_axesc           	      C  s   d}d}d}d}t dtjd t dtjd g}t dtjd t dtjd g}ttd	dgdgtd	dgdggd
||}| dtj|ffdtj|||ffgtdddgddgd|dgdgdgg }| j|t dtj|ft dtj|||fgt	t
dgd d S )Nr  r  rQ   r   r  r  r  r  r-  r  r  r  r  r  r  r   r  r  r  scan_output_axesr!  r   r  r  r1   r1   r2   test_scan_opset9_output_axes  Z   


z/TestShapeInference.test_scan_opset9_output_axesc           	      C  s   d}d}d}d}t dtjd t dtjd g}t dtjd t dtjd g}ttd	dgdgtd	dgdggd
||}| dtj|ffdtj|||ffgtdddgddgd|dgdgdgg }| j|t dtj|ft dtj|||fgt	t
dgd d S )Nr  r  rQ   r   r  r  r  r  r-  r  r  r  r  r  r  r   r[  r  r!  r   r  r  r1   r1   r2   test_scan_opset9_negative_axes  r  z1TestShapeInference.test_scan_opset9_negative_axesc              
   C  s   t tdddgdggdg tdtjd g}t tdddgdggd	g tdtjd g}| d
tjdfdtjdfdtjdfdtjdfgtdd
gdg||dgg }| j	|tdtjdgt
tdgd d S )Nrr  current_value	add_valuethen_outputthen_subgraphSub	sub_valueelse_outputelse_subgraphcondr  If	if_outputthen_branchelse_branchr1  r   )r   r   r   r!   r   rY   rc   r+  r   r   r   r   r\   r  r  r}   r1   r1   r2   test_if_ver1&  sB   



	

zTestShapeInference.test_if_ver1c              
   C  s   t tdddgdggdg tdtjd g}t tdddgdggd	g tdtjd g}| d
tjdfdtjdfdtjdfdtjdfgtdd
gdg||dgg }| 	|tdtjdg d S )Nrr  r  r  r  r  r  r  r  r  r  r  r  r  r  
r   r   r   r!   r   rY   rc   r+  r   r   r  r1   r1   r2   test_ifR  >   



	zTestShapeInference.test_ifc              
   C  s   t tdddgdggdg tdtjdg}t tdddgd	ggd
g td	tjdg}| dtjdfdtjdfdtjdfdtjdfgtddgdg||dgg }| 	|tdtjdg d S )Nrr  r  r  r  r  r  r  r  r  r  r;   r  r  r  r  rT   r  r  r1   r1   r2   3test_if_with_different_shapes_in_then_else_branches|  r  zFTestShapeInference.test_if_with_different_shapes_in_then_else_branchesc              
   C  l   t d}t d}| dtjdfdtjdfdtjdfgtddgd	g||d
gg }| |td	tjd g d S )NzQthen_graph () => (then_output) { then_output = ReduceSum <keepdims=0> (X, axes) }zKelse_graph () => (else_output) { else_output = ReduceSum <keepdims=0> (X) }r  r  r   r   r  r  r  r  r  r  	r"   rc   r   r+  r   r[   r   r   r!   r\   
then_graph
else_graphr}   r1   r1   r2   test_if_no_shape_in_then_branch  0   


	z2TestShapeInference.test_if_no_shape_in_then_branchc              
   C  r   )NzKthen_graph () => (then_output) { then_output = ReduceSum <keepdims=0> (X) }zQelse_graph () => (else_output) { else_output = ReduceSum <keepdims=0> (X, axes) }r  r  r   r  r  r  r  r  r  r  r1   r1   r2   test_if_no_shape_in_else_branch  r  z2TestShapeInference.test_if_no_shape_in_else_branchc              
   C  s  t jtjdgd}t |}t d|}t tddgdggdg |g}t jtjdgd}t |}t d|}t tdd	gdggd
g |g}| dtj	dfdtj
dfd	tj
dfgtddgdg||dgg }	t jtj
dd}
t |
}t d|}| |	|g d S )Nr   r   r   then_optional_outputre  then_tensor_valuer  r;   else_optional_outputelse_tensor_valuer  r  r  r  r  r  r  rT   )r   rh  r   rY   ri  rj  r   r   rc   r+  r   r   )r\   then_tensor_protothen_optional_type_protothen_optional_vir  else_tensor_protoelse_optional_type_protoelse_optional_vir  r}   output_tensor_protooutput_optional_type_protooutput_optional_vir1   r1   r2   <test_if_with_different_optional_shapes_in_then_else_branches  sn   




	zOTestShapeInference.test_if_with_different_optional_shapes_in_then_else_branchesc              
   C  sZ   |  dtjdfdtjdfgtdddgdddgddgdgg }| |tdtjdg d S )	NxTrs  xI	MaxUnpoolr   rQ   r{  r  r   r   r1   r1   r2   )test_maxunpool_shape_without_output_shape"  r  z<TestShapeInference.test_maxunpool_shape_without_output_shapec              
   C  sp   |  dtjdfdtjdfdtjdfgtdg ddd	d	gd	d	gd
gtdtjd g}| |tdtjd g d S )Nr  rs  r  r  rk  r  )r  r  r  r   rQ   r{  )rc   r   r   r   r!   r   r   r1   r1   r2   &test_maxunpool_shape_with_output_shape3  s$   


	z9TestShapeInference.test_maxunpool_shape_with_output_shapec              	   C  sj   | j dtjdfdtjdfgtdddgdddgddgdgg tdtjdd	ggd
}| tjj	| j
| d S )Nr  rs  r  r1   r  r   rQ   r{  r   r  )rc   r   r   r[   r   r   r   rl   rm   r   rr   r   r1   r1   r2   #test_maxunpool_rank0_indices_raisesI  s   

z6TestShapeInference.test_maxunpool_rank0_indices_raisesc              	   C  sd   | j dtjdfdtjdfgtdddgdddgdgg tdtjdd	ggd
}| tjj| j	| d S )Nr   r  r  r1   r  r   rQ   r"          r  )
rc   r   r   r   r   r   rl   rm   r   rr   r   r1   r1   r2   'test_conv_transpose_rank0_weight_raises[  s   

z:TestShapeInference.test_conv_transpose_rank0_weight_raisesc                 C  j   | j dtjdfdtjdfgtdddgdddgdgg tdtjdttd	gd
}| tj	j
| j| d S )Nr   r  r  r!  r  r   rQ   r"  r!  r  rc   r   r   r   r   r~   r)   r   rl   rm   r   rr   r   r1   r1   r2   'test_conv_transpose_rank1_weight_raisesi     

z:TestShapeInference.test_conv_transpose_rank1_weight_raisesc                 C  r   )Nr   r  r  )r  r  r  r   rQ   r"  i   r  r"  r   r1   r1   r2   'test_conv_transpose_rank2_weight_raisesw  r$  z:TestShapeInference.test_conv_transpose_rank2_weight_raisesc                 C  sj   | j dtjdfdtjdfgtdddgdddgdgg tdtjdttd	gd
}| tj	j
| j| d S )Nr   )r  r  r  r  r  r   rQ   r"  i  r  r"  r   r1   r1   r2   &test_conv_transpose_rank2_input_raises  r$  z9TestShapeInference.test_conv_transpose_rank2_input_raisesc              	   C  r   | j dtjdfdtjdfgtdddgdddgdgg tdtjdd	ggd
}| jtjj| j	|t
tdgd d S )Nr   r  r  r1   r  r   rQ   r"  r  r  r  r   rc   r   r   r   r   r   rl   rm   r   rr   r   r   r   r   r1   r1   r2   /test_conv_transpose_rank0_weight_raises_opset11     


zBTestShapeInference.test_conv_transpose_rank0_weight_raises_opset11c              	   C  r'  )Nr   r  r  r1   r  r   rQ   r"  r  r  r   r   r(  r   r1   r1   r2   .test_conv_transpose_rank0_weight_raises_opset1  r*  zATestShapeInference.test_conv_transpose_rank0_weight_raises_opset1c              	   C  x   | j dtjdfdtjdfgtdddgdddgddgdgg tdtjdd	ggd
}| jtjj	| j
|ttdgd d S )Nr  rs  r  r1   r  r   rQ   r{  r   r  r!  r   rc   r   r   r[   r   r   r   rl   rm   r   rr   r   r   r   r   r1   r1   r2   *test_maxunpool_rank0_indices_raises_opset9  $   


z=TestShapeInference.test_maxunpool_rank0_indices_raises_opset9c              	   C  r,  )Nr  rs  r  r1   r  r   rQ   r{  r   r  r  r   r-  r   r1   r1   r2   +test_maxunpool_rank0_indices_raises_opset11  r/  z>TestShapeInference.test_maxunpool_rank0_indices_raises_opset11c                 C  sV   |  dtjdfdtjdfdtjdfgtdg dd	gg }| |td	tjd
g d S )Nr  r/  depthr1   valuesr   OneHotr  r1  r2  r   )rQ   rQ   Nrc   r   r[   r   r   r   r!   r   r1   r1   r2   test_onehot_without_axis  s   


	z+TestShapeInference.test_onehot_without_axisc              	   C  sZ   |  dtjdfdtjdfdtjdfgtdg dd	d
dgg }| |td	tjdg d S )Nr  rQ   r   r;   r1  r  r2  r   r3  r4  r   r   r9  )rQ   Nr   r;   r5  r   r1   r1   r2   test_onehot_with_axis  s   


	z(TestShapeInference.test_onehot_with_axisc              	   C  sh   | j dtjdfdtjdfdtjdfgtdg dd	gg tdtjdd
gd}| |td	tjdg d S )Nr  r/  r1  r1   r2  r   r3  r4  r   r"  r  )rQ   rQ   r"  rc   r   r[   r   r   r   r   r!   r   r1   r1   r2   test_onehot_without_axis_2  s   



z-TestShapeInference.test_onehot_without_axis_2c              	   C  sl   | j dtjdfdtjdfdtjdfgtdg dd	d
dgg tdtjddgd}| |td	tjdg d S )Nr  r7  r1  r  r2  r   r3  r4  r   r   r9  r9  r  )rQ   r"  r   r;   r:  r   r1   r1   r2   test_onehot_with_axis_2  s   



z*TestShapeInference.test_onehot_with_axis_2c              	   C  s   t dtjdt dtjd t dtjdg}t dtjd t dtjd t dtjd	g}ttd
dgdgtd
dgdgtd
dgdggd||}| dtjdfdtjdfdtjdfdtjd	fgtdg dddg|dgg }| 	|t dtjd t dtjdg d S )Niter_num_inr  cond_inr  r1   cond_outr  r  r   r-  outer_scope_inputr  max_trip_count	cond_origr  r   Loop)rA  rB  r  r  loop_outputr  Nr   
r!   r   r[   rY   r   r   r   r   rc   r   r\   r^   r  r  r}   r1   r1   r2   	test_loop!  sP   



zTestShapeInference.test_loopc              	   C  s   t dtjdt dtjd g}t dtjd t dtjdg}ttddgdgtddgdggd	||}| d
tjdfdtjdfdtjdfgtdd
dgdg|dgg }| 	|t dtjdg d S )Nr=  r  r>  r?  r  r   r-  r@  r  rA  rB  rC  rD  rE  rF  rG  rH  r1   r1   r2   test_loop_no_stateW  s>   



z%TestShapeInference.test_loop_no_statec                 C  sp   |  g tdg dgtdtjdddtddgdgtdtjd	d
dgg }| |tdtjdtdtjdg d S )Nr]  r   r   r3  r^  ConstantOfShaper   r_  r  r   rc   r   r   r   r[   r  r   r!   r   r1   r1   r2   %test_constantofshape_with_input_shape  .   z8TestShapeInference.test_constantofshape_with_input_shapec                 C  R   |  dtjdfgtddgdgtdtjdddgg }| |tdtjd	g d S )
Nr   r   rK  r   r_  r  r   r^  r=  rc   r   r[   r   r   r   r   r!   r   r1   r1   r2   (test_constantofshape_without_input_shape     z;TestShapeInference.test_constantofshape_without_input_shapec                 C  rO  )
Nr   r  rK  r   r_  r  r   r^  r1   rP  r   r1   r1   r2   /test_constantofshape_without_input_shape_scalar  rR  zBTestShapeInference.test_constantofshape_without_input_shape_scalarc                 C  sp   |  g tdg dgtdtjdddtddgdgtdtjdd	dgg }| |tdtjdtdtjdg d S )
Nr]  r   r  r  r^  rK  r   r_  r   rL  r   r1   r1   r2   $test_constantofshape_with_shape_zero  rN  z7TestShapeInference.test_constantofshape_with_shape_zeroc                 C  s`   |  dtjdfdtjdfgtdddgdg dg dg d	d
gg }| |tdtjdg d S )NrN   rf  r   rg  ConvIntegerr   ri  rK  rj  rk  rl  rc   r   r   r   r   r!   r  r   r1   r1   r2   test_convinteger  rn  z#TestShapeInference.test_convintegerc              	   C  sh   |  dtjdfdtjdfdtjdfdtjdfgtdg d	d
g ddgg }| |td
tjdg d S )NrN   rt  r   ru  x_zero_pointr1   y_zero_pointrU  rN   r   rX  rY  r   rv  r,  rw  rc   r   r   r  r   r   r!   r  r   r1   r1   r2   test_convinetger_dilations  $   



z-TestShapeInference.test_convinetger_dilationsc              	   C  sh   |  dtjdfdtjdfdtjdfdtjdfgtdg d	d
g ddgg }| |td
tjdg d S )NrN   rt  r   ru  rX  r1   rY  rU  rZ  r   rv  r"  rz  )rc   r   r  r   r   r   r!   r  r   r1   r1   r2   test_convinteger_strides  r]  z+TestShapeInference.test_convinteger_stridesc              	   C  sT   |  dtjdfdtjdfgtdddgdg ddgg }| |tdtjd	g d S )
NrN   r  r   ru  rU  r   r  r(  r  r[  r   r1   r1   r2   test_convineteger_pads  ry  z)TestShapeInference.test_convineteger_padsc              	   C  sP   |  dtjdfdtjdfgtdddgdddgg }| |tdtjd	g d S )
NrN   rt  r   r  rU  r   r   r  r  )rc   r   r  r   r   r!   r  r   r1   r1   r2   test_convineteger_group'  r  z*TestShapeInference.test_convineteger_groupc              	   C  sh   |  dtjdfdtjdfdtjdfdtjdfgtdg d	d
g ddgg }| |td
tjdg d S )NrN   r  r   ru  rX  r1   rY  rU  rZ  r   r  r(  r  rV  r   r1   r1   r2   'test_convineteger_partial_missing_shape4  s&   



z:TestShapeInference.test_convineteger_partial_missing_shapec              	   C  sT   |  dtjdfdtjdfgtdddgdg ddgg }| |tdtjd g d S )	NrN   r  r   r  rU  r   r  r(  rV  r   r1   r1   r2   .test_convineteger_partial_missing_weight_shapeK  ry  zATestShapeInference.test_convineteger_partial_missing_weight_shapec                 C  s   |  dtjdfdtjdfdtjdfdtjdfdtjdfd	tjdfd
tjdfdtjdfgtdg ddg dg dg ddgg }| |tdtjdg d S )NrN   rf  x_scaler1   rX  r  rg  w_scalew_zero_pointy_scalerY  QLinearConvrN   rc  rX  r  rd  re  rf  rY  r   ri  rK  rj  rk  rl  rc   r   r   r   r   r   r!   r   r1   r1   r2   test_qlinearconvX  s0   








 z#TestShapeInference.test_qlinearconvc                 C     |  dtjdfdtjdfdtjdfdtjdfdtjdfd	tjdfd
tjdfdtjdfgtdg ddg ddgg }| |tdtjdg d S )NrN   rt  rc  r1   rX  r  ru  rd  re  rf  rY  rg  rh  r   rv  r,  rw  ri  r   r1   r1   r2   test_qlinearconv_dilations}  ,   








z-TestShapeInference.test_qlinearconv_dilationsc                 C  rk  )NrN   rt  rc  r1   rX  r  ru  rd  re  rf  rY  rg  rh  r   rv  r"  rz  rc   r   r  r   r   r   r!   r   r1   r1   r2   test_qlinearconv_strides  rm  z+TestShapeInference.test_qlinearconv_stridesc                 C  s   |  dtjdfdtjdfdtjdfdtjdfdtjdfd	tjdfd
tjdfdtjdfgtdg ddg ddgg }| |tdtjdg d S )NrN   r  rc  r1   rX  r  ru  rd  re  rf  rY  rg  rh  r   r  r(  r  )rc   r   r   r   r  r   r   r!   r   r1   r1   r2   test_qlinearconv_pads  rm  z(TestShapeInference.test_qlinearconv_padsc                 C  s   |  dtjdfdtjdfdtjdfdtjdfdtjdfd	tjdfd
tjdfdtjdfgtdg ddddgg }| |tdtjdg d S )NrN   rt  rc  r1   rX  r  r  rd  re  rf  rY  rg  rh  r   r   r  r  rn  r   r1   r1   r2   test_qlinearconv_group  s,   








z)TestShapeInference.test_qlinearconv_groupc                 C  rk  )NrN   r  rc  r1   rX  r  ru  rd  re  rf  rY  rg  rh  r   r  r(  r  ri  r   r1   r1   r2   &test_qlinearconv_partial_missing_shape	  s.   








z9TestShapeInference.test_qlinearconv_partial_missing_shapec                 C  s   |  dtjdfdtjdfdtjdfdtjdfdtjdfd	tjdfd
tjdfdtjdfgtdg ddg ddgg }| |tdtjd g d S )NrN   r  rc  r1   rX  r  r  rd  re  rf  rY  rg  rh  r   r  r(  ri  r   r1   r1   r2   -test_qlinearconv_partial_missing_weight_shape-  rm  z@TestShapeInference.test_qlinearconv_partial_missing_weight_shapec                 C  s   t t t ||t t ||j}| dtj|fdtj	dfdtjdfdtj|fdtj	dfdtjdfdtj	dfd	tjdfgt
d
g ddggg }| |tdtj|g d S Nr   a_scaler1   a_zero_pointr   b_scaleb_zero_pointrf  rY  QLinearMatMul)r   ru  rv  r   rw  rx  rf  rY  r   )r   r   r   r   r   r   rc   r   r   r   r   r   r!   r\   r   r   r   r}   r1   r1   r2   _make_qlinearmatmul_testP  s6   








z+TestShapeInference._make_qlinearmatmul_testc                 C  sL   |  dd |  dd |  dd |  dd |  dd |  dd d S )	Nr   r   r   r   r   r   r   r   )r{  rU  r1   r1   r2   test_qlinearmatmulx     z%TestShapeInference.test_qlinearmatmulc                 C  s   |  dtj|fdtjdfdtjdfdtj|fdtjdfdtjdfdtjdfd	tjdfgtd
g ddggg }| |tdtj|g d S rt  ri  rz  r1   r1   r2   &_make_qlinearmatmul_test_allow_unknown  s*   








z9TestShapeInference._make_qlinearmatmul_test_allow_unknownc                 C  s   |  ddd |  ddd |  ddd |  ddd |  d	dd |  d	d
d |  ddd |  ddd |  d dd  |  d d d  d S r   )r~  rU  r1   r1   r2    test_qlinearmatmul_allow_unknown  s   z3TestShapeInference.test_qlinearmatmul_allow_unknownc                 C  s   t t t ||t t ||j}| dtj|fdtj|fdtjdfdtjdfgt	dg ddggg }| 
|tdtj|g d S )	NAr  rv  r1   rx  MatMulInteger)r  r  rv  rx  r   )r   r   r   r   r   r   rc   r   r   r   r   r!   r  rz  r1   r1   r2   _make_matmulinteger_test  s*   



z+TestShapeInference._make_matmulinteger_testc                 C  sL   |  dd |  dd |  dd |  dd |  dd |  dd d S )Nr   r   r   r   r   r   r   )r  rU  r1   r1   r2   test_matmulinteger  r}  z%TestShapeInference.test_matmulintegerc                 C  sT   |  d|dfd|dfdtjdfgtdg ddggg }| |tdtjdg d S )	NrN   r   rf  r1   rY  QuantizeLinearrN   rf  rY  r   rc   r   r   r   r   r!   r\   r   r}   r1   r1   r2   test_quantizelinear  s   
	z&TestShapeInference.test_quantizelinearc                 C  sN   |  dtjdfdtjdfgtdddgdggg }| |tdtjdg d S )NrN   r   rf  r1   r  r   rc   r   r   r   r   r!   r   r   r1   r1   r2   test_quantizelinear_default_zp  r  z1TestShapeInference.test_quantizelinear_default_zpc                 C  sN   |  dtjdfdtjdfgtdg ddggg }| |tdtjdg d S )NrN   r   rf  r1   r  )rN   rf  r  r   r  r   r1   r1   r2   "test_quantizelinear_optional_input  r  z5TestShapeInference.test_quantizelinear_optional_inputc              	   C  sT   |  dtjdfdtjdfgtdddgdgtjdgg }| |tdtjdg d S NrN   r3  rf  r1   r  r   output_dtype)rc   r   r   r   UINT4r   r!   r   r1   r1   r2    test_quantizelinear_output_dtype  s   z3TestShapeInference.test_quantizelinear_output_dtypec              	   C  s^   |  dtjdfdtjdfdtjdfgtdg ddgtjd	gg }| |tdtjdg d S 
NrN   r3  rf  r1   rY  r  r  r   r  )rc   r   r   UINT16r   r   r!   r   r1   r1   r2   #test_quantizelinear_zp_output_dtype	  s"   


z6TestShapeInference.test_quantizelinear_zp_output_dtypec              	   C  sZ   |  dtjdfdtjdfdtjdfgtdg ddgtjd	gg }| tjj	| j
| d S r  )rc   r   r   r  r   INT4r   rl   rm   r   rr   r   r1   r1   r2   .test_quantizelinear_zp_output_dtype_conflicted  s&   


zATestShapeInference.test_quantizelinear_zp_output_dtype_conflictedc              	   C  sP   |  dtjdfdtjdfgtdddgdgtjdgg }| tjj| j	| d S r  )
rc   r   r   r   r   r   rl   rm   r   rr   r   r1   r1   r2   (test_quantizelinear_invalid_output_dtype6  s    z;TestShapeInference.test_quantizelinear_invalid_output_dtypec                 C  sT   |  dtjdfd|dfdtjdfgtdg ddggg }| |td|dg d S )	NrN   r   rc  r1   rX  DequantizeLinear)rN   rc  rX  r   r  r  r1   r1   r2   test_dequantizelinearM  s   

	z(TestShapeInference.test_dequantizelinearc              	   C  s\   |  dtjdfgtddgg dgg }| |tdtjdtdtjdtdtjdg d S )	NrN   r   DynamicQuantizeLinear)r   rf  rY  r   rf  r1   rY  r  r   r1   r1   r2   test_dynamicquantizelinear^  s   	z-TestShapeInference.test_dynamicquantizelinearc                 C  sN   |  dtjdfdtjdfgtdddgdggg }| |tdtjdg d S )NrN   r  sequence_lensr  ReverseSequencer   rA  r   r1   r1   r2   test_reversesequenceq  r  z'TestShapeInference.test_reversesequencec              
   C  sh   |  dtjdfgtddgg dgg }| |tdtjdtdtjdtdtjdtd	tjdg d S )
Nr   rQ   r   rQ   Uniquer   r  inverse_indicescountsr   rT   r  r  r  r(  r   r1   r1   r2   test_unique_without_axis~  s   z+TestShapeInference.test_unique_without_axisc              
   C  sl   |  dtjdfgtddgg dddgg }| |tdtjdtd	tjd
tdtjd
tdtjd
g d S )Nr   r  r  r  r   r9  r   )rQ   NrQ   r  rT   r  r  r(  r   r1   r1   r2   test_unique_with_axis  s&   z(TestShapeInference.test_unique_with_axisc                 C  s   |  dtjdfgtddgdggg }| |tdtjdg |  dtjdfgtddgdggg }| |tdtjdg d S )Nr   r$  Detr   r1   )r   r;   r  r8  r8  r  r   r   r1   r1   r2   test_det  s   zTestShapeInference.test_detc              	   C  `   | j dtjdfdtjdfgtdddgdggg tdtjddgd}| |tdtjd	g d S )
NrN   r  repeatsr   Tiler   rv  r  r   r1  r  r5  r   r1   r1   r2   	test_tile     zTestShapeInference.test_tilec                 C  sv   | j dtjdfdtjdfgtdddgdggg tdtjdtjg ddd	 d
dgd}| 	|t
dtjdg d S )NrN   r  r  r   r  r   rv  r  r|  Tr~  r  r  rD  r   r1   r1   r2   test_tile_raw_input_data  s    z+TestShapeInference.test_tile_raw_input_datac                 C  N   |  dtjdfdtjdfgtdddgdggg }| |tdtjdg d S )NrN   r  r  r   r  r   r=  rA  r   r1   r1   r2   test_tile_rank_inference  r  z+TestShapeInference.test_tile_rank_inferencez-ONNX_ML required to test ai.onnx.ml operatorsc                 C  sz   |  dtjdfgtddgddgtddgddgd	d
gdgg }| j|tdtjdtdtjdgttd	tt	dgd d S )NrN   r  LinearClassifierr   r   g-C6J?g-C6Jry  r   rQ   r.   coefficients
interceptsclasslabels_intsr  r   r  r   
rc   r   r   r   r   r   r!   r[   r   r   r   r1   r1   r2   test_linearclassifier_1D_input  .   
z1TestShapeInference.test_linearclassifier_1D_inputc                 C  sz   |  dtjdfgtddgddgtg dg dg dd	gg }| j|tdtjd
tdtjdgttdtt	dgd d S )NrN   r  r  r   r   )皙?皙?g333333?皙?r3  g333333?)ry  ry  g      @rv  r  rk  r  r   r  r   r  r   r1   r1   r2   test_linearclassifier_2D_input  r  z1TestShapeInference.test_linearclassifier_2D_inputc              
   C  s^   |  dtjdfdtjdfdtjdfgtdg dd	gd
ddgg }| |td	tjdg d S )NrN   r  r  num_roisr   batch_indicesr  RoiAlignrN   r  r  r   r1  r;   )output_heightoutput_width)r  r  r1  r;   rA  r   r1   r1   r2   test_roialign_symbolic  s&   


	z)TestShapeInference.test_roialign_symbolicc                 C  X   |  dtjdfdtjdfdtjdfgtdg dd	ggg }| |td	tjd
g d S )NrN   r  r  r  r  r  r  r  r   )r  r  r   r   rA  r   r1   r1   r2   test_roialign_symbolic_defaults/  s   


	z2TestShapeInference.test_roialign_symbolic_defaultsc                 C  r  )NrN   r  r  r  r  )r'  r  r  r   )r'  r  r   r   rA  r   r1   r1   r2   test_roialign_num_rois>  rC  z)TestShapeInference.test_roialign_num_roisc                 C  sb   |  dtjdfdtjdfdtjdfdtjdfgtdg d	d
ggg }| |td
tjdg d S )Nr   )r  	num_headsr  r  	cos_cachemax_seq_lenhead_size_div_2	sin_cacheposition_idsr  r  RotaryEmbeddingr   r  r  r  r   rA  r   r1   r1   r2   test_rotaryembedding_4dL  s*   



z*TestShapeInference.test_rotaryembedding_4dc              	   C  sf   |  dtjdfdtjdfdtjdfdtjdfgtdg d	d
gddgg }| |td
tjdg d S )Nr   )r  r  r  r  r  r  r  r  r  r  r   r   )r  rA  r   r1   r1   r2   test_rotaryembedding_3df  s,   



z*TestShapeInference.test_rotaryembedding_3dLabelEncoderT)skip_on_emptyc                 C  sH  |  |dk d g d}g d}g d}| dtjdfgtddgd	gt||d
gg }| j|td	tjdgt	t|t	t
dgd | dtjdfgtddgd	gt||dgg }| j|td	tjdgt	t|t	t
dgd | dtjdfgtddgd	gt||dgg }| j|td	tjdgt	t|t	t
dgd | dtjdfgtddgd	gt||dgg }| j|td	tjdgt	t|t	t
dgd | dtjdfgtddgd	gt||dgg }| j|td	tjdgt	t|t	t
dgd | dtjdfgtddgd	gt||dgg }| j|td	tjdgt	t|t	t
dgd d S )NrQ   z7keys_* attributes were introduced in ai.onnx.ml opset 2)r  mr   )g{GW@g      B@g     X)r2     V   rN   r  r   r  r   )r.   keys_stringsvalues_int64sr  r   r   )r.   keys_int64svalues_stringsr   )r.   keys_floatsr  r  )r.   r  values_floatsr1   )r.   r  r  r   )r.   r  r  )r   rc   r   r   r   r   r   r!   r[   r   r   r   )r\   r   r0   string_list
float_list
int64_listr}   r1   r1   r2   test_label_encoder_string_int64  s   
	
	
	
	
	

z2TestShapeInference.test_label_encoder_string_int64c                 C  s   |  |dk d tdtjdgg d}tdtjdgg d}| dtjdfgtd	dgd
gt||tdtjdgdgdgg }| j|t	d
tjdgt
t|t
tdgd d S )Nr   z7tensor attributes were introduced in ai.onnx.ml opset 4keys_tensorr   r   ccdddvalues_tensorr   rQ   r   r   rN   rK  Nr   r2  r  r   default_tensorr   r   r.   r  r  r  r  r   )r   r   r   r   r[   rc   r   r   r   r!   r   r   )r\   r   r0   
key_tensorr  r}   r1   r1   r2   $test_label_encoder_tensor_attributes   s@   
z7TestShapeInference.test_label_encoder_tensor_attributesc                 C  s  |  |dk d tdtjdgg d}tdtjdgg d}tt|ttdg}| dtjd	fgt	d
dgdgt||tdtj
dgdgdgg }| jtjj| j||d | dtjd	fgt	d
dgdgt|g dtdtjddgddgdgg }| jtjj| j||d d S )Nr   z2tensor attributes introduced in ai.onnx.ml opset 4r  r  r  r  r  rN   r  r  r   r  r   r   r  r   rQ   r   r   )r.   r  r  r  )r   r   r   r   r[   r   r   r   rc   r   r  r   rl   rm   r   rr   )r\   r   r0   r  r  r   r}   r1   r1   r2   ;test_label_encoder_tensor_attributes_invalid_configurations<   sl   
zNTestShapeInference.test_label_encoder_tensor_attributes_invalid_configurationsr   r2  indices_shaper  r   c                 C  sT   t  }|j| t|}|jtdtj	|f| |j
tdtj	|| |S )Nspvalspind)r   r  extendr   r2  CopyFromr   r   r   r[   r  )r\   r   r2  r  r  sparsennzr1   r1   r2   make_sparse   s   zTestShapeInference.make_sparsec              	   C  sZ   dg}|  |g ddgg d}| g tdg dg|dgg }| |tdtj|g d S )Nr  )r
  r  r  r   )r!     Q   r]  r   )sparse_value)r  rc   r   r   r!   r   r[   )r\   y_shapey_valuer}   r1   r1   r2   test_constant_sparse   s   z'TestShapeInference.test_constant_sparsec              	   C  :   |  g tdg dgddgg }| |tdtjg g d S )Nr]  r   *   )	value_int)rc   r   r   r!   r   r[   r   r1   r1   r2   test_constant_value_int      z*TestShapeInference.test_constant_value_intc              	   C  H   g d}|  g tdg dg|dgg }| |tdtjt|gg d S )Nrv  r]  r   )
value_ints)rc   r   r   r!   r   r[   r   )r\   r  r}   r1   r1   r2   test_constant_value_ints      z+TestShapeInference.test_constant_value_intsc              	   C  r  )Nr]  r   gQ?)value_float)rc   r   r   r!   r   r   r   r1   r1   r2   test_constant_value_float   r  z,TestShapeInference.test_constant_value_floatc              	   C  r  )N)rd  re  g333333?r]  r   )value_floats)rc   r   r   r!   r   r   r   )r\   r	  r}   r1   r1   r2   test_constant_value_floats   r  z-TestShapeInference.test_constant_value_floatsc              	   C  r  )Nr]  r   zString value)value_string)rc   r   r   r!   r   r   r   r1   r1   r2   test_constant_value_string   r  z-TestShapeInference.test_constant_value_stringc              	   C  r  )N)onr  rN   r]  r   )value_strings)rc   r   r   r!   r   r   r   )r\   r  r}   r1   r1   r2   test_constant_value_strings   s   z.TestShapeInference.test_constant_value_stringsc                 C  s   | j dtjdfdtjdfdtjdfgtdg ddggg tdtjddtdtjdd	tdtjdd
gd}| |tdtjd
g d S )Nr  r1   limitdeltaRanger  r  r  r  r  r  r   r  )rc   r   r   r   r   r   r!   r   r1   r1   r2   
test_range      


zTestShapeInference.test_rangec              
   C  s   t  }d|_t j|_|jdg | jdt jdfdt jdfdt jdfgtdg ddggg tdt jdd	tdt jdd
|gd}| 	t
jj| j| d S )Nr  rQ   r  r1   r  r  r  r  r  r  r  )r   r-   r   	data_type
int64_datar  rc   r   r   r   rl   rm   r   rr   r\   
bad_tensorr}   r1   r1   r2   test_range_initializer_invalid   s"   


z1TestShapeInference.test_range_initializer_invalidc              
   C  s   t dtjdtjdgdd dd}d|_| jd	tjdfd
tjdfdtjdfgtdg ddggg t d	tjddt d
tjdd|gd}| 	t
jj| j| d S )Nr  r1   rd  r{  r|  Tr~      r  r  r  r  r  r  r  r  )r   r   r   r   r  r  raw_datarc   r   r   rl   rm   r   rr   r  r1   r1   r2   &test_range_initializer_invalid_rawdata   s*   


z9TestShapeInference.test_range_initializer_invalid_rawdatac              
   C  x   | j dtjdfdtjdfdtjdfgtdg ddggg tdtjddtdtjdd	gd
}| |tdtjdg d S Nr  r1   r  r  r  r  r  r  r  r  rT   )rc   r   r  r   r   r   r!   r   r1   r1   r2   test_range_rank_inference!  rG  z,TestShapeInference.test_range_rank_inferencec                 C     | j dtjdfdtjdfdtjdfgtdg ddggg tdtjddtdtjdd	tdtjdd
gd}| |tdtjdg d S Nr  r1   r  r  r  r  r  r  r  r   r  rT   rc   r   r   r   r   r   r!   r   r1   r1   r2   test_range_float16.!  r  z%TestShapeInference.test_range_float16c                 C  r"  r#  rc   r   r(  r   r   r   r!   r   r1   r1   r2   test_range_bfloat16A!  r  z&TestShapeInference.test_range_bfloat16c              
   C  r  r   r$  r   r1   r1   r2   !test_range_float16_rank_inferenceT!  rG  z4TestShapeInference.test_range_float16_rank_inferencec              
   C  r  r   r&  r   r1   r1   r2   "test_range_bfloat16_rank_inferencef!  rG  z5TestShapeInference.test_range_bfloat16_rank_inferencec                 C  r  )NrN   r  r  r   GatherNDr   r  rA  r   r1   r1   r2   test_gatherndx!  r  z TestShapeInference.test_gatherndc              	   C  R   |  dtjdfdtjdfgtdddgdgddgg }| |tdtjd	g d S )
NrN   rA  r  r   r*  r   r   )
batch_dimsr/  rA  r   r1   r1   r2   test_gathernd_batchdim_1!  rr  z+TestShapeInference.test_gathernd_batchdim_1c                 C  L   |  dtjdfdtjdfgtdddgdgg }| |tdtjdg d S )NrN   r  r:  r  CumProdr   r   r   r1   r1   r2   test_cumprod!     zTestShapeInference.test_cumprodc                 C  r0  )NrN   r   r:  r  CumSumr   r   r   r1   r1   r2   test_cumsum!  r3  zTestShapeInference.test_cumsumc                 C  sN   |  dtjdfdtjdfgtdddgdggg }| |tdtjdg d S )Nboxesr   r   r   r.  )r   r;   r   NonMaxSuppressionr   rF  r(  r   r1   r1   r2   test_nonmaxsuppression!  r  z)TestShapeInference.test_nonmaxsuppressionc                 C  s6   |  g tdg dggg }| |tdtjd g d S )NSequenceEmptyr  )rc   r   r   r    r   r   r   r1   r1   r2   test_sequence_empty!  s   z&TestShapeInference.test_sequence_emptyc                 C  r  )NrY  r   rZ  r[  r]  r^  r`  rb  r   r1   r1   r2   test_sequence_construct!  (   


z*TestShapeInference.test_sequence_constructc                 C  r  )NrY  r   r]  r`  rb  r   r1   r1   r2   !test_sequence_construct_one_input!  s   z4TestShapeInference.test_sequence_construct_one_inputc                 C  sX   |  dtjdfdtjdfdtjdfgtdg ddggg }| |tdtjd g d S )	NrY  r   rZ  r   r[  r]  r^  r`  rb  r   r1   r1   r2   !test_sequence_construct_diff_rank!  r=  z4TestShapeInference.test_sequence_construct_diff_rankc                 C  r  )NrY  r   rZ  r7  r[  r  r]  r^  r`  rQ   r   Nrb  r   r1   r1   r2   %test_sequence_construct_diff_dim_size!  r=  z8TestShapeInference.test_sequence_construct_diff_dim_sizec                 C  s~   |  dtjdfdtjdfdtjdfdtjdfgtdg ddgtd	ddgd
ggg }| |tdtjdtd
tjdg d S )NrY  r   rZ  r[  input4r]  r^  r_  SequenceInsertr`  rb  r   r1   r1   r2   test_sequence_insert"  2   



z'TestShapeInference.test_sequence_insertc                 C  s~   |  dtjdfdtjdfdtjdfdtjdfgtdg dd	gtd
d	dgdggg }| |td	tjdtdtjd g d S )NrY  r   rZ  r[  rB  r   r]  r^  r_  rC  r`  rb  r   r1   r1   r2   test_sequence_insert_diff_rank."  rE  z1TestShapeInference.test_sequence_insert_diff_rankc                 C  s~   |  dtjdfdtjdfdtjdfdtjdfgtdg d	d
gtdd
dgdggg }| |td
tjdtdtjdg d S )NrY  r   rZ  r[  r\  rB  rQ   r;   rQ   r]  r^  r_  rC  r`  ra  rQ   NNrb  r   r1   r1   r2   test_sequence_insert_diff_shapeL"  rE  z2TestShapeInference.test_sequence_insert_diff_shapec                 C  s~   |  dtjdfdtjdfdtjdfdtjdfgtdg dd	gtd
d	dgdggg }| |td	tjdtdtjdg d S )NrY  r   rZ  r[  indr1   r]  r^  r_  
SequenceAtr  rc   r   r   r[   r   r   r    r!   r   r1   r1   r2   test_sequence_atj"  *   



z#TestShapeInference.test_sequence_atc                 C  s~   |  dtjdfdtjdfdtjdfdtjdfgtdg d	d
gtdd
dgdggg }| |td
tjd tdtjd g d S )NrY  r   rZ  r   r[  rJ  r1   r]  r^  r_  rK  r  rL  r   r1   r1   r2   test_sequence_at_unknown_shape"  s&   



z1TestShapeInference.test_sequence_at_unknown_shapec                 C  s~   |  dtjdfdtjdfdtjdfdtjdfgtdg d	d
gtdd
dgdggg }| |td
tjdtdtjdg d S )NrY  r   rZ  r7  r[  rJ  r1   r]  r^  r_  rK  r  r@  rL  r   r1   r1   r2   !test_sequence_at_unknown_dim_size"  rN  z4TestShapeInference.test_sequence_at_unknown_dim_sizec                 C  s~   |  dtjdfdtjdfdtjdfdtjdfgtdg dd	gtd
d	dgdggg }| |td	tjdtdtjdg d S )NrY  r   rZ  r[  rJ  r1   r]  r^  r_  SequenceEraser`  rc   r   r   r[   r   r   r    r   r1   r1   r2   test_sequence_erase"  .   



z&TestShapeInference.test_sequence_erasec                 C  s~   |  dtjdfdtjdfdtjdfdtjdfgtdg d	d
gtdd
dgdggg }| |td
tjdtdtjdg d S )NrY  rQ   r   rN   rZ  r[  )rQ   r;   rN   rJ  r1   r]  r^  r_  rQ  r`  rQ   NrN   rR  r   r1   r1   r2   !test_sequence_erase_diff_dim_size"  rT  z4TestShapeInference.test_sequence_erase_diff_dim_sizec                 C  sr   |  dtjdfdtjdfdtjdfgtdg ddgtddgd	ggg }| |tdtjdtd	tjd
g d S )NrY  rU  rZ  r[  r]  r^  r_  SequenceLengthr   r1   )rc   r   r   r   r   r    r!   r[   r   r1   r1   r2   test_sequence_length"  s(   


z'TestShapeInference.test_sequence_lengthc              	   C  r  )
Nr  r  r   rH  r   SplitToSequencer`  r$  r  r  rc   r   r   r  r   r   r   r    r   r1   r1   r2   test_split_to_sequence#     z)TestShapeInference.test_split_to_sequencec              	   C  r  )
Nr  rZ  rH  r1   r[  r`  r   r  r   r\  r   r1   r1   r2   test_split_to_sequence_scalar#  r^  z0TestShapeInference.test_split_to_sequence_scalarc              	   C  r  )Nr  rZ  r[  r`  r   r  r]  rb  r   r1   r1   r2   test_split_to_sequence_keepdims'#     z2TestShapeInference.test_split_to_sequence_keepdimsc              	   C  r  )Nr  rZ  r[  r`  r   r  rk  rb  r   r1   r1   r2   #test_split_to_sequence_not_keepdims6#  ra  z6TestShapeInference.test_split_to_sequence_not_keepdimsc              	   C  sd   | j dtjdfdtjdfgtdddgdgddgg tdtjdd	gd
}| |tdtjdg d S )Nr  rZ  rH  r   r[  r`  r   r  r$  r  r  r\  r   r1   r1   r2   &test_split_to_sequence_ignore_keepdimsE#  s&   z9TestShapeInference.test_split_to_sequence_ignore_keepdimsc              	   C  r  )Nr  rZ  r[  r`  r   r9  r  rb  r   r1   r1   r2   test_split_to_sequence_axis\#  ra  z.TestShapeInference.test_split_to_sequence_axisc              	   C  r  )Nr  rZ  r[  r`  r[  r9  r]  rb  r   r1   r1   r2   test_split_to_sequence_neg_axisk#  ra  z2TestShapeInference.test_split_to_sequence_neg_axisc              	   C  r  )
Nr  rZ  rH  r   r[  r`  rR  r  Nr   r\  r   r1   r1   r2   "test_split_to_sequence_split_sizesz#  r^  z5TestShapeInference.test_split_to_sequence_split_sizesc              	   C  r  )
Nr  rZ  rH  r1   r[  r`  rk  r  rf  r\  r   r1   r1   r2   $test_split_to_sequence_non_divisible#  r^  z7TestShapeInference.test_split_to_sequence_non_divisiblec              
   C  sv   |  dtjdfdtjdfdtjdfgtdg ddgtddgd	gd
dgg }| |tdtjdtd	tjdg d S )NrY  rU  rZ  r[  r]  r^  r_  ConcatFromSequencer?  r   r9  )Nr   rN   rc   r   r   r   r   r    r!   r   r1   r1   r2   test_concat_from_sequence#  (   


z,TestShapeInference.test_concat_from_sequencec              
   C  sv   |  dtjdfdtjdfdtjdfgtdg ddgtd	dgd
gddgg }| |tdtjd td
tjd g d S )NrY  rU  rZ  r   r[  r]  r^  r_  ri  r?  r   r9  rj  r   r1   r1   r2   'test_concat_from_sequence_unknown_shape#  s$   


z:TestShapeInference.test_concat_from_sequence_unknown_shapec              
   C  v   |  dtjdfdtjdfdtjdfgtdg ddgtd	dgd
gddgg }| |tdtjdtd
tjdg d S )NrY  rU  rZ  rQ   r   rN   r[  r]  r^  r_  ri  r?  r   r9  rV  NNrN   rj  r   r1   r1   r2   *test_concat_from_sequence_unknown_dim_size#  rl  z=TestShapeInference.test_concat_from_sequence_unknown_dim_sizec              
   C  rn  )NrY  rU  rZ  ro  r[  r]  r^  r_  ri  r?  rQ   r9  rV  rH  rj  r   r1   r1   r2   test_concat_from_sequence_axis#  rl  z1TestShapeInference.test_concat_from_sequence_axisc              
   C  rn  )NrY  rU  rZ  ro  r[  r]  r^  r_  ri  r?  r9  rV  rp  rj  r   r1   r1   r2   "test_concat_from_sequence_neg_axis#  rl  z5TestShapeInference.test_concat_from_sequence_neg_axisc                 C  x   |  dtjdfdtjdfdtjdfgtdg ddgtddgd	gd
ddgg }| |tdtjdtd	tjdg d S )NrY  rU  rZ  r[  r]  r^  r_  ri  r?  rQ   r   r:  new_axis)rQ   r   NrN   rj  r   r1   r1   r2   "test_concat_from_sequence_new_axis$  ,   


z5TestShapeInference.test_concat_from_sequence_new_axisc                 C  ru  )NrY  rU  rZ  r[  r]  r^  r_  ri  r?  r'   r   rv  )rQ   r   rN   Nrj  r   r1   r1   r2   &test_concat_from_sequence_neg_new_axis0$  ry  z9TestShapeInference.test_concat_from_sequence_neg_new_axisc              	   C  s   |  dtjdfdtjdfdtjdfdtjdfdtjdfgtdg d	d
dgtdgg }| j|td
tjdtdtjdgt	t
dt	tdgd d S )NRr1   r  r   r   Gr  Adagrad)r{  r  r   r|  r  X_newH_newr<   r2  r   r   rc   r   r   r[   r   r   r   r!   r   r   r   r   r1   r1   r2   test_adagradK$  s2   







zTestShapeInference.test_adagradc                 C  s   |  dtjdfdtjdfdtjdfdtjdfdtjdfd	tjdfd
tjdfdtjdfgtdg dg dtdgg }| j|tdtjdtdtjdtdtjdtdtjdgt	t
dt	tdgd d S )Nr{  r1   r  X1r   X2r  G1G2H1H2r}  )r{  r  r  r  r  r  r  r  )X1_newX2_newH1_newH2_newr<   r  r  r  r  r2  r   r   r  r   r1   r1   r2   test_adagrad_multiplek$  s<   










z(TestShapeInference.test_adagrad_multiplec                 C  s   |  dtjdfdtjdfdtjdfdtjdfdtjdfgtdg d	d
dgddddtdgg }| j|td
tjdtdtjdgt	t
dt	tdgd d S )Nr{  r1   r  r   r   r|  r  Momentum)r{  r  r   r|  r  r~  V_new?rd  {Gz?standardr4  r5  norm_coefficientr  r.   r2  r   r   r  r   r1   r1   r2   test_momentum$  s:   







z TestShapeInference.test_momentumc                 C  s   |  dtjdfdtjdfdtjdfdtjdfdtjdfd	tjdfd
tjdfdtjdfgtdg dg dddddtdgg }| j|tdtjdtdtjdtdtjdtdtjdgt	t
dt	tdgd d S )Nr{  r1   r  r  r   r  r  r  r  V1V2r  )r{  r  r  r  r  r  r  r  )r  r  V1_newV2_newr  rd  r  nesterovr  r  r  r  r  r2  r   r   r  r   r1   r1   r2   test_momentum_multiple$  sD   










z)TestShapeInference.test_momentum_multiplec                 C  s   |  dtjdfdtjdfdtjdfdtjdfdtjdfdtjdfgtd	g d
g dtddddgg }tdtjdtdtjdtdtjdg}| j||ttdtt	dgd d S )Nr{  r1   r  r   r   r|  r  r  Adam)r{  r  r   r|  r  r  )r~  r  r  r  rd  r  r.   r4  r5  r  r~  r  r  r   r2  r   
rc   r   r   r[   r   r   r!   r   r   r   r\   r}   infosr1   r1   r2   	test_adam$  s>   





	
zTestShapeInference.test_adamc                 C  s   |  dtjdfdtjdfdtjdfdtjdfdtjdfd	tjdfd
tjdfdtjdfdtjdfdtjdfg
tdg dg dtddddgg }tdtjdtdtjdtdtjdtdtjdtdtjdtdtjdg}| j||ttdtt	dgd d S )Nr{  r1   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  rd  r  r  r  r  r  r  r  r  r   r2  r   r  r  r1   r1   r2   test_adam_multiple%  sL   









	
z%TestShapeInference.test_adam_multiplec              	   C  sT   |  dtjdfgtdddg ddgg }| j|tdtjdgttdgd	 d S )
NrN   r   NrQ   Padr   r   r   r   r   r   r   r(  r   Nr   r1  r   r   r   r1   r1   r2   test_pad_opset101%  s   
z#TestShapeInference.test_pad_opset10c                 C  sX   |  dtjdfgtdddg ddddgg }| j|tdtjd	gttd
gd d S )NrN   )rQ   r   r   r   r  r   )r   r   r   r   r   r   r   rQ   constantry  )r)  r  r_  )rQ   r   r  r8  r1  r   r   r   r1   r1   r2   test_constant_pad_2d_opset10=%  s$   

z/TestShapeInference.test_constant_pad_2d_opset10c              	   C  r3  )
NrN   r  r)  r+  r  r   r  r  r  r5  r   r1   r1   r2   test_padR%  s   zTestShapeInference.test_padc                 C  N   |  dtjdfdtjdfgtdddgdggg }| |tdtjdg d S )NrN   r+  r  r   r  r   rA  r   r1   r1   r2   test_gatherelements_basick%  r  z,TestShapeInference.test_gatherelements_basicc                 C  sN   |  dtjdfdtjd fgtdddgdggg }| |tdtjd g d S )NrN   r+  r  r  r   rA  r   r1   r1   r2   )test_gatherelements_indices_missing_shapeu%  r  z<TestShapeInference.test_gatherelements_indices_missing_shapec              	   C  r  )NrN   r  Einsumr   zij->jiequationr  r   r   r1   r1   r2   test_einsum_transpose%  r   z(TestShapeInference.test_einsum_transposec              	   C  R   |  dtjdfdtjdfgtdddgdgddgg }| |tdtjdg d S )	NrN   r  r   r  r   i,i->r  r1   r   r   r1   r1   r2   test_einsum_dot%     z"TestShapeInference.test_einsum_dotc              	   C  R   |  dtjdfdtjdfgtdddgdgddgg }| |tdtjdg d S )NrN   r1   r   r  r   z,->r  r   r   r1   r1   r2   test_einsum_scalar%  r  z%TestShapeInference.test_einsum_scalarc              	   C  sB   |  dtjdfgtddgdgddgg }| tjj| j| d S )NrN   r1   r  r   zi->ir  r   r   r1   r1   r2   #test_einsum_scalar_invalid_equation%  s   z6TestShapeInference.test_einsum_scalar_invalid_equationc              	   C  R   |  dtjdfdtjdfgtdddgdgddgg }| |tdtjd	g d S )
NrN   r
  r   )r8  r!  r  r   zij,ab->ijabr  )r   r;   r8  r!  r   r   r1   r1   r2   test_einsum_outer_prod%  r  z)TestShapeInference.test_einsum_outer_prodc              	   C  r  )NrN   r  r  r   zi j->i r  r   r   r   r1   r1   r2   test_einsum_sum_along_dim%  r   z,TestShapeInference.test_einsum_sum_along_dimc              	   C  r  )NrN   )r   r   r   r  r   z... ii ->... ir  r  r   r   r1   r1   r2   test_einsum_ellipsis%  r   z'TestShapeInference.test_einsum_ellipsisc              	   C  r  )
NrN   r   r   rQ   r   r;   r  r   ...ij,...jk->...ikr  r7  r   r   r1   r1   r2   test_einsum_ellipsis_2%  r  z)TestShapeInference.test_einsum_ellipsis_2c              	   C  r  )
NrN   r   r   r  r  r   z...ij,...jkr  r7  r   r   r1   r1   r2   test_einsum_ellipsis_3%  r  z)TestShapeInference.test_einsum_ellipsis_3c              	   C  r  )
NrN   r7  r   )r  r   r;   r  r   r  r  )r  r   r;   r   r   r1   r1   r2   test_einsum_ellipsis_broadcast%  r  z1TestShapeInference.test_einsum_ellipsis_broadcastc              	   C  r  )
NrN   )r;   r  r8  r  r   )r  r!  r1  r  r   zabcd,dfg->abcfgr  )r;   r  r8  r!  r1  r   r   r1   r1   r2   test_einsum_contraction%     

z*TestShapeInference.test_einsum_contractionc              	   C  r  )
NrN   r3  r   r
  r  r   z
ijk,ik->jkr  r  r   r   r1   r1   r2   test_einsum_contraction_2%  r  z,TestShapeInference.test_einsum_contraction_2c              	   C  r  )
NrN   )r;   rQ   r   r   )r;   r   r   r  r   zbij , b jk-> bikr  )r;   rQ   r   r   r   r1   r1   r2   test_einsum_batch_matmul%  r  z+TestShapeInference.test_einsum_batch_matmulc              	   C  r  )
NrN   r   r   r  r  r   zij,klr  )rQ   r   r   r   r   r   r1   r1   r2   test_einsum_left_hand_eqn&  r  z,TestShapeInference.test_einsum_left_hand_eqnc              	   C  sX   |  dtjdfdtjdfdtjdfgtdddgdgddgg }| tjj| j| d S )NrN   r   r   r   r  zi,...j, k, l-> ir  r   r   r1   r1   r2    test_einsum_incorrect_num_inputs&  s   


	z3TestShapeInference.test_einsum_incorrect_num_inputsc              	   C  F   |  dtjdfgtddgdgddgg }| |tdtjdg d S )NrN   r   r  r   r  r  r   r   r1   r1   r2   test_einsum_view_A1&  r   z&TestShapeInference.test_einsum_view_A1c              	   C  r  )NrN   r   r  r   zi->r  r1   r   r   r1   r1   r2   test_einsum_sum_A1(&  r   z%TestShapeInference.test_einsum_sum_A1c              	   C  r  )NrN   r   r   r  r   zi,i->ir  r   r   r1   r1   r2   -test_einsum_element_wise_multiplication_A1_B12&     z@TestShapeInference.test_einsum_element_wise_multiplication_A1_B1c              	   C  r  )	NrN   r   r   r  r   r  r  r1   r   r   r1   r1   r2   test_einsum_inner_product_A1_B1>&  r  z2TestShapeInference.test_einsum_inner_product_A1_B1c              	   C  r  )	NrN   r   r   r  r   zi,j->ijr  r$  r   r   r1   r1   r2   test_einsum_outer_product_A1_B1H&  r  z2TestShapeInference.test_einsum_outer_product_A1_B1c              	   C  r  )NrN   r$  r  r   zij->ijr  r   r   r1   r1   r2   test_einsum_view_A2R&  r   z&TestShapeInference.test_einsum_view_A2c              	   C  r  )NrN   r$  r  r   ijr  r   r   r1   r1   r2   test_einsum_view_A2_2\&  r   z(TestShapeInference.test_einsum_view_A2_2c              	   C  r  )NrN   r$  r  r   jir  r   r   r1   r1   r2   test_einsum_transpose_A2f&  r   z+TestShapeInference.test_einsum_transpose_A2c              	   C  r  )NrN   r$  r  r   zji->ijr  r   r   r1   r1   r2   test_einsum_transpose_A2_to_ijp&  r   z1TestShapeInference.test_einsum_transpose_A2_to_ijc              	   C  r  )NrN   r$  r  r   zii->ir  r   r   r   r1   r1   r2   test_einsum_diag_A2z&  r   z&TestShapeInference.test_einsum_diag_A2c              	   C  r  )NrN   r$  r  r   zii->r  r1   r   r   r1   r1   r2   test_einsum_trace_A2&  r   z'TestShapeInference.test_einsum_trace_A2c              	   C  r  )NrN   r$  r  r   zij->r  r1   r   r   r1   r1   r2   test_einsum_sum_A2&  r   z%TestShapeInference.test_einsum_sum_A2c              	   C  r  )NrN   r$  r  r   zij->jr  r   r   r   r1   r1   r2   test_einsum_sum_columns_A2&  s   z-TestShapeInference.test_einsum_sum_columns_A2c              	   C  r  )NrN   r$  r  r   zij->ir  r   r   r   r1   r1   r2   test_einsum_sum_rows_A2&  r   z*TestShapeInference.test_einsum_sum_rows_A2c              	   C  r  )NrN   r$  r   r  r   z	ij,ij->ijr  r   r   r1   r1   r2   -test_einsum_element_wise_multiplication_A2_B2&  r  z@TestShapeInference.test_einsum_element_wise_multiplication_A2_B2c              	   C  r  )NrN   r$  r   r  r   z	ij,ji->ijr  r   r   r1   r1   r2   7test_einsum_element_wise_multiplication_A2_B2_transpose&  r  zJTestShapeInference.test_einsum_element_wise_multiplication_A2_B2_transposec              	   C  r  )NrN   r$  r   r  r   zij,jkr  r   r   r1   r1   r2   'test_einsum_matrix_multiplication_A2_B2&  r  z:TestShapeInference.test_einsum_matrix_multiplication_A2_B2c              	   C  r  )NrN   r$  r   r  r   z	ij,jk->ikr  r   r   r1   r1   r2   -test_einsum_matrix_multiplication_A2_B2_to_ik&  r  z@TestShapeInference.test_einsum_matrix_multiplication_A2_B2_to_ikc              	   C  r  )NrN   rQ  r   r  r   zbij,bjk->bikr  r   r   r1   r1   r2   'test_einsum_matrix_multiplication_A3_B3&  r  z:TestShapeInference.test_einsum_matrix_multiplication_A3_B3c              	   C  r  )NrN   rQ  r   r  r   zbij,bkj->bikr  r   r   r1   r1   r2   1test_einsum_matrix_multiplication_A3_B3_transpose&  r  zDTestShapeInference.test_einsum_matrix_multiplication_A3_B3_transposec              	   C  r  )NrN   r$  r   r  r   z	ij,kj->ikr  r   r   r1   r1   r2   test_einsum_inner_product_A2_B2&  r  z2TestShapeInference.test_einsum_inner_product_A2_B2c              	   C  r  )	NrN   r$  r   r  r   z
ij,kj->ikjr  )r   r   r   r   r   r1   r1   r2   $test_einsum_row_multiplication_A2_B2 '  r  z7TestShapeInference.test_einsum_row_multiplication_A2_B2c              	   C  r  )	NrN   r$  r   r  r   zij,kl->ijklr  )r   r   r   r   r   r   r1   r1   r2   &test_einsum_value_multiplication_A2_B2'  r  z9TestShapeInference.test_einsum_value_multiplication_A2_B2c              	   C  R   |  dtjdfdtjdfgtdddgdgddgg }| |tdtjdg d S )	NrN   r1   r   r$  r  r   z,ij->ijr  r   r   r1   r1   r2   test_einsum_scalar_times_array'  r  z1TestShapeInference.test_einsum_scalar_times_arrayc              	   C  r  )	NrN   r$  r   r   r  r   zij,j->ir  r   r   r1   r1   r2   test_einsum_matrix_vector_A2_B1"'  r  z2TestShapeInference.test_einsum_matrix_vector_A2_B1c              	   C  r  )	NrN   r$  r   r  r   zii,ii->ir  r   r   r   r1   r1   r2   %test_einsum_diag_multiplication_A2_B2,'  r  z8TestShapeInference.test_einsum_diag_multiplication_A2_B2c              	   C  r  )	NrN   r$  r   r  r   zii,ii->r  r1   r   r   r1   r1   r2   "test_einsum_diag_dot_product_A2_B28'  r  z5TestShapeInference.test_einsum_diag_dot_product_A2_B2c              	   C  sb   d\}}|  dtj||ffdtj|ffgtdddgdgddgg }| |tdtj|fg d S )Nr  r  targetNegativeLogLikelihoodLosslossnone	reductionrA  r\   r   r  r}   r1   r1   r2   *test_negative_log_likelihood_shape_is_NCddB'  s   z=TestShapeInference.test_negative_log_likelihood_shape_is_NCddc              	   C  sn   d\}}|  dtj||ffdtj|ffdtj|ffgtdg ddgdd	gg }| |tdtj|fg d S )
Nr  r  r  weightr  r  r  r  r  r  r  rA  r  r1   r1   r2   4test_negative_log_likelihood_shape_is_NC_with_weightT'  s$   zGTestShapeInference.test_negative_log_likelihood_shape_is_NC_with_weightc              	   C  s`   d\}}|  dtj||ffdtj|ffgtdddgdgddgg }| |tdtjdg d S )	Nr  r  r  r  r  r9  r  r1   rA  r  r1   r1   r2   7test_negative_log_likelihood_shape_is_NC_reduction_meanj'  s   zJTestShapeInference.test_negative_log_likelihood_shape_is_NC_reduction_meanc              	   C  sl   d\}}|  dtj||ffdtj|ffdtj|ffgtdg ddgdd	gg }| |tdtjd
g d S )Nr  r  r  r  r  r  r  r9  r  r1   rA  r  r1   r1   r2   Ctest_negative_log_likelihood_shape_is_NC_with_weight_reduction_mean|'  s$   zVTestShapeInference.test_negative_log_likelihood_shape_is_NC_with_weight_reduction_meanc              	   C  sr   d\}}}}|  dtj||||ffdtj|||ffgtdddgdgddgg }| |tdtj|||fg d S )Nr   r   r;   r  r  r  r  r  r  r  rA  r\   r   r  d1d2r}   r1   r1   r2   ,test_negative_log_likelihood_shape_is_NCd1d2'  s"   z?TestShapeInference.test_negative_log_likelihood_shape_is_NCd1d2c              	   C  s~   d\}}}}|  dtj||||ffdtj|||ffdtj|ffgtdg ddgdd	gg }| |tdtj|||fg d S )
Nr  r  r  r  r  r  r  r  r  rA  r  r1   r1   r2   8test_negative_log_likelihood_shape_is_NCd1d2_with_weight'  s$   zKTestShapeInference.test_negative_log_likelihood_shape_is_NCd1d2_with_weightc              	   C  sl   d\}}}}|  dtj||||ffdtj|||ffgtdddgdgddgg }| |tdtjdg d S )	Nr  r  r  r  r  sumr  r1   rA  r  r1   r1   r2   :test_negative_log_likelihood_shape_is_NCd1d2_reduction_sum'  s"   zMTestShapeInference.test_negative_log_likelihood_shape_is_NCd1d2_reduction_sumc              	   C  sx   d\}}}}|  dtj||||ffdtj|||ffdtj|ffgtdg ddgdd	gg }| |tdtjd
g d S )Nr  r  r  r  r  r  r  r9  r  r1   rA  r  r1   r1   r2   Gtest_negative_log_likelihood_shape_is_NCd1d2_with_weight_reduction_mean'  s$   zZTestShapeInference.test_negative_log_likelihood_shape_is_NCd1d2_with_weight_reduction_meanc              	   C  s   d\}}}}|  dtj|||ffdtj||d |ffdtj|ffdtjdfgtdg d	dgd
dgg }| tjj| j	| d S )Nr  r  r  r   r  r  r1   r  r  r9  r  )
rc   r   r   r[   r   r   rl   rm   r   rr   r  r1   r1   r2   8test_negative_log_likelihood_input_target_shape_mismatch'  s"   
zKTestShapeInference.test_negative_log_likelihood_input_target_shape_mismatchc              
   C  s   d\}}}}|  dtj||||ffdtj|||ffdtj|d ffdtj|||ffgtdg ddgd	d
gg }| tj| j| d S )Nr  r  r  r  r   r  r  r  r  r  )	rc   r   r   r[   r   r   r   rs  rr   r  r1   r1   r2   8test_negative_log_likelihood_input_weight_shape_mismatch(  s"   zKTestShapeInference.test_negative_log_likelihood_input_weight_shape_mismatchc              	   C  r  )	NrN   r   r   r   SoftmaxCrossEntropyLossr   r  r  r   r   r1   r1   r2   test_softmax_cross_entropy_none(  r  z2TestShapeInference.test_softmax_cross_entropy_nonec              	   C  r  )
NrN   r   r   r   r  r   r9  r  r1   r   r   r1   r1   r2   test_softmax_cross_entropy_mean (  r  z2TestShapeInference.test_softmax_cross_entropy_meanc              	   C  r  )	NrN   )rQ   r   r;   r  r   )rQ   r;   r  r  r   r  r  r   r   r1   r1   r2   &test_softmax_cross_entropy_none_NCD1D2*(  rr  z9TestShapeInference.test_softmax_cross_entropy_none_NCD1D2c              	   C  r  )
NrN   r  r   r  r  r   r9  r  r1   r   r   r1   r1   r2   &test_softmax_cross_entropy_mean_NCD1D27(  rr  z9TestShapeInference.test_softmax_cross_entropy_mean_NCD1D2c              	   C  r  )Nr   r  Celur   ry  )r4  r   r   r1   r1   r2   test_celu_function_output_shapeD(  r   z2TestShapeInference.test_celu_function_output_shapec           
      C  s   t dddgdg}|d u rg }n$d}|D ]}|| }qdd t|D }tdtj||tdtj||g}|d u r;g }ntdtj|tdtj|g}tj|d|g |g d	}	t|	S )
Nrr  rN   r   r   r   c                 S  s   g | ]}d qS )r  r1   r5   r  r1   r1   r2   r=   V(  s    zHTestShapeInference.prepare_input_initializer_tensors.<locals>.<listcomp>rV   )r  outputsrI   rG   )	r   r)   r   r   r   r   r!   r   rk   )
r\   initializer_shapeinput_shaperE   rI   r6  dr  r  r}   r1   r1   r2   !prepare_input_initializer_tensorsN(  s0   

z4TestShapeInference.prepare_input_initializer_tensorsc                 C  s`   d}|  |d }tjj|dd}|jj }|jjj	j
d j|jjj	j
d jf}||ks.J d S )Nr  r8  Tr  r   r   )r  rl   rm   rn   r}   rG   rj   r   r   r   r   r   )r\   r  original_modelrq   z_tenorz_shaper1   r1   r2   3test_infer_with_initializer_without_input_above_ir4m(  s   zFTestShapeInference.test_infer_with_initializer_without_input_above_ir4c                 C  sj   d}d}|  ||}d|_tjj|dd}|jj }|jj	j
jd j|jj	j
jd jf}|dks3J d S )	Nr  rH  r   Tr  r   r   r   r   )r  
ir_versionrl   rm   rn   r}   rG   rj   r   r   r   r   r   )r\   r  r	  r  rq   r  r  r1   r1   r2   3test_infer_with_initializer_without_input_below_ir4~(  s   zFTestShapeInference.test_infer_with_initializer_without_input_below_ir4c                 C  2   d}d}|  ||}| jtjjtjj|dd d S )Nr  r  Tr  r  r   rl   rm   r   rn   r\   r  r	  r  r1   r1   r2   %test_infer_initializer_input_mismatch(  s   
z8TestShapeInference.test_infer_initializer_input_mismatchc                 C  (   d}d}|  ||}tjj|dd d S Nr  rH  Tr  r  rl   rm   rn   r  r1   r1   r2   1test_infer_initializer_input_consistency_all_none(     zDTestShapeInference.test_infer_initializer_input_consistency_all_nonec                 C  r  )Nr  Nr8  Tr  r  r  r1   r1   r2   4test_infer_initializer_input_consistency_single_none(  r  zGTestShapeInference.test_infer_initializer_input_consistency_single_nonec                 C  r  )N)r  r8  r!  r  Tr  r  r  r1   r1   r2   7test_infer_initializer_input_consistency_different_rank(  s   
zJTestShapeInference.test_infer_initializer_input_consistency_different_rankc                 C  s,   d}d}|  ||}tjj| dd d S r  )r  rl   rm   rn   SerializeToStringr  r1   r1   r2   <test_infer_initializer_input_consistency_all_none_serialized(  s   
zOTestShapeInference.test_infer_initializer_input_consistency_all_none_serializedc              	   C  s`   | j dtjdfdtjdfgtdddgdggg tdtjddgd}| |tdtjdg d S )	NrN   r3  r  r1   Trilur   r   r  r5  r   r1   r1   r2   test_trilu_upper(  r  z#TestShapeInference.test_trilu_upperc              	   C  sd   | j dtjdfdtjdfgtdddgdgddgg tdtjdd	gd
}| |tdtjdg d S )NrN   r3  r  r1   r"  r   r   upperr1  r  r5  r   r1   r1   r2   test_trilu_lower(     z#TestShapeInference.test_trilu_lowerc              	   C  sd   | j dtjdfdtjdfgtdddgdgddgg tdtjdd	gd
}| |tdtjdg d S )NrN   )r   r;   r  r1   r"  r   r   r$  r  r  )rc   r   r[   r   r   r   r!   r   r1   r1   r2   test_trilu_upper_zero(  r(  z(TestShapeInference.test_trilu_upper_zeroc              	   C  r  )NrN   )r   r   r;   r"  r   r   r$  )rc   r   r  r   r   r!   r   r1   r1   r2   test_trilu_lower_one(  r   z'TestShapeInference.test_trilu_lower_onec              	   C     |  dtjdfdtjdfdtjdfdtjdfdtjdfgtdg d	g d
ddgg }| |tdtjdtdtjdtdtjdg d S NrN   rf  r  rk  r   
input_mean	input_varr;  rN   r  r   r-  r.  r?  output_mean
output_varr   training_moder?  r1  r2  r   r   r1   r1   r2   test_batch_norm_train(  .   




z(TestShapeInference.test_batch_norm_trainc              	   C  r+  )NrN   )r   r  r;   r  r8  r  r  r   r-  r.  r;  r/  r0  r   r3  r?  r1  r2  r   r   r1   r1   r2   test_batch_norm_train_dim_param)  r6  z2TestShapeInference.test_batch_norm_train_dim_paramc              	   C  s   |  dtjdfdtjdfdtjdfdtjdfdtjdfgtdg d	g d
ddgg }| |tdtjdtdtjdtdtjdg d S r,  )rc   r   r   r   r   r   r!   r   r1   r1   r2   $test_batch_norm_train_with_diff_type3)  r6  z7TestShapeInference.test_batch_norm_train_with_diff_typec              	   C  sp   |  dtjdfdtjdfdtjdfdtjdfdtjdfgtdg d	d
gddgg }| |td
tjdg d S )NrN   rf  r  rk  r   r-  r.  r;  r/  r?  r   r3  r   r   r1   r1   r2   test_batch_norm_testO)  s&   




z'TestShapeInference.test_batch_norm_testc              	   C  sp   |  dtjdfdtjdfdtjdfdtjdfdtjdfgtd	g d
dgddgg }| |tdtjdg d S )NrN   )r   r   NNNr  rk  r   r-  rT   r.  r;  r/  r?  r   r3  r   r   r1   r1   r2   test_batch_norm_test_no_dimf)  s.   




z.TestShapeInference.test_batch_norm_test_no_dimc              	   C  s   |  dtjd fdtjd fdtjd fdtjdfdtjdfgtdg dg d	d
dgg }| |tdtjd tdtjdtdtjdg d S )NrN   r  r   r-  r7  r.  r;  r/  )r?  running_meanrunning_varr   r3  r?  r<  r=  r   r   r1   r1   r2   test_batch_norm_train_no_shape)  r6  z1TestShapeInference.test_batch_norm_train_no_shapec                 C  B   |  dtjdfgtddgdggg }| |tdtjdg d S )NrN   rT   NonZeror?  )r   Nr(  r   r1   r1   r2   test_nonzero)  r  zTestShapeInference.test_nonzeroc                 C  sB   |  dtjd fgtddgdggg }| |tdtjdg d S )NrN   r@  r?  rH  r(  r   r1   r1   r2   test_nonzero_no_shape)     z(TestShapeInference.test_nonzero_no_shapec                 C  sN   |  dtjdfgtddgdggtdtjdg}| |tdtjdg d S )NrN   r   r@  r   )NNZ)r   rD  )rc   r   r   r   r!   r[   r   r   r1   r1   r2   test_nonzero_existing_dim_param)  s   z2TestShapeInference.test_nonzero_existing_dim_paramc                 C  r?  )NrN   r1   r@  r?  )r   Nr(  r   r1   r1   r2   test_nonzero_scalar)  rC  z&TestShapeInference.test_nonzero_scalarc              	   C  s\   t jtjg dd}t |}t jd|d}| g tdg dg|dgg }| ||g d S )Nrv  r	  r  r-   
type_protore  r   	r   rh  r   r   ri  rj  rc   r   r   r\   rk  rl  optional_val_infor}   r1   r1   r2   $test_optional_construct_empty_tensor)  s   

z7TestShapeInference.test_optional_construct_empty_tensorc              	   C  sf   t jtjg dd}t |}t |}t jd|d}| g tdg dg|dgg }| 	||g d S )Nrv  r	  r`  rG  re  rI  )
r   rh  r   r  rn  ri  rj  rc   r   r   )r\   rk  ro  rl  rL  r}   r1   r1   r2   &test_optional_construct_empty_sequence)  s   


z9TestShapeInference.test_optional_construct_empty_sequencec                 C  sd   t jtjg dd}t |}t jd|d}| dtjdfgtddgdggg }| ||g d S )Nr   r	  r  rG  rY  re  rJ  rK  r1   r1   r2   test_optional_construct_tensor)  s   

z1TestShapeInference.test_optional_construct_tensorc                 C  s   t jtjg dd}t |}t jd|d}t |}t jd|d}| dtjdfgtddgdgtddgdggg }| 	|||g d S )	N)rQ   r   r   r	  input_sequencerG  r`  rY  r]  re  )
r   rh  r   r[   rn  rj  ri  rc   r   r   r\   rk  ro  sequence_val_inforl  rL  r}   r1   r1   r2    test_optional_construct_sequence)  s&   


z3TestShapeInference.test_optional_construct_sequencec                 C  s~   t jtjg dd}t |}t jd|d}| dtjdfgtddgdgtddgdggg }| ||t	dtj
d	g d S )
Nr   r	  r  rG  rY  re  OptionalHasElementr  r1   )r   rh  r   r   ri  rj  rc   r   r   r!   r+  rK  r1   r1   r2    test_optional_tensor_has_element*  s$   

z3TestShapeInference.test_optional_tensor_has_elementc              	   C  s   t jtjg dd}t |}t jd|d}t |}t jd|d}| dtjdfgtddgdgtddgdgtd	dgd
ggg }| 	|||t
d
tjdg d S )N)r   r   r   r	  r  rG  optionalrY  r]  re  rT  r  r1   )r   rh  r   r   rn  rj  ri  rc   r   r   r!   r+  rQ  r1   r1   r2   "test_optional_sequence_has_element*  s4   


	z5TestShapeInference.test_optional_sequence_has_elementc                 C  sZ   t jtjg dd}t jd|d}| dtjdfgtddgdggg }| ||g d S )NrQ   r   r   r	  r  rG  r  OptionalGetElement)r   rh  r   r  rj  rc   r   r   )r\   rk  output_tensor_val_infor}   r1   r1   r2   test_tensor_get_element7*  s   
z*TestShapeInference.test_tensor_get_elementStringSplitc                 C  j   t dtjd}t dtjd}| dtjdfgtddgddgg||g}| j|||gtt	|gd d S )N
substrings)rQ   Nlengthr   rN   r\  r   
r!   r   r   r[   rc   r   r   r   r   r   r\   r   r0   r^  r_  r}   r1   r1   r2   test_string_split_basicG*  "   

z*TestShapeInference.test_string_split_basicc                 C  r]  )Nr^  )r  Nr_  )r  rN   r\  r   r`  ra  r1   r1   r2   test_string_split_symbolic\*  rc  z-TestShapeInference.test_string_split_symbolicc              	   C  n   t dtjd}t dtjd}| dtjdfgtddgddgddg||g}| j|||gtt	|gd	 d S )
Nr^  )rQ   r   r   Nr_  r   rN   r\  rQ   maxsplitr   r`  ra  r1   r1   r2   test_string_split_nestedq*  s   

z+TestShapeInference.test_string_split_nestedc              	   C  re  )
Nr^  rT   r_  r1   rN   r\  rQ   rf  r   r`  ra  r1   r1   r2   (test_string_split_zero_dimensional_input*  s   

z;TestShapeInference.test_string_split_zero_dimensional_inputc              	   C  re  )
Nr^  )rK  r   r   Nr_  )rK  r   r   rN   r\  rQ   rf  r   r`  ra  r1   r1   r2   test_string_split_empty_input*  s   

z0TestShapeInference.test_string_split_empty_inputc                 C  s   t jtjg dd}t jd|d}t |}t jd|d}| dtjdfgtddgdgtddgdggg }| |||g d S )	NrX  r	  r  rG  rV  rY  re  rY  )	r   rh  r   r  rj  ri  rc   r   r   )r\   rk  tensor_val_intorl  rL  r}   r1   r1   r2    test_optional_tensor_get_element*  s$   

z3TestShapeInference.test_optional_tensor_get_elementc              	   C  s   t jtjg dd}t |}t jd|d}t |}t jd|d}t jd|d}| dtjdfgtddgdgtd	dgdgtd
dgdggg }| 	||||g d S )N)rQ   r   r   r	  r  rG  rV  r  rY  r]  re  rY  )
r   rh  r   r  rn  rj  ri  rc   r   r   )r\   rk  ro  sequence_val_intorl  rL  output_val_intor}   r1   r1   r2   "test_optional_sequence_get_element*  s2   


	
z5TestShapeInference.test_optional_sequence_get_elementc                 C  sX   |  dtjdfdtjdfdtjdfgtdg ddggg }| |tdtjdg d S )Nr  r&  rN   r   Where)r  rN   r   r?  )rc   r   r+  r(  r   r   r!   r   r1   r1   r2   test_where_bfloat*  rC  z$TestShapeInference.test_where_bfloatc                 C  s   t jt jdg t jdtjd dgtddgdggtjt	j
ddgt	jddd	gd
d}| jtjjtjj|dd tj|}| |jjd jjd d S )Ngraph_with_unsupported_typer   r   rK  rN   r   r   r|  rL   r-   r  r  rE   rI   r}   Tr  r   r   )r   rk   r   r!   r   r   r   r   
from_arrayr   r  int32r   rl   rm   r   rn   assertFalser}   r  r   r   r   )r\   r  rq   r1   r1   r2   ,test_parse_data_with_unsupported_tensor_type*  s*   z?TestShapeInference.test_parse_data_with_unsupported_tensor_typec                 C  s  t jt jdg t jdtjd dgtddgdggtjt	j
ddgt	jddd	gd
d}tj|jjd _| jtjjtjj|dd tj|}| |jjd jjd | jdtjdfdtjdfgtdddgdgddgg tdtjddgd}| |tdtjdg d S )Ngraph_with_undefined_typer   rs  rK  rN   r   r   r|  rL   rt  ru  r   Tr  r   rY  r   rU   r   rZ  rW  r  )r   rk   r   r!   r   r   r   r   rv  r   r  int64rY   r}   rI   r  r   rl   rm   r   rn   rx  r  r   r   r   rc   r   r[   r   r   )r\   r  rq   r}   r1   r1   r2   *test_parse_data_with_undefined_tensor_type+  s>   z=TestShapeInference.test_parse_data_with_undefined_tensor_typec                 C  s   d\}}}}| j dtj|ddffdtjdfgtdddgdgd	d
gg tdtjd||||fgd}| |tdtj|||dfg d S )Nr  thetarQ   r   r6  rk  
AffineGridgridr   )align_cornersr  r5  )r\   r   r  r  r  r}   r1   r1   r2   test_affinegrid_2d,+  s$   
z%TestShapeInference.test_affinegrid_2dc                 C  s   d\}}}}}| j dtj|ddffdtjdfgtdddgdggg tdtjd|||||fgd	}| |tdtj||||dfg d S )
N)rQ   r   r   r;   r  r}  r   r   r6  r  r~  r  r  r5  )r\   r   r  Dr  r  r}   r1   r1   r2   test_affinegrid_3dB+  s"   
z%TestShapeInference.test_affinegrid_3dc                 C  sV   |  dtjdfdtjdfgtdddgdgddd	d
gg }| |tdtjdg d S )NrN   r}  r  )r   r   r   rQ   
GridSampler   nearestborderr   r  padding_moder  rA  r   r1   r1   r2   test_gridsample_2dW+  $   


z%TestShapeInference.test_gridsample_2dc                 C  sV   |  dtjdfdtjdfgtdddgdgddd	d
gg }| |tdtjdg d S )NrN   r  r  )r   r   rQ   r   r   r  r   r  r  r   r  )r   r   r   rQ   r   rA  r   r1   r1   r2   test_gridsample_3dm+  r  z%TestShapeInference.test_gridsample_3dc                 C  r  )NrN   r  r  )r   H_outW_outrQ   r  r   )r   r  r  r  r   r   r1   r1   r2   test_gridsample_2d_defaults+     

z.TestShapeInference.test_gridsample_2d_defaultsc                 C  r  )NrN   )r   r  r  r  r  r  )r   D_outr  r  r   r  r   )r   r  r  r  r  r   r   r1   r1   r2   test_gridsample_3d_defaults+  r  z.TestShapeInference.test_gridsample_3d_defaultsc              
   C  T   |  dtjdfdtjdfgtdddgdgddd	gg }| |tdtjdg d S )
NrN   )r   r  NNr  )r   NNrQ   r  r   r  r  r  r  r   r   r1   r1   r2   test_gridsample_2d_no_dim+  s$   

	z,TestShapeInference.test_gridsample_2d_no_dimc              
   C  r  )
NrN   )r   r  NNNr  )r   NNNr   r  r   r  r  r  r   r   r1   r1   r2   test_gridsample_3d_no_dim+  s*   

	z,TestShapeInference.test_gridsample_3d_no_dimc              
   C  s   t dtjdg}t dtjdg}ttddgdggd||}| dtjdfdtjdfdtjdfgtd	g d
dgtddgdg|dgg }| |tdtjdtdtjdg d S )Nr  )   r  r   r  r-  
body_graphrY  rZ  r[  r]  r^  r_  SequenceMapout_sequencerE  	r!   r   r   r   r   r   rc   r   r    r\   r^   r  r  r}   r1   r1   r2   %test_sequence_map_identity_known_dims+  D   


z8TestShapeInference.test_sequence_map_identity_known_dimsc              
   C  s   t dtjdg}t dtjdg}ttddgdggd||}| dtjdfdtjd	fd
tjdfgtdg ddgtddgdg|dgg }| |tdtjdtdtjdg d S )Nr  r  r  r   r  r-  r  rY  )rU  r  r   rZ  )r  rU  r   r[  )r;   r   r   r]  r^  r_  r  r  rE  NNr   r  r  r1   r1   r2   'test_sequence_map_identity_unknown_dims ,  r  z:TestShapeInference.test_sequence_map_identity_unknown_dimsc                 C  s4  t jtdg ddgtdg ddggdtj dtjjdgtj dtjjd	tj dtjjd
gtdtjddtdtjddtdtjddtdtjddtdtjddgd}| 	dtjdfdtjdfdtjdfgtdg ddgtddgd d!g|d"gg }| 
|tdtjd#td tjd	td!tjd
g d S )$Nr?  rN   starts1ends1r  r  y1rN   starts2ends2r  r  y2r  rN   r  )r1  r  r   )r   (   r   r  r   rV  r  r  r  r1  r  r  r  r   r  rE   r-   r  r  rI   rY  r  i6  r   rZ  n      r   r[  Z   r  r   r]  r^  r_  r  out_sequence1out_sequence2rE  r  r   r   r   rl   r!   r   r   r   r[   rc   r   r    r\   r  r}   r1   r1   r2   'test_sequence_map_slice_outs_known_dims),  j   


	


z:TestShapeInference.test_sequence_map_slice_outs_known_dimsc                 C  s4  t jtdg ddgtdg ddggdtj dtjjdgtj dtjjd	tj dtjjd
gtdtjddtdtjddtdtjddtdtjddtdtjddgd}| 	dtjdfdtjdfdtjdfgtdg ddgtddgd d!g|d"gg }| 
|tdtjd#td tjd#td!tjd#g d S )$Nr?  r  r  r  r  r  rN   r  )r  W1r   )r  W2r   r  r   rV  r  r  r  r  r  r  r  r  rY  r  rZ  r  r[  r  r]  r^  r_  r  r  r  rE  r  r  r  r1   r1   r2   )test_sequence_map_slice_outs_unknown_dimsh,  r  z<TestShapeInference.test_sequence_map_slice_outs_unknown_dimsc              
   C  s   t jtddgdggdtj dtjjdgtj dtjjdgd}| dtjd	fd
tjdfdtjdfgtdg ddgtddgdg|dgg }| 	|t
dtjdt
dtjdg d S )Nr  rN   r   r  )r  r  r  r   )rE   r-   r  r  rY  r  rZ  r  r[  r  r]  r^  r_  r  shapesrE  r  )r   r   r   rl   r!   r   r   r[   rc   r   r    r  r1   r1   r2   'test_sequence_map_different_tensor_type,  s@   




z:TestShapeInference.test_sequence_map_different_tensor_typec                 C     |  g tdg dgtdtjdddtddgdggg }| |tdtjdtdtjdg |  g tdg dgtdtjdddtddgdgdd	gg }| |tdtjdtdtjdg d S )
Nr]  r   r1   r&  r^  HammingWindowr   r   periodicrc   r   r   r   r[   r   r!   r   r   r1   r1   r2   test_hammingwindow,  H   		z%TestShapeInference.test_hammingwindowc                 C  r  )
Nr]  r   r1   r&  r^  
HannWindowr   r   r  r  r   r1   r1   r2   test_hannwindow,  r  z"TestShapeInference.test_hannwindowc                 C  r  )
Nr]  r   r1   r&  r^  BlackmanWindowr   r   r  r  r   r1   r1   r2   test_blackmanwindow%-  r  z&TestShapeInference.test_blackmanwindowc           	   
   C  4   g | ]\\}}\}}}}}}||||||||fqS r1   r1   	r5   r-   r0   test_aspectr	  r:  onesidedinverseexpected_shaper1   r1   r2   r=   Q-  $    
zTestShapeInference.<listcomp>DFT))reals_default_axisrQ   r;   r   NNNrG  )reals_axis_0r   r;   r1  r   r   r   r   r   r;   r1  rQ   )reals_axis_1r  r   r   r   r  )reals_axis_2r  rQ   r   r   r  )reals_axis_negr  r[  r   r   r  )reals_axis_0_onesidedr  r   r   r   rQ   r;   r1  rQ   )reals_axis_1_onesidedr  r   r   r   r   r   r1  rQ   )reals_axis_2_onesidedr  rQ   r   r   r   r;   r  rQ   )reals_axis_neg_onesidedr  r[  r   r   r  )complex_default_axisrG  NNNrG  )real_inverser  r   Nr   rG  )complex_inverserG  r   Nr   rG  )irfft_axis_0r  r   r   r   )rQ   r;   r1  r   )irfft_axis_1r  r   r   r   )r   r   r1  r   )irfft_axis_2r  rQ   r   r   r  )irfft_axis_negr  r[  r   r   r  _test_aspectr	  
tuple[int]r:  
int | Noner  r  r  c	                 C  sX  i }	|d ur
||	d< |d ur||	d< |dk r/|d ur||	d< t dddgdgfi |	g}
g }n@|dks5J |d ur_t d	g dgtdtjd
|fdt dg ddgfi |	g}
tdtjd
g}nt dg ddgfi |	g}
g }| g t d	g dgtdtj|tj|tj	d
 dg|
g }| j|tdtj|g|tdtj|tt|gd d S )Nr  r  r  r:  r  r  r  r  r]  r1   r^  r  r  r:  r  r  r  r|  r   r   r   r   r[   r!   rc   r   r   onesfloat32flattenr   r   r   r   )r\   r   r0   r  r	  r:  r  r  r  
attributesrE   value_infosr}   r1   r1   r2   test_dftP-  sh   6	
zTestShapeInference.test_dftc           	   
   C  r  r1   r1   r  r1   r1   r2   r=   -  r  ))r  r  NNNrQ   r  rQ   )r  r  r   r   r   )r  r;   r1  rQ   )r  r  r   r   r   )r   r  r1  rQ   )r  r  rQ   r   r   r   r;   r  rQ   )r  r  r[  r   r   r  )r  r  r   r   r   )   r;   r1  rQ   )r  r  r   r   r   )r   r  r1  rQ   )r  r  rQ   r   r   r   r;   r  rQ   )r  r  r[  r   r   r  )r  rG  NNNr  )r  r  r   Nr   r  )r  rG  r   Nr   r  )r  r  r   r   r   )r  r;   r1  r   )r  r  r   r   r   )r   r  r1  r   )r  r  rQ   r   r   r   r;   r  r   )r  r  r[  r   r   r  c	                 C  s  i }	|d ur
||	d< |d ur||	d< d}
|dk rF|d ur ||	d< t dg dgtdtjd|
fd	t d
ddgdgfi |	g}tdtjdg}nj|dksLJ |d urt dg dgtdtjd|fd	t dg dgtdtjd|
fd	t d
g ddgfi |	g}tdtjdtdtjdg}n%t dg dgtdtjd|
fd	t d
g ddgfi |	g}tdtjdg}| g t dg dgtdtj|tj|tj	d
 d	g|g }| j|tdtj|g|tdtj|tt|gd d S )Nr  r  r  r  r:  r]  
dft_lengthr1   r^  r  r  r  r  r  r:  )r  r  r  r|  r   r  )r\   r   r0   r  r	  r:  r  r  r  r  r  rE   r  r}   r1   r1   r2   test_dft_dft_length-  s   6
z&TestShapeInference.test_dft_dft_length))r  r   )last_negativer'   )out_of_ranger   )out_of_range_negativer  c                 C  s   |  g tdg dgtdtjdtjdtjd dtdddgdgd	|d
gg }| 	t
jj" | j|tdtjdtdtjdgttdgd W d    d S 1 sTw   Y  d S )Nr]  r  rQ   r;   r;   rQ   r|  r^  r  r  r  r   r  r:  rQ   r   r;   rQ   r  r   rc   r   r   r   r   r   r  r  r  r   rl   rm   r   r   r!   r   r   r   r\   r   r:  r}   r1   r1   r2   test_dft_invalid_axis_opset17].  s4   	"z0TestShapeInference.test_dft_invalid_axis_opset17c                 C  s   |  g tdg dgtdtjdtjdtjd dtdg dgtdtj	d|fdtdg d	d
ggg }| 
tjj( | j|tdtjdtdtj	dtd
tjdgttdgd W d    d S 1 sfw   Y  d S )Nr]  r  r  r|  r^  r:  r1   r  r  r  r   r  r   rc   r   r   r   r   r   r  r  r  r[   r   rl   rm   r   r   r!   r   r   r   r  r1   r1   r2   test_dft_invalid_axis_opset20.  sB   	"z0TestShapeInference.test_dft_invalid_axis_opset20c                 C  s   |  g tdg dgtdtjdtjdtjd dtdddgdgd	d	d
gg }| 	t
jj" | j|tdtjdtdtjdgttdgd W d   dS 1 sTw   Y  dS )<Test that RFFT (onesided=1, inverse=0) rejects complex inputr]  r  rG  r|  r^  r  r  r  r   r  rQ   r   rQ   r  r   Nr  r   r1   r1   r2   +test_dft_rfft_invalid_complex_input_opset17.  s4   "z>TestShapeInference.test_dft_rfft_invalid_complex_input_opset17c                 C  s   |  g tdg dgtdtjdtjdtjd dtdg dgtdtj	dddtd	g d
dgddgg }| 
tjj( | j|tdtjdtdtj	dtdtjdgttdgd W d   dS 1 sgw   Y  dS )r  r]  r  rG  r|  r^  r:  r1   r  r  r  r  r   r  r  r  r   Nr  r   r1   r1   r2   +test_dft_rfft_invalid_complex_input_opset20.  sB   "z>TestShapeInference.test_dft_rfft_invalid_complex_input_opset20c                 C  s   |  g tdg dgtdtjdtjdtjd dtdddgdgd	d	d	d
gg }| 	t
jj" | j|tdtjdtdtjdgttdgd W d   dS 1 sUw   Y  dS ):Test that IRFFT (onesided=1, inverse=1) rejects real inputr]  r  r  r|  r^  r  r  r  r   )r  r  r:  rQ   r  r   r  r   Nr  r   r1   r1   r2   )test_dft_irfft_invalid_real_input_opset17.  s8   "z<TestShapeInference.test_dft_irfft_invalid_real_input_opset17c                 C  s   |  g tdg dgtdtjdtjdtjd dtdg dgtdtj	dddtd	g d
dgdddgg }| 
tjj( | j|tdtjdtdtj	dtdtjdgttdgd W d   dS 1 shw   Y  dS )r  r]  r  r  r|  r^  r:  r1   r  r  r  r  r   )r  r  r  r  r   Nr  r   r1   r1   r2   )test_dft_irfft_invalid_real_input_opset20/  sF   "z<TestShapeInference.test_dft_irfft_invalid_real_input_opset20)realrQ   r;   r;   r   )complexr  c                 C  s   |  dtjdfgtdg dgtdtj|tj|tjd	 dtdg dd	ggg }| j
|tdtj|td	tjd
gttdgd d S )Nr:  r1   r]  r  r|  r^  r  r  r  r  r  r   rc   r   r[   r   r   r   r   r  r  r  r   r!   r   r   r   r\   r   r   r}   r1   r1   r2   test_dft_dynamic_axis_opset208/  s0   
z0TestShapeInference.test_dft_dynamic_axis_opset20c                 C  s   |  dtjdfgtdg dgtdtj|tj|tjd	 dtdg dgtdtjdtj
dgtjddtd	g d
dgddgg }| j|tdtj|tdtjdtdtjdgttdgd d S )Nr:  r1   r]  r  r|  r^  r  r  r  r  r  r   r	  NNNrQ   r  r   )rc   r   r[   r   r   r   r   r  r  r  r  r{  r   r!   r   r   r   r  r1   r1   r2   1test_dft_dynamic_axis_onesided_dft_length_opset20Z/  sP   
zDTestShapeInference.test_dft_dynamic_axis_onesided_dft_length_opset20c                 C  s   |  dtjdfgtdg dgtdtj|tj|tjd	 dtdg dd	gd
dgg }| j
|tdtj|td	tjdgttdgd d S )Nr:  r1   r]  r  r|  r^  r  r  r  r   r	  r  r  r   r  r  r1   r1   r2   &test_dft_dynamic_axis_onesided_opset20/  s4   
z9TestShapeInference.test_dft_dynamic_axis_onesided_opset20c                 C  s   |  g tdg dgtdtjdtjdtjd dtdddgdgd	d
gg }| j	|t
dtjdt
dtjdgttdgd d S )Nr]  r  r  r|  r^  r  r  r  r   r	  r   r  r   rc   r   r   r   r   r   r  r  r  r   r!   r   r   r   r   r1   r1   r2   &test_dft_onesided_default_axis_opset17/  0   
z9TestShapeInference.test_dft_onesided_default_axis_opset17c                 C  s   |  g tdg dgtdtjdtjdtjd dtdg ddgd	d
gg }| j	|t
dtjdt
dtjdgttdgd d S )Nr]  r  r  r|  r^  r  r  r  r   r	  )rQ   r;   r   rQ   r  r   r  r   r1   r1   r2   &test_dft_onesided_default_axis_opset20/  r  z9TestShapeInference.test_dft_onesided_default_axis_opset20c                 C  s6  |  g tdg dgtdtjdddtdg dgtdtjdddtdg d	gtd	tjd
ddtdg ddggg }| |tdtjdtdtjdtd	tjd
tdtjdg |  g tdg dgtdtjdddtdg dgtdtjdddtdg d	gtd	tjd
ddtdg dgtdtjdd
dtdg ddggg }| |tdtjdtdtjdtd	tjd
tdtjdtdtjdg |  g tdg dgtdtjdddtdg dgtdtjdddtdg dgtdtjdd
dtdg ddggg }| |tdtjdtdtjdtdtjdtdtjdg d S )Nr]  signal)rQ   r1  r   )r   r   r   r   r   r   r   r   r   r   rQ   rQ   rQ   rQ   rQ   r   r   r   r   r   r^  
frame_stepr1   r   windowr  r4  STFT)r  r  r  r  r   frame_length)r  r  r  r   )rc   r   r   r   r   r[   r   r!   r   r1   r1   r2   test_stft_reals/  s   
!

"'!z"TestShapeInference.test_stft_realsc                 C  s  |  g tdg dgtdtjdddtdg dgtdtjdddtdg dgtdtjdddtdg d	gtd	tjdd
dtdg dgtdtjdddtdg ddggg }| |tdtjdtdtjdtdtjdtd	tjdtdtjdtdtjdg d S )Nr]  num_mel_binsr1   r&  r^  r  r?  sample_ratelower_edge_hertzg      $@upper_edge_hertzg      Y@MelWeightMatrixr"  r  r#  r$  r&  r  r  r1  )rc   r   r   r   r[   r   r   r!   r   r1   r1   r2   test_melweightmatrixu0  sl   

/3z'TestShapeInference.test_melweightmatrixc                 C  s  |  g tdg dgtdtjdddtdg dgtdtjdddtdg dgtdtjdddtdg d	gtd	tjdd
dtdg dgtdtjdddtdg ddgtjdgg }| |tdtjdtdtjdtdtjdtd	tjdtdtjdtdtjdg d S )Nr]  r"  r1   r&  r^  r  r?  r#  r$  r%  r&  r'  r(  r)  r  )output_datatyper*  )	rc   r   r   r   r[   r   r  r   r!   r   r1   r1   r2   )test_melweightmatrix_with_output_datatype0  sn   

04z<TestShapeInference.test_melweightmatrix_with_output_datatypec              	   C  v   | j dtjdfdtjdfgtdddgdgddgd	gg tdtjdd
gd}| j|tdtjdgt	t
dgd d S )N
input_data)r  r1  r   r   r   CenterCropPadr   r   r   r  r1  r  r  r1  r  r   r  r   r  r   r1   r1   r2   test_center_crop_pad_hwc_crop0     

	
z0TestShapeInference.test_center_crop_pad_hwc_cropc              	   C  r.  )Nr/  )r   r  r1  r   r   r0  r   r   rQ   r  r1  r  )r   r1  r  r  r   r  r   r1   r1   r2   test_center_crop_pad_chw_crop1  r4  z0TestShapeInference.test_center_crop_pad_chw_cropc              	   C  r.  )Nr/  )r1  r1  r   r   r   r0  r   r   r   r  r  r  r  )r  r  r   r  r   r  r   r1   r1   r2    test_center_crop_pad_hwc_croppad1  r4  z3TestShapeInference.test_center_crop_pad_hwc_croppadc              	   C  r.  )Nr/  )r   r1  r1  r   r   r0  r   r   rQ   r  r6  r  )r   r  r  r  r   r  r   r1   r1   r2    test_center_crop_pad_chw_croppad&1  r4  z3TestShapeInference.test_center_crop_pad_chw_croppadc                 C  s\   |  dtjdfdtjdfgtdddgdggg }| j|tdtjd gtt	dgd d S )	Nr/  r  r   r   r0  r   r  r   r  r   r1   r1   r2   (test_center_crop_pad_without_input_shape61  s   


z;TestShapeInference.test_center_crop_pad_without_input_shapec              	   C  r.  )Nr/  )r  r  r   r   r   r0  r   r   r   r  r1  r  r2  r  r   r  r   r1   r1   r2   ;test_center_crop_pad_with_input_shape_containing_dim_paramsE1  s   

	
zNTestShapeInference.test_center_crop_pad_with_input_shape_containing_dim_paramsc                 C  s   t ddgdgtg dg dd}| dtjdfg|gg }| j|tdtjdgttdtt	d	gd
 | dtjdfg|gg }| j|tdtjdgttdtt	d	gd
 d S )NCategoryMapperrN   r   rv  123r.   cats_int64scats_stringsr   r   r  r   )r   r;   r   )
r   r   rc   r   r[   r   r!   r   r   r   )r\   cat	graph_int	graph_strr1   r1   r2   test_category_mapperW1  s@   
z'TestShapeInference.test_category_mapperrv  r=  r>  Nr<  rH  c                 C  s^   t ddgdgt||d}| dtjdfg|gg }| jtjj| j	|t
tdt
tdgd d S )	Nr;  rN   r   r@  r   r   r  r   )r   r   rc   r   r[   r   rl   rm   r   rr   r   r   )r\   rA  rB  rC  r}   r1   r1   r2   0test_category_mapper_fails_if_invalid_attributes|1  s*   
zCTestShapeInference.test_category_mapper_fails_if_invalid_attributesc                 C  s`   t ddgdgtdd}| dtjdfg|gg }| j|tdtjdgttdtt	d	gd
 d S )NTreeEnsembleRegressorrN   r   r;   )r.   	n_targetsr   r   r   r;   r   r  r   )
r   r   rc   r   r  r   r!   r   r   r   r\   treer}   r1   r1   r2   test_tree_ensemble_regressor1  s&   
z/TestShapeInference.test_tree_ensemble_regressorc                 C  s   d}d}t ddgdgtddg| td||ftt|tdtj|fdg| dg| dg| dg| dg| td	|d
dddtjdddgdg| td||fdg| dgd}| 	d|dfg|gg }| j
|td|dgttdttdgd d S )Nr;   r!  TreeEnsemblerN   r   r   nodes_splitsnodes_modesmembership_values)r8  r  r  r  r  r3  rd  leaf_weightsr   )r.   rI  nodes_featureidsrP  rQ  nodes_truenodeidsnodes_falsenodeidsnodes_trueleafsnodes_falseleafsrR  leaf_targetidsrS  
tree_roots
Batch SizeFeatures)r\  r;   r  r   )r   r   r   r~   r)   r   r   r   nanrc   r   r!   r   r   )r\   r}  interior_nodesleavesrM  r}   r1   r1   r2   test_tree_ensemble1  s^   
"

z%TestShapeInference.test_tree_ensembler   r  rS  r!  r   r!  rP  r  r;   )r  r  c                 C  s   d}d}t ddgdgtddg| |tdtj|fdg| |dg| dg| dg| dg| |dgd}| dtjd	fg|gg }| jtj	j
| j|ttdttd
gd d S )Nr;   r!  rO  rN   r   r   rQ  )r.   rI  rT  rP  rQ  rU  rV  rW  rX  rY  rS  rZ  r[  r  r   )r   r   r   r   r   rc   r  r   rl   rm   r   rr   r   r   )r\   rU  rS  rP  r_  r`  rM  r}   r1   r1   r2   .test_tree_ensemble_fails_if_invalid_attributes1  sJ   
zATestShapeInference.test_tree_ensemble_fails_if_invalid_attributesc                 C  sr   t ddgddgg dtd}| dtjdfg|gg }| j|tdtjdtdtjd	gt	td
t	t
dgd d S )NTreeEnsembleClassifierrN   r   r   )r   r   rQ   r   r   )classlabels_int64sr.   rJ  )r   rK  r   r  r   )r   r   rc   r   r  r   r!   r[   r   r   r   rL  r1   r1   r2   test_tree_ensemble_classifier32  s*   
z0TestShapeInference.test_tree_ensemble_classifierc              	   C  s~   t dddgdgtd}dD ]/\}}| dtjdfdtj|fg|gg }| j|tdtjdd	|fgttdttd
gd qd S )NArrayFeatureExtractorrN   r   r   r<   ))r   rQ   )r1   r  )r   r   r3  r   r   r  r   	r   r   rc   r   r[   r   r!   r   r   )r\   r  
axes_shaper  r}   r1   r1   r2   test_array_feature_extractorM2  s,   

z/TestShapeInference.test_array_feature_extractorc                 C  s^   t ddgdgtd}| dtjdfg|gg }| j|tdtjdgttdttdgd d S )	N	BinarizerrN   r   r<   r3  r   r  r   rg  )r\   r  r}   r1   r1   r2   test_binarizerk2  s&   

z!TestShapeInference.test_binarizerc              
   C  s`   |  dtjdfgtddgdgg dddgg }| j|tdtjdgttd	tt	d
gd d S )Nr  rQ   r   r   OneHotEncoderr  r  
ai.onnx.ml)rA  r.   rQ   r   r   r   r   r  r   )
rc   r   r[   r   r   r!   r   r   r   r   r   r1   r1   r2   test_one_hot_encoder2  s&   	
z'TestShapeInference.test_one_hot_encoderc                 C  sZ   |  dtjdfgtddgdg||ddgg }| jtjj| j|t	t
dt	tdgd	 d S )
Nr  rl  rm  r  rn  )rA  rB  r.   r   r  r   )rc   r   r[   r   r   rl   rm   r   rr   r   r   r   )r\   rA  rB  r}   r1   r1   r2   0test_one_hot_encoder_fails_if_invalid_attributes2  s*   


zCTestShapeInference.test_one_hot_encoder_fails_if_invalid_attributesc              	   C  st   dg dit jjfdg dit jjff}|D ]!\}}| j||d | || W d    n1 s2w   Y  qd S )Nrd  rv  classlabels_strings)r   r   c)attrsr  )rl   r   r[   r   subTestzip_map_test_case)r\   paramsrt  r  r1   r1   r2   test_zip_map2  s   zTestShapeInference.test_zip_mapc                 C  s   |  dtjdfgtddgdgfi |ddigg }tj|tjtjd}| j|tj	dtj
|gttdttd	gd
 d S )Nr  )r   r   ZipMapr  r.   rn  r1   r   r  r   )rc   r   r   r   rl   r   make_map_type_protorh  r   rj  rn  r   r   r   )r\   rt  r  r}   typr1   r1   r2   rv  2  s6   	
z$TestShapeInference.zip_map_test_casec                 C  r  )Nr  ro  r   rT   Compressr  rc   r   r[   r+  r   r   r!   r   r1   r1   r2   test_compress_without_axis2  r  z-TestShapeInference.test_compress_without_axisc              	   C  r-  )
Nr  ro  r   rT   r|  r  r'   r9  )rQ   r   r   Nr}  r   r1   r1   r2   test_compress_with_axis2  r  z*TestShapeInference.test_compress_with_axisc                 C  s   d}t j|}tjdddg g d}t j| | t jj t j	|d W d    n1 s1w   Y  t j
|j|j|j d S )Nz
            <
                ir_version: 7,
                opset_import: ["" : 1]
            >
            agraph (X, Y) => (Z)
            {
                Z = CustomOp(X, Y)
            }
           CustomOpr  r   )r  r  T)rl   r  r  r   r   register_schemar   rm   r   rn   deregister_schemar-   r*   r.   )r\   r  r  	op_schemar1   r1   r2   (test_check_type_when_schema_has_empty_io 3  s    
z;TestShapeInference.test_check_type_when_schema_has_empty_ioc                 C  `   d}t j|}| t jj t jj|dd t j| W d    d S 1 s)w   Y  d S )Na  
        <
        ir_version: 10,
        opset_import: ["" : 17]
        >
        graph (float in0, float[2,7,8,1,3] in1, float[3,7] in2) => () {
        out0, out1, out2 = LayerNormalization <epsilon: float = -841.058, stash_type: int = -940> (in0, in1, in2)
        }
        T
full_check	rl   r  r  r   rm   r   r   ro   rn   r\   modeltxtr  r1   r1   r2   #test_issue_layer_normalization_61873     	"z6TestShapeInference.test_issue_layer_normalization_6187c                 C  r  )Nz
        <
        ir_version: 9,
        opset_import: ["" : 11]
        >
        graph (float[7,6,1,5] in0, float in1, float[7,2,3,2,1] in2) => () {
        out0 = Conv <auto_pad = "NOTSET", group = 1> (in0, in1, in2)
        }
        Tr  r  r  r1   r1   r2   test_issue_conv_6180*3  r  z'TestShapeInference.test_issue_conv_6180c                 C  s`   d}t j|}| t jj t jj|dd t j| W d    d S 1 s)w   Y  d S )Na  
        <
        ir_version: 10,
        opset_import: ["" : 6]
        >
        graph (double[2,1] in0, double in1, double[2] in2) => () {
        out0 = Gemm <alpha: float = 1, beta: float = -693.752, broadcast: int = -436, transB: int = 823> (in0, in1, in2)
        }
        Tr  )	rl   r  r  r   r   rs  ro   rm   rn   r  r1   r1   r2   test_issue_gemm_618593  r  z'TestShapeInference.test_issue_gemm_6185c                 C  r  )Nz
        <
        ir_version: 10,
        opset_import: ["" : 17]
        >
        graph (float16[3] in0, int32[2] in1, float16[7,8,8,8] in2, int32[8,1,7,2] in3) => () {
        out0 = STFT (in0, in1, in2, in3)
        }
        Tr  r  r  r1   r1   r2   test_issue_stft_6186H3  r  z'TestShapeInference.test_issue_stft_6186rK  c              	   C  sd   | j dtjdfdgtddgdgddgg tdtjddgd}| jtjj	| j
|tt|gd	 d S )
Nzstd.constantr  r  rK  invalid_node)r  r  r-   )ir  r   )rc   r   r[   r   r   r   r   rl   rm   r   rr   r   r   r   r   r1   r1   r2   test_issue_constantofshape_6135W3  s$   
z2TestShapeInference.test_issue_constantofshape_6135c                 C  s$   d}t |t }| |g  d S )Na  
            ir_version: 8
            producer_name: "test"
            graph {
              node {
                input: "in"
                output: "out"
                op_type: "Flatten"
                attribute {
                  name: "axis"
                  type: INT
                }
              }
              name: "g"
              input {
                name: "in"
                type {
                  tensor_type {
                    elem_type: 1
                    shape {
                      dim {
                        dim_value: 2
                      }
                      dim {
                        dim_value: 3
                      }
                    }
                  }
                }
              }
              output {
                name: "out"
                type {
                  tensor_type {
                    elem_type: 1
                    shape {
                      dim {
                        dim_value: 1
                      }
                      dim {
                        dim_value: 6
                      }
                    }
                  }
                }
              }
            }
            opset_import {
              version: 18
            }
        )r   Parserl   r
   r   )r\   
model_textr  r1   r1   r2   test_protobuf_defaultm3  s   3z(TestShapeInference.test_protobuf_defaultc                 C  sL   t jd}| t jj t j| W d    d S 1 sw   Y  d S )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) }
        )rl   r  r  r   r   rs  rm   rn   r  r1   r1   r2   )test_infer_shapes_rejects_cyclic_function3  s   "z<TestShapeInference.test_infer_shapes_rejects_cyclic_functionc              
   C  s   d}dD ]E}| j |pdd3 tjd| | d}| tjj tjj|dd W d    n1 s5w   Y  W d    n1 sDw   Y  qd S )	Nzibody = b (float[1] si, float[1] xi) => (float[1] so, float[1] xo) { so = Identity(si) xo = Identity(xi) })r  znum_scan_inputs = -1, missing)rt  z
                    <ir_version: 8, opset_import: [ "" : 9 ]>
                    g (float[1] s, float[3,1] x) => (float[1] so, float[3,1] xo) {
                        so, xo = Scan <z3> (s, x)
                    }
                    Tr  )ru  rl   r  r  r   rm   r   rn   )r\   	scan_bodyrt  r  r1   r1   r2   0test_scan_invalid_num_scan_inputs_does_not_crash3  s$   zCTestShapeInference.test_scan_invalid_num_scan_inputs_does_not_crashc                 C  P   t jd}| t jj t jj|dd W d    d S 1 s!w   Y  d S )Na  
            <ir_version: 8, opset_import: [ "" : 18, "local" : 1 ]>
            agraph (float[1] X) => (float[1] Y) { Y = local.F (X) }
            <opset_import: [ "" : 18 ], domain: "local">
            F (x) => (y1, y2) { y1 = Identity(x) y2 = Identity(x) }
            Tr  rl   r  r  r   rm   r   rn   r  r1   r1   r2   2test_function_output_count_mismatch_does_not_crash3  s   "zETestShapeInference.test_function_output_count_mismatch_does_not_crashc                 C  r  )Nz
            <ir_version: 8, opset_import: [ "" : 11 ]>
            g (float[1,1,5] X, float[1,3] W) => (float[1,1,?] Y) { Y = ConvTranspose(X, W) }
            Tr  r  r  r1   r1   r2   ,test_conv_transpose_undersized_weight_raises3  s   "z?TestShapeInference.test_conv_transpose_undersized_weight_raisesc                 C  sB   |  td tjtd W d    d S 1 sw   Y  d S )NzCFor Model paths \(str or os.PathLike\), use infer_shapes_path\(\)\.z
model.onnx)r  	TypeErrorrl   rm   rn   r   rU  r1   r1   r2    test_infer_shapes_pathlike_error3  s   "z3TestShapeInference.test_infer_shapes_pathlike_errorr%   rt   )r   r9   rf   r   r%   rt   )r   r   r   r   r%   rt   )r   r   r   r   r   r   r%   rt   )r0   r  r  r9   r  r  r  r  r  r  r%   rt   )r0   r  ri  r  r  r  r%   rt   )r   r9   r0   r  r%   rt   )r   r9   r  r  r%   rt   )
r  r  r  r  r  r  r  r  r%   rt   )r  )r  r  r  r  r  r  r  r  r{  r9   r%   rt   )
r   r   r2  r   r  r   r  r   r%   r   )r   r9   r0   r  r  r9   r	  r  r:  r  r  r  r  r  r  r  r%   rt   )r   r9   r:  r  r%   rt   )r   r9   r   r  r%   rt   (  r   r   r   r   r   r   expandrA   r   r   r   r   r   r   r   r   r   r   r   r   unittestr   r   r   r  r  r	  r  r  r  r  r%  r*  r0  r5  r;  r@  rB  rD  rE  rI  rM  rN  rR  rU  rX  r\  r`  rw  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  r  r  r  r"  r$  r,  r-  r1  r2  r6  r9  r:  r<  rB  rE  rF  rL  rO  rQ  rW  rY  rZ  r\  r^  r_  r`  rb  rd  re  rm  rq  rx  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  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+  r4  r:  r;  r>  r@  rA  rC  rD  rE  rH  rL  rP  rV  rX  rc  rm  rp  rs  rv  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   r  r  r	  r  r  r  r  r  r   r!  r"  r#  r$  r)  r+  r,  r-  r1  r7  r=  r@  rA  rF  rI  rJ  rL  rO  rS  rU  rW  rY  rZ  r]  r`  ra  rb  rd  re  rf  rg  rj  rm  rq  ru  rx  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  r  r  r  r  r  r  r  r  r  r  r  r  r#  r%  r&  r)  r+  r.  r0  r6  r8  r;  r<  rI  rJ  rM  rQ  rS  rT  rW  r\  r^  r_  r`  ra  rb  rj  rl  ro  rp  rq  rr  rs  r{  r|  r~  r  r  r  rl   r   r   r   r(  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  
skipUnlessr   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/  r2  r5  r9  r;  r<  r>  r?  rA  rD  rF  rI  rM  rO  rP  rS  rW  rY  r]  r_  r`  rb  rc  rd  re  rg  rh  rk  rm  rq  rr  rt  rx  rz  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  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*  r5  r8  r9  r:  r;  r>  rA  rB  rE  rF  rM  rN  rO  rS  rU  rW  r[  rb  rd  rh  ri  rj  rl  ro  rq  ry  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  	itertoolsproductr  r  r  r  r  r
  r  r  r  r  r  r  r  r!  r+  r-  r3  r5  r7  r8  r9  r:  rF  rG  rN  r  ra  r   rb  re  ri  rk  rp  rq  rx  rv  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r1   r1   r1   r2   r      s   
	)/8"&" 




'$,,=








 
,"





 


















:9;99,**D6)%####$#($&

&
 $D
		



 %#)'.
































		


'))??(+++
*G
*r$% '.  
@A$ 4"""""""".	7r   c                   @  s   e Zd ZU dZded< dZded< dZded< d	Zded
< d#ddZd#ddZ	dd Z
dd Zd$ddZdd Zdd Zd#ddZd#ddZd#d d!Zd"S )%TestCustomSchemaShapeInferencer  r9   custom_op_type
DummyGraphdummy_graph_op_typer   r  
op_versionr  	op_domainr%   rt   c                 C  s4   |  tj| j| j |  tj| j| j d S rT   )rx  rl   r   hasr  r  r  rU  r1   r1   r2   setUp3  s   z$TestCustomSchemaShapeInference.setUpc                 C  s`   t tjj tj| j| j| j tj| j	| j| j W d    d S 1 s)w   Y  d S rT   )

contextlibsuppressrl   r   r   r  r  r  r  r  rU  r1   r1   r2   tearDown3  s   "z'TestCustomSchemaShapeInference.tearDownc              
     st   t  j j jtj ddtj ddgtj jddt jjdgtj dtj j	j
gd}d fd
d}|| |S )Nr   r  r   r?  param_optionout_lenr  r  r  ctx%onnx.shape_inference.InferenceContextc                   s:  d	 fdd}  |  d | d}| d}||\}}||\}}  |tj   |tj   t|d   t|d   |d |d  |\}}	|\}
}| d}|j}  t||   t	|  D ]-}| 
|}||j_||jjj _|	| |jjj _|| |jjj _| || qmd S )
Nr   r   c                   s,     t| t | jjdd | jjjD fS )Nc                 S  s    g | ]}| d r|jndqS )r   N)r   r   )r5   r
  r1   r1   r2   r=   4      zTestCustomSchemaShapeInference.get_custom_op_schema.<locals>.schema_shape_infer_func.<locals>.parse_tensor_input.<locals>.<listcomp>)
assertTruerW   r   r   r   r   r   )r   rU  r1   r2   parse_tensor_input4  s   zpTestCustomSchemaShapeInference.get_custom_op_schema.<locals>.schema_shape_infer_func.<locals>.parse_tensor_inputrQ   r   r   r  )r   r   )assertEqualget_num_inputsget_input_typer   r   r   get_attributeintsget_num_outputsr)   get_output_typer   r   r   r   r+   r   set_output_type)r  r  in0in1in0_type	in0_shapein1_type	in1_shaper   Lar   Lbattrr  r  r?  rU  r1   r2   schema_shape_infer_func4  s0   




zTTestCustomSchemaShapeInference.get_custom_op_schema.<locals>.schema_shape_infer_funcr  r  )r   r  r  r  r   FormalParameterFormalParameterOptionVariadic	AttributeAttrTypeINTS%set_type_and_shape_inference_functionr\   r$   r  r1   rU  r2   get_custom_op_schema3  s"   

"z3TestCustomSchemaShapeInference.get_custom_op_schemac              
     sp   t  j j jtj jddt jjdgtj jddt jjdgtj dtj j	j
gd}d fd	d
}|| |S )Ninr  r  r?  r}   r  r  r  c                   s      d  d  d}| fddt  D  fddt  D }t|D ]
\}} || q5d S )NrQ   r}   c                      g | ]}  |qS r1   )r  r  r  r1   r2   r=   Z4      zjTestCustomSchemaShapeInference.get_dummy_graph_schema.<locals>.schema_shape_infer_func.<locals>.<listcomp>c                   r  r1   )get_input_datar  r  r1   r2   r=   [4  r  )	r  r  assertIsNotNoner  get_graph_attribute_inferencerdo_inferencingr)   r   r  )r  gctxr  idxr?  rU  r  r2   r  U4  s   
zVTestCustomSchemaShapeInference.get_dummy_graph_schema.<locals>.schema_shape_infer_funcr  )r   r  r  r  r   r  r  r  r  r  GRAPHr  r  r1   rU  r2   get_dummy_graph_schema<4  s"   


z5TestCustomSchemaShapeInference.get_dummy_graph_schemaFc           
      C  s   t dtj||f}t dtj||f}dd tt|D }t| jddgdd |D |d}	t|	gd||g|r;||dS g |dS )	Nr   r   c                 S      g | ]}t d | tjdqS r?  Nr!   r   r   r  r1   r1   r2   r=   f4  r  zFTestCustomSchemaShapeInference.gen_custom_op_graph.<locals>.<listcomp>c                 S     g | ]}|j qS r1   rL   r5   r   r1   r1   r2   r=   k4  rP   )r  rV   rG   )r!   r   r   r)   r   r   r  r   )
r\   r   r  r  r  mark_outputr   r   outsr  r1   r1   r2   gen_custom_op_graphc4  s   
z2TestCustomSchemaShapeInference.gen_custom_op_graphc           
      C  s   |  ||||d}tdtj||f}tdtj||f}dd tt|D }t| jddgdd |D |d}	t|	gd||gg |d	S )
NTr   r   c                 S  r  r  r  r  r1   r1   r2   r=   u4  r  zHTestCustomSchemaShapeInference.gen_dummy_graph_graph.<locals>.<listcomp>c                 S  r  r1   rL   r  r1   r1   r2   r=   z4  rP   ru  rV   r  )	r  r!   r   r   r)   r   r   r  r   )
r\   r   r  r  r  r  r   r   r  r  r1   r1   r2   gen_dummy_graph_graphq4  s   
z4TestCustomSchemaShapeInference.gen_dummy_graph_graphc                   s&   |  | fddt|D  d S )Nc                   s.   g | ]\}}t d | tj  |fqS )r?  r  )r5   r  Lir  r  r   r1   r2   r=   4  s    zCTestCustomSchemaShapeInference.shape_infer_once.<locals>.<listcomp>)r   r   )r\   r}   r   r  r  r  r1   r  r2   shape_infer_once~4  s   z/TestCustomSchemaShapeInference.shape_infer_oncec                 C  s   d}d}d}ddg}|  ||||}| tjj | ||||| W d    n1 s-w   Y  |  }tj| | ||||| tj	|j
|j|j d S Nr   r  r  r   rQ   )r  r   rl   r   rs  r  r  r   r  r  r-   r*   r.   )r\   r   r  r  r  r}   r$   r1   r1   r2   "test_custom_schema_shape_inference4  s   zATestCustomSchemaShapeInference.test_custom_schema_shape_inferencec                 C  s   d}d}d}ddg}|  ||||}| tjj | ||||| W d    n1 s-w   Y  |  }|  }tj	| tj	| | ||||| tj
|j|j|j tj
|j|j|j d S r  )r  r   rl   r   rs  r  r  r  r   r  r  r-   r*   r.   )r\   r   r  r  r  r}   custom_op_schemadummy_graph_schemar1   r1   r2   'test_dummy_graph_schema_shape_inference4  s.   zFTestCustomSchemaShapeInference.test_dummy_graph_schema_shape_inferencec                   s   d}d}d}dg} ||||} }|  d	 fdd}|| tj| ||||| tj|j	|j
|j d S )
Nr   r  r  r   r  r  c                   s   |   | d | d | d t | d W d    n1 s4w   Y  | d | d t | d W d    n1 saw   Y  tj	j
 | d W d    n1 s}w   Y   | d t  | d W d    n1 sw   Y   | d t  | d W d    n1 sw   Y  | d t | d W d    n1 sw   Y   | d t | d W d    n	1 sw   Y  | d t | d W d    n	1 s/w   Y  |  d |  d d S )Nznot-exist-attrr   rQ   r'   r   r1  )assertIsNoner  r  	has_inputrx  r   r  
has_outputrl   rm   r   r  r  RuntimeErrorget_input_sparse_datar  r  get_symbolic_inputr  r  r  r  r  raw_funcr\   r1   r2   r  4  sJ   zdTestCustomSchemaShapeInference.test_invalid_field_in_inference_func.<locals>.schema_shape_infer_funcr  )r  r  %get_type_and_shape_inference_functionr  rl   r   r  r  r  r-   r*   r.   )r\   r   r  r  r  r}   r$   r  r1   r  r2   $test_invalid_field_in_inference_func4  s   
zCTestCustomSchemaShapeInference.test_invalid_field_in_inference_funcNr  )F)r   r   r   r  __annotations__r  r  r  r  r  r  r  r  r  r  r  r  r  r1   r1   r1   r2   r  3  s   
 


B
'
	
!r  __main__rQ   )	verbosity)r$   r   r%   r&   )r8   r9   r%   r:   )=
__future__r   r  r  r  pathlibr   typingr   r   numpyr   r   google.protobufr   r   onnx.shape_inferencerl   r   r	   r
   r   r   r   r   r   r   r   r   r   r   	onnx.defsr   r   r   r   r   r   onnx.helperr   r   r   r   r   r    r!   onnx.parserr"   collections.abcr#   r3   get_all_schemasr7   r  rA   TestCaserB   r   r  r   mainr1   r1   r1   r2   <module>   s
  < $	

                                                                                                       a  