o
    soiK                     @  sP   d dl mZ d dlZd dlZd dlmZ d dlmZ dd Z	G dd deZ
dS )	    )annotationsN)Base)expectc                 C  s   |rg S | S )N )xcondr   r   R/home/ubuntu/.local/lib/python3.10/site-packages/onnx/backend/test/case/node/if.pycompute_if_outputs   s   r	   c                   @  s6   e Zd Zed
ddZed
ddZed
ddZd	S )IfreturnNonec               	   C  s  t jdt jjdg} t jdt jjdg}tg dtj}tg dtj}t jj	dg dgt j
|d}t jj	dg dgt j
|d}t j|gdg | g}t j|gd	g |g}t jj	d
dgdg||d}tdt}	|	ry|n|}
t||	g|
gdt jddgd d S )Nthen_out   else_out            r   r   r   r   r   r   Constantinputsoutputsvalue	then_body	else_bodyr
   r   resr   r   then_branchelse_branchr   test_if    r   r   nameopset_imports)onnxhelpermake_tensor_value_infoTensorProtoFLOATnparrayastypefloat32	make_nodenumpy_helper
from_array
make_graphboolr   make_opsetid)r   r   r   ythen_const_nodeelse_const_noder   r   if_noder   r   r   r   r   	export_if   sT   


zIf.export_ifc               	   C  s\  t jjdt jjdgd} t jjdt jjdgd}tg dtjg}tg dtjg}t jj	dg dgt j
|d	 d
}t jj	ddgdgd}t jj	dg dgt j
|d	 d
}t jj	ddgdgd}t j||gdg | g}t j||gdg |g}	t jj	ddgdg||	d}
tdt}|r|n|}t|
|g|gdt jddgd d S )Nr   r   shaper   r   r   r   r   r   r   SequenceConstructr   r   r6   r   r   r
   r   r   r   r   test_if_seqr"      r$   )r'   r(   make_tensor_sequence_value_infor*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r   r5   )r   r   r   r6   r7   then_seq_noder8   else_seq_noder   r   r9   r   r   r   r   r   export_if_seqK   s`   


zIf.export_if_seqc               
   C  s  t jjt jjdgd} t j| }t jjt jjdgd}t j|}t j|}t jd|}t jjt jjdgd}t j|}t j|}t jd|}	t	g d
tjg}
t	d
t}t|
|}t jjdg dg|d}t j|gd	g |g}t jjd
g dgt j|
d d}t jjddgdgd}t jjddgdgd}t j|||gdg |	g}t jjddgdg||d}t||g|gd|gt jddgd d S )Nr   r;   optional_emptyelse_optr   r   Optional)r   r   typer   r   r   r   r=   else_seqr>   r   r
   r   sequencer   test_if_optr"      )r   r   r%   output_type_protosr&   )r'   r(   make_tensor_type_protor*   r+   make_sequence_type_protomake_optional_type_protomake_value_infor,   r-   r.   r/   r4   r	   r0   r3   r1   r2   r   r5   )	ten_in_tp	seq_in_tpthen_out_tensor_tpthen_out_seq_tpthen_out_opt_tpr   else_out_tensor_tpelse_out_seq_tpelse_out_opt_tpr   r   r   r   opt_empty_inr   r8   rC   else_optional_seq_noder   r9   r   r   r   export_if_optional   sp   







zIf.export_if_optionalN)r   r   )__name__
__module____qualname__staticmethodr:   rD   r\   r   r   r   r   r
      s    6>r
   )
__future__r   numpyr,   r'   onnx.backend.test.case.baser   onnx.backend.test.case.noder   r	   r
   r   r   r   r   <module>   s   