U
    qh
                     @  s4   d dl mZ d dlZd dlmZ G dd deZdS )    )annotationsN)OpRunc                   @  s2   e Zd Zdd ZddddZddd	d
dZdS )Ifc                 C  sF   t | || d| jkr tdd|kr0tdd| jkrBtdd S )NZopsetsz&run_params must contains key 'opsets'.verbosez'run_params must contains key 'verbose'.Zexisting_functionsz2run_params must contains key 'existing_functions'.)r   __init__
run_paramsKeyError)self	onnx_noder    r   </tmp/pip-unpacked-wheel-xnis5xre/onnx/reference/ops/op_if.pyr      s    

zIf.__init__bool)returnc                 C  s   dS )zTells the runtime if this node needs the context
        (all the results produced so far) as it may silently access
        one of them (operator Loop).
        The default answer is `False`.
        Tr   )r	   r   r   r   need_context   s    zIf.need_contextNznp.ndarray | np.bool_)condc                 C  s2  |j dkr(td| jjdt| d|d}|rh| d| | j||d}| d t|}d	}	n0| d
| | j	||d}| d t|}d}	|st
d| jjdt|D ]n\}
}|d kr|	d	kr| jn| j}|j}dd |jjjD }t
d|
d|	d||
 dt| d| dq| |S )N   zOperator If (zC) expects a single element as condition, but the size of 'cond' is .r   z  -- then> {%r})
attributesz
  -- then<Zthenz  -- else> {%r}z
  -- else<elsez) does not have any output.c                 S  s   g | ]
}|j qS r   )name).0ir   r   r   
<listcomp>@   s     zIf._run.<locals>.<listcomp>zOutput z	 (branch=z, name=z) is None, available inputs=z, initializers=)size
ValueErrorr
   r   lenitem_logZ_run_then_branchtupleZ_run_else_branchRuntimeError	enumeratethen_branchelse_branchZoutput_namesobjgraphZinitializersortedZ_check_and_fix_outputs)r	   r   contextr"   r!   r   Zcond_outputsfinalbranchr   fbrnamesZinitsr   r   r   _run   s:    



*zIf._run)NNNN)__name__
__module____qualname__r   r   r-   r   r   r   r   r      s   	    r   )
__future__r   ZnumpynpZonnx.reference.op_runr   r   r   r   r   r   <module>   s   