o
    öXiC  ć                   @  s   d dl mZ d dlZd dlmZ d dlmZ d dlmZm	Z	 e 
e”ZdZdddZdd Zdd ZdddZeeeeZeeeeZe	eegZdS )é    )ŚannotationsN)Śir)Ś	_ir_utils)ŚRewriteRuleŚRewriteRuleSetl   ’’’’ Śdataśir.ValueŚstartsŚendsŚaxesŚstepsŚreturnŚboolc                 K  sd  ~ |j }|j }|j }	|j }
|du s|du s|	du s|
du r$t d” dS | ” jdkr2t d” dS | ” jdkr@t d” dS |	 ” jdkrNt d” dS |
 ” jdkr\t d” dS |
 ”  ” dkrkt d	” dS | ”  ” d
krzt d” dS | ”  ” tkrdS |jdu s|j |	 ”  ” ”rt d” dS | ”  ” |j|	 ”  ”  k r°t d” dS dS )zyIf the starts is 0, and the ends is equal to or grater than the shape of the specified axis, then the slice is redundant.NzAThe value 'start', 'end', 'axis', 'step' is not statically known.Fé   z"The value 'start' is not a scalar.z The value 'end' is not a scalar.z!The value 'axis' is not a scalar.z!The value 'step' is not a scalar.zThe value 'step' is not 1.r   zThe value 'start' is not 0.Tz/The value 'data' shape is not statically known.z=The value 'end' is less than the shape of the specified axis.)	Śconst_valueŚloggerŚinfoŚnumpyŚsizeŚitemŚ
_INT64_MAXŚshapeŚ
is_dynamic)Ścontextr   r	   r
   r   r   Ś_Śstarts_constŚ
ends_constŚ
axes_constŚsteps_const© r   śe/home/ubuntu/.local/lib/python3.10/site-packages/onnxscript/rewriter/rules/common/_collapse_slices.pyŚ_check_if_redundant_slice   sF   
 








r!   c                 K  s
   |   |”S )z$Return the input data as the output.)ŚIdentity)Śopr   r   r   r   r    Ś_identity_to_itselfF   s   
r$   c                 C  s   | j |||||dgdS )zTo identify a slice opŚslice_output)Ś_outputs)ŚSlice)r#   r   r	   r
   r   r   r   r   r    Ś_potential_redundant_sliceK   s   r(   r%   c                 K  s8   |j du s
|j du rdS t |d”sdS t |j |j ”S )z?Check if the shape of the slice output is the same as the data.NFr   )r   r   Śis_singleton_valueŚ
same_shape)r#   r   r%   r   r   r   r   r    Ś_same_shapeP   s
   r+   )r   r   r	   r   r
   r   r   r   r   r   r   r   )r   r   r%   r   r   r   )Ś
__future__r   ŚloggingŚ
onnxscriptr   Śonnxscript.rewriterr   Ś!onnxscript.rewriter._rewrite_ruler   r   Ś	getLoggerŚ__name__r   r   r!   r$   r(   r+   Ścollapse_slice_ruleŚcollapse_slice2_ruleŚrulesr   r   r   r    Ś<module>   s,   

7
żż	