o
    ¢ÄiO	  ã                   @   sD   d dl Z ddlmZmZmZmZmZ ddlmZ G dd„ deƒZ	dS )é    Né   )ÚTENSOR_NAME_QUANT_SUFFIXÚQuantizedValueÚQuantizedValueTypeÚattribute_to_kwargÚ	ms_domainé   )ÚQuantOperatorBasec                       s(   e Zd Z‡ fdd„Z‡ fdd„Z‡  ZS )ÚQGlobalAveragePoolc                    s   t ƒ  ||¡ d S )N)ÚsuperÚ__init__)ÚselfZonnx_quantizerZ	onnx_node©Ú	__class__© úe/home/kim/smarthome/.venv/lib/python3.10/site-packages/onnxruntime/quantization/operators/gavgpool.pyr      s   zQGlobalAveragePool.__init__c                    sL  | j }|jdks
J ‚|jd | jjvrtƒ  ¡ S | jj|jd  }| jj|jd  }| j |jd ¡\}}}}}|r<|n|j	}|rC|n|j
}t|jd |jd t ||tjƒ}	|	| jj|jd < i }
|jD ]	}|
 t|ƒ¡ qet|
d< d|
d< |jr|jd nd}tjjd|j |j|j	|j
||g|	jg|fi |
¤Ž}| j j|g7  _d S )NZGlobalAveragePoolr   ÚdomainZchannels_lastZ_quantÚ ZQLinear)ÚnodeZop_typeÚinputZ	quantizerZquantized_value_mapr   ÚquantizeZ_get_quantization_paramsÚoutputZ
scale_nameZzp_namer   r   r   ZInputÚ	attributeÚupdater   r   ÚnameÚonnxÚhelperZ	make_nodeZq_nameZ	new_nodes)r   r   Zquantized_input_valueZ
data_foundZ output_scale_name_from_parameterZoutput_zp_name_from_parameterÚ_Zoutput_scale_nameZoutput_zp_nameZquantized_output_valueÚkwargsr   Z
qnode_nameZqnoder   r   r   r      sV   
úû
ûöõzQGlobalAveragePool.quantize)Ú__name__Ú
__module__Ú__qualname__r   r   Ú__classcell__r   r   r   r   r
      s    r
   )
r   Zquant_utilsr   r   r   r   r   Zbase_operatorr	   r
   r   r   r   r   Ú<module>   s    