
    Χg                     |   d Z ddlZddlmZmZ ddlZddlmZ ddlmZm	Z	m
Z
 ddlmZmZ g dZ ej        ej        d	          Z ed
           e
j        dddddd          dej        dej        dee         dej        dej        dedefd                        Z ed          dej        fd            Zd Z ed           e
j        dddddddd          	 	 	 	 	 	 d(dej        dej        ded ee         d!ee         d"eej                 d#ed$ee         d%ee         d&ej        fd'                        ZdS ))a  This file exports ONNX ops for opset 17.

Note [ONNX Operators that are added/updated in opset 17]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
https://github.com/onnx/onnx/blob/main/docs/Changelog.md#version-17-of-the-default-onnx-operator-set
New operators:
    BlackmanWindow
    DFT
    HammingWindow
    HannWindow
    LayerNormalization
    MelWeightMatrix
    STFT
    SequenceMap
    N)OptionalSequence)_C)_type_utilserrorssymbolic_helper)	jit_utilsregistration)
layer_normstftquantized_layer_norm   )opsetzaten::layer_normvisfnoneginputnormalized_shapeweightbiasepscudnn_enablec                    t          |           }t          j                            |t          j        j                  }|                                }	t          j        |          r-t          j	        ||	          }
| 
                    d|
          }t          j        |          r-t          j        ||	          }| 
                    d|          }| 
                    d|||||          S )NdtypeConstantvalue_tLayerNormalization)	epsilon_faxis_i)lenr   JitScalarType
from_valueFLOATr   r   _is_nonetorchonesopzeros)r   r   r   r   r   r   r   axisscalar_typer   weight_value
bias_values               W/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/onnx/symbolic_opset17.pyr   r   %   s      !!!D+66{(. K E'' 8z"2%@@@j,77%% 4[!1???
ttJ
t3344        zquantized::layer_normc           	          t          j        | |          \  }}}}t          | |||||d          }	t          j        | |	||          S )NF)r   dequantize_helperr   quantize_helper)
r   xr   r   r   r   op_scaleop_zero_point_outputs
             r1   r   r   I   sO     !21a88JAq!Q1.c5IIF*1fhNNNr2   c                 *    | |z
  dz  }| |z
  |z
  }||fS )zuHelper function to compute the sizes of the edges (left and right)
    of a given window centered within an FFT size.    )n_fftwindow_sizeleftrights       r1   _compute_edge_sizesrB   [   s+     KA%DDL;&E;r2   z
aten::stftibFTr>   
hop_length
win_lengthwindow
normalizedonesidedreturn_complexreturnc	                    |rt          j        d|          ||n|dz  }	|                     dt          j        |	t          j                            }
|                     dt          j        |t          j                            }|}t          j        |          }|dk    rL|                     d	||                     dt          j        d
gt          j                                      }n"||dk    rt          j        d| d|          t          j        |d
          }||r|n|}||k    sJ d| df            ||k     rt          ||          \  }}|                     dt          j
        |                    }|                     dt          j
        |                    }|                     d|||d
          }t          j        |          r|r||k    rt          j        d| d| d|          t          ||          \  }}t          j        t          j
        |          t          j        |          t          j
        |          f          }nt          j        |          }|j        d
         |k    sJ |                     d|          }|                     d|t          j                            |                                                    }|                     d||
||||rdnd
          }|                     d|g d          }|dk    rK|                     d||                     dt          j        d
gt          j                                      }|rxt          j        t          j        ||                                                                                    }|                     d||                     d|                    }|S )a  Associates `torch.stft` with the `STFT` ONNX operator.
    Note that torch.stft calls _VF.stft, without centering or padding options.
    Hence, this function does not contain these two arguments.
    See torch.stft source code for more info.

    Args:
        g: Graph to write the ONNX representation into
        input: Input tensor for the transformation
        n_fft: FFT size
        hop_length: Size of the hop. Defaults to `floot(n_fft // 4)`
        win_length: Size of the analysis window. Defaults to `n_fft`
        window: Analysis window. Defaults to a window of all ones
        normalized: Whether to return a normalized STFT
        onesided: Whether to return only half (+1) of the results, given the
            symmetry of the STFT
        return_complex: Whether to return the complex value (Note: Must be
            `False` or `None`)

    Returns:
        op: Operator for torch.stft associated with STFT (ONNX)
    z-STFT does not currently support complex types)msgvalueN   r   r   r      	Unsqueezer   r<   zcSTFT can only take inputs of 1 [signal] or 2 [batch, signal] dimensions. Current rank of signal is z, please reduce it.)dimzuAnalysis window size must equal `win_length` or `n_fft`. Please, set `win_length` or `n_fft` to match `window` size ()Concat)r#   zWThe analysis window can't be longer than the size of the FFT. Please set `win_length` (z) to `n_fft` (z
) or less.Cast)to_iSTFT)
onesided_i	Transpose)r   r<   rP      )perm_iSqueezeDiv)r   SymbolicValueErrorr+   r)   tensorint64r   _get_tensor_rank_get_tensor_dim_sizerB   r,   r(   hstackr*   shaper   r%   r&   	onnx_typesqrttyper   )r   r   r>   rE   rF   rG   rH   rI   rJ   frame_step_valueframe_step_constframe_length_constsignalsignal_rankn_winwin_length_defaultr@   rA   left_win	right_wintorch_windowresult	sqrt_nffts                          r1   r   r   c   sl   F  
'?u
 
 
 	

 &0%;zz!ttEL)9MMM    ELekBBB   
 F!26::KaDDU\1#U[%I%I%IDJJ
 

 
	a'J)4J J J
 
 
 	
 0Q???E+5@ZZ5****TKPT T T-
*** 5==-eU;;KD%ttJD0A0AtBBHZU1C1CDDITT(HfiTJJF '' 8 	-E!!/\0:\ \JO\ \ \    .eZ@@KD% <T""EJz$:$:EK<N<NO LL
 !:e,,L!!$----j,77TT[6AA&IISSUU   F
 TT (H(11!   F TT+vlllT;;F aDDU\1#U[%I%I%IDJJ
 
  JJu|E9L9L9N9NOOOPP	eVQTT*iT%H%HIIMr2   )NNNFTF)__doc__	functoolstypingr   r   r)   r   
torch.onnxr   r   r   torch.onnx._internalr	   r
   __all__partialonnx_symbolic_onnx_symbolic
parse_argsGraphContextValueintfloatboolr   r   rB   r   r=   r2   r1   <module>r      s   "     % % % % % % % %        ; ; ; ; ; ; ; ; ; ; 8 8 8 8 8 8 8 8 9
8
8""<#=RHHH "##CsCf==8 sm H	
 ( 
    >= $#D '((OO O O )(O"   Cc3S#sCC
 !% $!%#%*B BB8B B 	B
 B RXB B tnB TNB XB B B DC B B Br2   