U
    rhi                     @  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 d S )N )xcondr   r   B/tmp/pip-unpacked-wheel-xnis5xre/onnx/backend/test/case/node/if.pycompute_if_outputs   s    r	   c                   @  sB   e Zd ZeddddZeddddZeddddZd	S )
IfNone)returnc               	   C  s(  t jdt jjdg} t jdt jjdg}tdddddgtj}tdddddg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}	|	r|n|}
t||	g|
gdt jddgd d S )Nthen_out   else_out            Constantinputsoutputsvalue	then_body	else_bodyr
   r   resr   r   Zthen_branchZelse_branchZtest_if    r   r   nameopset_imports)onnxhelperZ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   sh        

      zIf.export_ifc               	   C  sj  t jjdt jjdgd} t jjdt jjdgd}tdddddgtjg}tdddddg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   r   r   SequenceConstructr   r   r0   r   r   r
   r   r   r   Ztest_if_seqr      r   )r"   r#   Zmake_tensor_sequence_value_infor$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r   r/   )r   r   r   r0   r1   Zthen_seq_noder2   else_seq_noder   r   r3   r   r   r   r   r   export_if_seqL   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	dddddg
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   r5   Zoptional_emptyZelse_optr   r   r   r   r   Optional)r   r   typer   r   r   r   r7   Zelse_seqr8   r   r
   r   sequencer   Ztest_if_optr      )r   r   r    Zoutput_type_protosr!   )r"   r#   Zmake_tensor_type_protor$   r%   Zmake_sequence_type_protoZmake_optional_type_protoZmake_value_infor&   r'   r(   r)   r.   r	   r*   r-   r+   r,   r   r/   )Z	ten_in_tpZ	seq_in_tpZthen_out_tensor_tpZthen_out_seq_tpZthen_out_opt_tpr   Zelse_out_tensor_tpZelse_out_seq_tpZelse_out_opt_tpr   r   r   r   Zopt_empty_inr   r2   r:   Zelse_optional_seq_noder   r3   r   r   r   export_if_optional   s       
       zIf.export_if_optionalN)__name__
__module____qualname__staticmethodr4   r;   r@   r   r   r   r   r
      s   6>r
   )
__future__r   Znumpyr&   r"   Zonnx.backend.test.case.baser   Zonnx.backend.test.case.noder   r	   r
   r   r   r   r   <module>   s   