U
    qh                     @  s   d dl mZ d dlZd dlmZmZmZmZm	Z	m
Z
mZ d dlmZmZ dd ZG dd deZG d	d
 d
eZG dd deZG dd deZG dd deZdS )    )annotationsN)bfloat16float8e4m3fnfloat8e4m3fnuz
float8e5m2float8e5m2fnuzint4uint4)OpRunRefAttrNamec                 C  s~   | j }t|tj sz|ttttttt	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thkrztd| dt| dd S )NzType (z, z+) is not a numpy type (operator 'Constant'))dtype
isinstancenpr   r   r   r   r   r	   r   Zint8Zuint8Zfloat16float32Zfloat64Zint32int64Zint16Zuint16Zuint32Zbool_str_Zuint64boolstr	TypeErrortype)vala r   B/tmp/pip-unpacked-wheel-xnis5xre/onnx/reference/ops/op_constant.py_check_dtype   s8    r   c                   @  s   e Zd Zdd ZdS )ConstantCommonc                 C  s"   t |trtdt| d|S )NzUnexpected type z for a constant.)r   tupler   r   )selfcstr   r   r   _check4   s    
zConstantCommon._checkN)__name__
__module____qualname__r   r   r   r   r   r   3   s   r   c                   @  s   e Zd Zdd Zdd ZdS )
Constant_1c                 C  s$   t | || | j| _t| j d S N)r   __init__valuer   r   r   	onnx_node
run_paramsr   r   r   r%   ;   s    zConstant_1.__init__c                 K  sD   |r6t |dks.d|ks.t|d t| jkr6td| | jfS N   r&   zHFunction attributes are not implemented for opset <= 11. Use opset > 12.lenidr&   RuntimeErrorr   r   r   overridden_attributesr   r   r   _run@   s    
zConstant_1._runNr    r!   r"   r%   r2   r   r   r   r   r#   :   s   r#   c                   @  s   e Zd Zdd ZdS )
Constant_9c                 C  s   t | || d S r$   )r#   r%   r'   r   r   r   r%   M   s    zConstant_9.__init__N)r    r!   r"   r%   r   r   r   r   r4   L   s   r4   c                   @  s   e Zd Zdd Zdd ZdS )Constant_11c                 C  s>   t | || t| dd d kr(| j| _n| j| _t| j d S )Nsparse_value)r   r%   getattrr&   r   r6   r   r'   r   r   r   r%   R   s
    
zConstant_11.__init__c                 K  sD   |r6t |dks.d|ks.t|d t| jkr6td| | jfS r*   r,   r0   r   r   r   r2   Z   s    
zConstant_11._runNr3   r   r   r   r   r5   Q   s   r5   c                   @  s   e Zd Zdd Zdd ZdS )Constant_12c                 C  s$  t | || t| dr<| jd k	r<d| _| j| _dd | _nt| dr|| jd k	r|d| _t| jt	rh| jn| j| _dd | _nt
jt
jt
jt
jt
jt
jd D ]b\}}t| |rt| |d k	r|| _t| |}t|t	r|nt
j||d| _|fdd| _ qqt| d	s td
|j dd S )Nr6   c                 S  s   | S r$   r   vr   r   r   <lambda>l       z&Constant_12.__init__.<locals>.<lambda>r&   c                 S  s   | S r$   r   r9   r   r   r   r;   p   r<   )Zvalue_floatZvalue_floatsZ	value_intZ
value_intsZvalue_stringZvalue_stringsr   c                 S  s   t j| |dS )Nr=   )r   array)r:   np_dtyper   r   r   r;      s    cst_namez<No constant is defined for operator 'Constant', outputs are .)r   r%   hasattrr6   r@   r   cst_convertr&   r   r   r   r   r   r   itemsr7   r>   AttributeErroroutput)r   r(   r)   attrr?   r:   r   r   r   r%   g   s:    
zConstant_12.__init__c                 K  s|   | j rn|d kr td| jd| j|krFtd| jdt|d|| j }t|tjrb|fS | |fS | 	| jfS )Nz0Attributes are empty, cannot retrieve value for rA   zCannot find attribute z in )
Zhas_linked_attributer/   r   r@   listr   r   ZndarrayrC   r   )r   r1   r&   r   r   r   r2      s    

zConstant_12._runNr3   r   r   r   r   r8   f   s   $r8   )
__future__r   Znumpyr   Zonnx._custom_element_typesr   r   r   r   r   r   r	   Zonnx.reference.op_runr
   r   r   r   r#   r4   r5   r8   r   r   r   r   <module>   s   $	