o
    Xi$8                     @  s  d Z ddlmZ ddlZddlmZ ddlZddlZG dd dej	Z
G dd dej	Zi ejd	ejd
ejd
ejdejdejd	ejdejd
ejdejdejd	ejdejdejdejdejd
ejd
ejd
ejd
ejdej dej!dej"d
ej#dej$diZ%i e&deje&deje&deje&deje&deje&deje&deje&deje&deje&deje&dej'e&deje&deje&deje&deje&ej(eje&ej)eje&ej*eje&ej+eje&ej,eje&ej-ej"e&ej.ej e&ej/eje&ej0ej!e&ej1ej#e&ej2ej$i	Z3dd  e34 D Z5i ej6d!ejd"ejd#ejd$ejd%ejd&ejd'ejd(ejd)ej"d*ej!d+ejd,ejd-ej#d.ej d/ejd0ejd1ejd2ejd3ejd4ej$d5ejd6ejd7ejd8ejd9ejd:ej'd;i
Z7d<d  e74 D Z8dS )=z)ONNX IR enums that matches the ONNX spec.    )annotationsN)Anyc                   @  s`   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdddZdddZdS )AttributeTypez&Enum for the types of ONNX attributes.r                           	   
               returnstrc                 C     | j S Nnameself r   B/home/ubuntu/.local/lib/python3.10/site-packages/onnx_ir/_enums.py__repr__!      zAttributeType.__repr__c                 C     |   S r   r   r   r   r   r   __str__$      zAttributeType.__str__Nr   r   )__name__
__module____qualname____doc__	UNDEFINEDFLOATINTSTRINGTENSORGRAPHFLOATSINTSSTRINGSTENSORSGRAPHSSPARSE_TENSORSPARSE_TENSORS
TYPE_PROTOTYPE_PROTOSr   r!   r   r   r   r   r      s&    
r   c                   @  st  e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZedOd d!Z edPd$d%Z!e"dQd'd(Z#e"dRd*d+Z$e"dRd,d-Z%e"dRd.d/Z&e"dSd1d2Z'e"dSd3d4Z(e"dSd5d6Z)e"dSd7d8Z*e"dRd9d:Z+e"dSd;d<Z,dTd=d>Z-dUd?d@Z.dVdBdCZ/dVdDdEZ0dVdFdGZ1dVdHdIZ2dUdJdKZ3dUdLdMZ4dNS )WDataTypezIEnum for the data types of ONNX tensors, defined in ``onnx.TensorProto``.r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r                                       dtypenp.dtyper   c                 C  s   |t v r
| t | S t|tjst|tjrtjS t|drp|jdkr(tj	S |jdkr0tj
S |jdkr8tjS |jdkr@tjS |jdkrHtjS |jdkrPtjS |jdkrXtjS |jd	kr`tjS |jd
krhtjS |jdkrptjS td| )zReturns the ONNX data type for the numpy dtype.

        Raises:
            TypeError: If the data type is not supported by ONNX.
        names)bfloat16)e4m3fn)e4m3fnuz)e5m2)e5m2fnuz)uint4)int4)
float4e2m1)int2)uint2zUnsupported numpy data type: )_NP_TYPE_TO_DATA_TYPEnp
issubdtypestr_bytes_r7   r+   hasattrrF   BFLOAT16FLOAT8E4M3FNFLOAT8E4M3FNUZ
FLOAT8E5M2FLOAT8E5M2FNUZUINT4INT4
FLOAT4E2M1INT2UINT2	TypeError)clsrD   r   r   r   
from_numpyI   s4   










