o
    ;Î®cã  ã                   @   s@   d Z ddlmZmZ ddlmZ ddlmZ G dd„ deƒZdS )z 
Implements ONNX's backend API.
é    )ÚAnyÚTuple)Ú
BackendRep)Ú
RunOptionsc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚOnnxRuntimeBackendRepzr
    Computes the prediction for a pipeline converted into
    an :class:`onnxruntime.InferenceSession` node.
    c                 C   s
   || _ dS )zG
        :param session: :class:`onnxruntime.InferenceSession`
        N)Ú_session)ÚselfÚsession© r
   úF/tmp/pip-target-vg8gfxp4/lib/python/onnxruntime/backend/backend_rep.pyÚ__init__   s   
zOnnxRuntimeBackendRep.__init__c           
         sì   t ƒ }| ¡ D ]\}}t||ƒrt|||ƒ qt|tƒrSi }t| j ¡ ƒD ]\}}|| ||j	< q%| j 
d||¡‰ tˆ tƒr@ˆ S dd„ | j ¡ D ƒ}	‡ fdd„|	D ƒS | j ¡ }t|ƒdkrgtd t|ƒ¡ƒ‚|d j	|i}| j 
d||¡S )z`
        Computes the prediction.
        See :meth:`onnxruntime.InferenceSession.run`.
        Nc                 S   s   g | ]}|j ‘qS r
   )Úname)Ú.0Úor
   r
   r   Ú
<listcomp>.   s    z-OnnxRuntimeBackendRep.run.<locals>.<listcomp>c                    s   g | ]}ˆ | ‘qS r
   r
   )r   r   ©Úoutsr
   r   r   /   s    é   zModel expect {0} inputsr   )r   ÚitemsÚhasattrÚsetattrÚ
isinstanceÚlistÚ	enumerater   Ú
get_inputsr   ÚrunÚget_outputsÚlenÚRuntimeErrorÚformat)
r   ÚinputsÚkwargsÚoptionsÚkÚvÚinpsÚiÚinpÚoutput_namesr
   r   r   r      s&   
€


zOnnxRuntimeBackendRep.runN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r
   r
   r
   r   r      s    r   N)	r,   Útypingr   r   Úonnx.backend.baser   Úonnxruntimer   r   r
   r
   r
   r   Ú<module>   s
   