o
    toi                     @  s   d dl mZ d dl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)OpRunRefAttrNamec                 C  s0   | j }t|tj std| dt| dd S )NzType (z, z+) is not a numpy type (operator 'Constant'))dtype
isinstancenp	TypeErrortype)valr    r   R/home/ubuntu/.local/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   _check   s   
zConstantCommon._checkN)__name__
__module____qualname__r   r   r   r   r   r          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   r      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   r   zHFunction attributes are not implemented for opset <= 11. Use opset > 12.lenidr   RuntimeErrorr   r   r   overridden_attributesr   r   r   _run       zConstant_1._runNr   r   r   r   r)   r   r   r   r   r      s    r   c                   @  r   )
Constant_9c                 C  s   t | || d S r   )r   r   r   r   r   r   r   -   s   zConstant_9.__init__N)r   r   r   r   r   r   r   r   r,   ,   r   r,   c                   @  r   )Constant_11c                 C  s>   t | || t| dd d u r| j| _n| j| _t| j d S )Nsparse_value)r   r   getattrr   r   r.   r   r   r   r   r   r   2   s
   
zConstant_11.__init__c                 K  r    r!   r#   r'   r   r   r   r)   :   r*   zConstant_11._runNr+   r   r   r   r   r-   1   s    r-   c                   @  r   )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 )Nr.   c                 S     | S r   r   vr   r   r   <lambda>L       z&Constant_12.__init__.<locals>.<lambda>r   c                 S  r1   r   r   r2   r   r   r   r4   P   r5   )value_floatvalue_floats	value_int
value_intsvalue_stringvalue_stringsr   c                 S  s   t j| |dS )Nr<   )r   array)r3   np_dtyper   r   r   r4   `   s    cst_namez<No constant is defined for operator 'Constant', outputs are .)r   r   hasattrr.   r?   r   cst_convertr   r   float32int64str_itemsr/   r   r   r=   AttributeErroroutput)r   r   r   attrr>   r3   r   r   r   r   G   s>   


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 r@   zCannot find attribute z in )
has_linked_attributer&   r   r?   listr   r   ndarrayrB   r   )r   r(   r   r   r   r   r)   i   s   

zConstant_12._runNr+   r   r   r   r   r0   F   s    "r0   )
__future__r   numpyr   onnx.reference.op_runr   r   r   r   r   r,   r-   r0   r   r   r   r   <module>   s   