zDataType.from_numpy
short_namer   c                 C  s"   |t vrtd| | t | S )zReturns the ONNX data type for the short name.

        Raises:
            TypeError: If the short name is not available for the data type.
        zUnknown short name: )_SHORT_NAME_TO_DATA_TYPEra   )rb   rd   r   r   r   from_short_namep   s   zDataType.from_short_namefloatc                 C  s
   | j d S )z+Returns the size of the data type in bytes.r   )bitwidthr   r   r   r   itemsize{   s   
zDataType.itemsizeintc                 C     | t vrtd|  t |  S )zReturns the bit width of the data type.

        .. versionadded:: 0.1.2

        Raises:
            TypeError: If the data type is not supported.
        z+Bitwidth not available for ONNX data type: )_BITWIDTH_MAPra   r   r   r   r   rh      s   	zDataType.bitwidthc                 C  &   |   rt|  jS td|  )zReturns the bit width of the exponent for floating-point types.

        .. versionadded:: 0.1.8

        Raises:
            TypeError: If the data type is not supported.
        z+Exponent not available for ONNX data type: )is_floating_point	ml_dtypesfinfonumpynexpra   r   r   r   r   exponent_bitwidth      	zDataType.exponent_bitwidthc                 C  rm   )zReturns the bit width of the mantissa for floating-point types.

        .. versionadded:: 0.1.8

        Raises:
            TypeError: If the data type is not supported.
        z+Mantissa not available for ONNX data type: )rn   ro   rp   rq   nmantra   r   r   r   r   mantissa_bitwidth   rt   zDataType.mantissa_bitwidthint | np.floating[Any]c                 C  2   |   rdS |  rt|  jS td|  )a  Returns the difference between 1.0 and the next smallest representable float larger than 1.0 for the ONNX data type.

        Returns 1 for integers.

        .. versionadded:: 0.1.8

        Raises:
            TypeError: If the data type is not a numeric data type.
        r   z&Eps not available for ONNX data type: )
is_integerrn   ro   rp   rq   epsra   r   r   r   r   rz      
   zDataType.epsc                 C  rx   )zReturns the smallest positive non-zero value for the ONNX data type.

        Returns 1 for integers.

        .. versionadded:: 0.1.8

        Raises:
            TypeError: If the data type is not a numeric data type.
        r   z'Tiny not available for ONNX data type: )ry   rn   ro   rp   rq   tinyra   r   r   r   r   r|      r{   zDataType.tinyc                 C  >   |   rt|  jS |  rt|  jS td|  )zReturns the minimum representable value for the ONNX data type.

        .. versionadded:: 0.1.8

        Raises:
            TypeError: If the data type is not a numeric data type.
        z*Minimum not available for ONNX data type: )ry   ro   iinforq   minrn   rp   ra   r   r   r   r   r      
   	zDataType.minc                 C  r}   )zReturns the maximum representable value for the ONNX data type.

        .. versionadded:: 0.1.8

        Raises:
            TypeError: If the data type is not a numeric data type.
        z*Maximum not available for ONNX data type: )ry   ro   r~   rq   maxrn   rp   ra   r   r   r   r   r      r   zDataType.maxc                 C  rx   )aB  Returns the precision for the ONNX dtype if supported.

        For floats returns the approximate number of decimal digits to which
        this kind of float is precise. Returns 0 for integers.

        .. versionadded:: 0.1.8

        Raises:
            TypeError: If the data type is not a numeric data type.
        r   z,Precision not available for ONNX data type: )ry   rn   ro   rp   rq   	precisionra   r   r   r   r   r      
   zDataType.precisionc                 C  rx   )a/  Returns the resolution for the ONNX dtype if supported.

        Returns the approximate decimal resolution of this type, i.e.,
         10**-precision. Returns 1 for integers.

        .. versionadded:: 0.1.8

        Raises:
            TypeError: If the data type is not a numeric data type.
        r   z-Resolution not available for ONNX data type: )ry   rn   ro   rp   rq   
