o
    wi                     @  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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
float4e2m1float8e4m3fnfloat8e4m3fnuz
float8e5m2float8e5m2fnuzint4uint4)OpRunRefAttrNamec                 C  s   | j }t|tj s>|t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vr@td| dt| dd S d S )NzType (z, z+) is not a numpy type (operator 'Constant'))dtype
isinstancenpr   r   r   r   r   r
   r	   r   int8uint8float16float32float64int32int64int16uint16uint32bool_str_uint64boolstr	TypeErrortype)vala r#   [/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/onnx/reference/ops/op_constant.py_check_dtype   s<   r%   c                   @     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$   _check6   s   
zConstantCommon._checkN)__name__
__module____qualname__r+   r#   r#   r#   r$   r'   5       r'   c                   @     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$   r3   =   s   zConstant_1.__init__c                 K  D   |rt |dksd|vst|d t| jkrtd| | jfS N   r4   zHFunction attributes are not implemented for opset <= 11. Use opset > 12.lenidr4   RuntimeErrorr+   r*   r)   overridden_attributesr#   r#   r$   _runB      zConstant_1._runNr,   r-   r.   r3   rA   r#   r#   r#   r$   r1   <   s    r1   c                   @  r&   )
Constant_9c                 C  s   t | || d S r2   )r1   r3   r5   r#   r#   r$   r3   O   s   zConstant_9.__init__N)r,   r-   r.   r3   r#   r#   r#   r$   rD   N   r/   rD   c                   @  r0   )Constant_11c                 C  s>   t | || t| dd d u r| j| _n| j| _t| j d S )Nsparse_value)r'   r3   getattrr4   r*   rF   r%   r5   r#   r#   r$   r3   T   s
   
zConstant_11.__init__c                 K  r8   r9   r;   r?   r#   r#   r$   rA   \   rB   zConstant_11._runNrC   r#   r#   r#   r$   rE   S   s    rE   c                   @  r0   )Constant_12c                 C  s  t | || t| dr| jd urd| _| j| _dd | _nYt| dr5| jd ur5d| _| j| _dd | _nBtj	tj	tj
tj
tjtjd D ]0\}}t| |rvt| |d urv|| _t| |}t|tre|ntj||d| _|fdd| _ nqFt| d	std
|j dd S )NrF   c                 S     | S r2   r#   vr#   r#   r$   <lambda>n       z&Constant_12.__init__.<locals>.<lambda>r4   c                 S  rI   r2   r#   rJ   r#   r#   r$   rL   r   rM   )value_floatvalue_floats	value_int
value_intsvalue_stringvalue_stringsr   c                 S  s   t j| |dS )NrT   )r   array)rK   np_dtyper#   r#   r$   rL      s    cst_namez<No constant is defined for operator 'Constant', outputs are .)r'   r3   hasattrrF   rW   r*   cst_convertr4   r   r   r   r   itemsrG   r   r   rU   AttributeErroroutput)r)   r6   r7   attrrV   rK   r#   r#   r$   r3   i   sB   


zConstant_12.__init__c                 K  s|   | j r7|d u rtd| jd| j|vr#td| jdt|d|| j }t|tjr1|fS | |fS | 	| jfS )Nz0Attributes are empty, cannot retrieve value for rX   zCannot find attribute z in )
has_linked_attributer>   r*   rW   listr   r   ndarrayrZ   r+   )r)   r@   r4   r#   r#   r$   rA      s   

zConstant_12._runNrC   r#   r#   r#   r$   rH   h   s    $rH   )
__future__r   numpyr   onnx._custom_element_typesr   r   r   r   r   r   r	   r
   onnx.reference.op_runr   r   r%   r'   r1   rD   rE   rH   r#   r#   r#   r$   <module>   s   (
 