o
    ået  ã                   @   sÐ   d dl mZ d dlmZmZmZmZmZmZm	Z	 d dl
Z
d dlZd dlm  mZ d dlmZmZmZ G dd„ dƒZG dd„ dƒZd	ed
ee dededeeedf  f
dd„ZG dd„ dƒZG dd„ dƒZdS )é    )Ú
namedtuple)ÚSequenceÚAnyÚTypeÚTupleÚNewTypeÚOptionalÚDictN)Ú
ModelProtoÚ	NodeProtoÚ
IR_VERSIONc                   @   s8   e Zd ZU edeƒZedƒZeed< edƒZeed< dS )Ú
DeviceTypeÚ_Typer   ÚCPUé   ÚCUDAN)	Ú__name__Ú
__module__Ú__qualname__r   Úintr   r   Ú__annotations__r   © r   r   úAD:\Projects\ConvertPro\env\Lib\site-packages\onnx/backend/base.pyr      s   
 
r   c                   @   s"   e Zd ZdZdeddfdd„ZdS )ÚDevicez~
    Describes device type and device id
    syntax: device_type:device_id(optional)
    example: 'CPU', 'CUDA', 'CUDA:1'
    ÚdeviceÚreturnNc                 C   sB   |  d¡}tt|d ƒ| _d| _t|ƒdkrt|d ƒ| _d S d S )Nú:r   r   )ÚsplitÚgetattrr   ÚtypeZ	device_idÚlenr   )Úselfr   Úoptionsr   r   r   Ú__init__   s   
ÿzDevice.__init__)r   r   r   Ú__doc__Ústrr#   r   r   r   r   r      s    r   ÚtypenameÚfield_namesÚargsÚkwargsr   .c                    s`   dd„ t |ƒD ƒ‰ | dd¡ t| |g|¢R i |¤Ž}dtdtdtf‡ fdd	„}t|d
|ƒ |S )Nc                 S   s   i | ]\}}||“qS r   r   )Ú.0ÚiÚnr   r   r   Ú
<dictcomp>#   s    z"namedtupledict.<locals>.<dictcomp>ÚrenameTr!   Úkeyr   c                    s&   t |tƒr	ˆ | }tt| ƒ| ƒ |¡S ©N)Ú
isinstancer%   Úsuperr   Ú__getitem__)r!   r/   ©Zfield_names_mapr   r   Úgetitem(   s   
znamedtupledict.<locals>.getitemr3   )Ú	enumerateÚ
setdefaultr   r   Úsetattr)r&   r'   r(   r)   Údatar5   r   r4   r   Únamedtupledict"   s   r:   c                   @   s*   e Zd Zdededeedf fdd„ZdS )Ú
BackendRepÚinputsr)   r   .c                 K   s   d S r0   r   )r!   r<   r)   r   r   r   Úrun1   s   zBackendRep.runN)r   r   r   r   r   r=   r   r   r   r   r;   0   s    "r;   c                   @   sò   e Zd Ze	ddedededefdd„ƒZe	ddededede	e
 fdd	„ƒZe	dded
edededeedf f
dd„ƒZe		dded
edede	eeejeedf f   deeef de	eedf  fdd„ƒZededefdd„ƒZdS )ÚBackendr   Úmodelr   r)   r   c                 K   ó   dS )NTr   ©Úclsr?   r   r)   r   r   r   Úis_compatible6   s   zBackend.is_compatiblec                 K   s   t j |¡ d S r0   )ÚonnxÚcheckerZcheck_modelrA   r   r   r   Úprepare?   s   zBackend.preparer<   .c                 K   s*   | j ||fi |¤Ž}|d usJ ‚| |¡S r0   )rF   r=   )rB   r?   r<   r   r)   Úbackendr   r   r   Ú	run_modelI   s   
zBackend.run_modelNÚnodeÚoutputs_infoc                 K   sF   d|v rt  ¡ }t|_d|d i|_tj ||¡ dS tj |¡ dS )aˆ  Simple run one operator and return the results.
        Args:
            outputs_info: a list of tuples, which contains the element type and
            shape of each output. First element of the tuple is the dtype, and
            the second element is the shape. More use case can be found in
            https://github.com/onnx/onnx/blob/main/onnx/backend/test/runner/__init__.py
        Zopset_versionÚ N)Ú	c_checkerZCheckerContextr   Z
ir_versionZopset_importsrD   rE   Z
check_node)rB   rI   r<   r   rJ   r)   Zspecial_contextr   r   r   Úrun_nodeT   s   ÿzBackend.run_nodec                 C   r@   )zŽ
        Checks whether the backend is compiled with particular device support.
        In particular it's used in the testing suite.
        Tr   )rB   r   r   r   r   Úsupports_devicem   s   zBackend.supports_device)r   )r   N)r   r   r   Úclassmethodr
   r%   r   ÚboolrC   r   r;   rF   r   rH   r   r   ÚnumpyZdtyper   r	   rM   rN   r   r   r   r   r>   5   sl    þÿþýüþÿþýü	ýÿþýü
û
üÿþýü
ûúr>   )Úcollectionsr   Útypingr   r   r   r   r   r   r	   rQ   Zonnx.checkerrD   Zonnx.onnx_cpp2py_export.checkerZonnx_cpp2py_exportrE   rL   r
   r   r   r   r   r%   r:   r;   r>   r   r   r   r   Ú<module>   s   $.