resolutionra   r   r   r   r   r     r   zDataType.resolutionc                 C  rk   )zReturns the numpy dtype for the ONNX data type.

        Raises:
            TypeError: If the data type is not supported by numpy.
        z'Numpy does not support ONNX data type: )_DATA_TYPE_TO_NP_TYPEra   r   r   r   r   rq     s   zDataType.numpyc                 C  rk   )a  Returns the short name of the data type.

        The short name is a string that is used to represent the data type in a more
        compact form. For example, the short name for `DataType.FLOAT` is "f32".
        To get the corresponding data type back, call ``from_short_name`` on a string.

        Naming reference: https://github.com/pytorch/pytorch/blob/4bead7b85ea4160243c74109e0ce9bb80686d016/torch/utils/_dtype_abbrs.py

        Raises:
            TypeError: If the short name is not available for the data type.
        z-Short name not available for ONNX data type: )_DATA_TYPE_TO_SHORT_NAMEra   r   r   r   r   rd   #  s   zDataType.short_nameboolc                 C  s0   | t jt jt jt jt jt jt jt jt j	t j
h
v S )z7Returns True if the data type is a floating point type.)r7   r)   FLOAT16DOUBLErW   rX   rY   rZ   r[   r^   
FLOAT8E8M0r   r   r   r   rn   3  s   zDataType.is_floating_pointc                 C  s8   | t jt jt jt jt jt jt jt jt j	t j
t jt jhv S )zVReturns True if the data type is an integer.

        .. versionadded:: 0.1.4
        )r7   UINT8INT8UINT16INT16INT32INT64UINT32UINT64r\   r]   r_   r`   r   r   r   r   ry   B  s   zDataType.is_integerc                 C  sP   | t jt jt jt jt jt jt jt jt j	t j
t jt jt jt jt jt jt jt jhv S )zYReturns True if the data type is a signed type.

        .. versionadded:: 0.1.4
        )r7   r)   r   r   r   r   r   r   	COMPLEX64
COMPLEX128rW   rX   rY   rZ   r[   r]   r^   r   r_   r   r   r   r   	is_signedV  s(   zDataType.is_signedc                 C  s
   | t jkS )zYReturns True if the data type is a string type.

        .. versionadded:: 0.1.8
        )r7   r+   r   r   r   r   	is_stringp  s   
zDataType.is_stringc                 C  r   r   r   r   r   r   r   r   w  r   zDataType.__repr__c                 C  r   r   r    r   r   r   r   r!   z  r"   zDataType.__str__N)rD   rE   r   r7   )rd   r   r   r7   )r   rg   )r   rj   )r   rw   )r   rE   r#   )r   r   )5r$   r%   r&   r'   r(   r)   r   r   r   r   r   r   r+   BOOLr   r   r   r   r   r   rW   rX   rY   rZ   r[   r\   r]   r^   r   r`   r_   classmethodrc   rf   propertyri   rh   rs   rv   rz   r|   r   r   r   r   rq   rd   rn   ry   r   r   r   r!   r   r   r   r   r7   (   sz    &








r7       r   r9   @      r   r   r   
complex128	complex64float16float32float64int16int32int64int8objectuint16uint32uint64uint8c                 C     i | ]\}}||qS r   r   .0kvr   r   r   
<dictcomp>      r   	undefinedbf16f64f32f16f8e4m3fnf8e5m2
f8e4m3fnuz
f8e5m2fnuzf8e8m0f4e2m1c64c128i2i4i8i16i32i64b8u2u4u8u16u32u64sc                 C  r   r   r   r   r   r   r   r     r   )9r'   
__future__r   enumtypingr   ro   rq   rR   IntEnumr   r7   r)   r   r   r   r   r   r   r   r   r   r   r   r   r   rW   rX   rY   rZ   r[   r\   r]   r^   r   r_   r`   rl   rD   r+   rG   float8_e4m3fnfloat8_e4m3fnuzfloat8_e5m2float8_e5m2fnuzfloat8_e8m0fnurM   rL   float4_e2m1fnrO   rP   rQ   itemsr   r(   r   re   r   r   r   r   <module>   s&    X	
	
	
