o
    wZhg                     @   sn  d Z ddlZddlmZ ddl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	d
Zede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dZeddejfddZdd Zeded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e d+ejfd,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)Sequence)Optional)_C)_type_utilserrorssymbolic_helper)	jit_utilsregistration)
layer_normstftquantized_layer_norm   )Zopsetzaten::layer_normvisfnoneginputnormalized_shapeweightbiasepscudnn_enablec                 C   s   t | }tj|tjj}| }	t|r%tj	||	d}
| j
d|
d}t|r8tj||	d}| j
d|d}| j
d|||||dS )NdtypeConstantZvalue_tZLayerNormalization)Z	epsilon_faxis_i)lenr   JitScalarType
from_valueFLOATr   r   _is_nonetorchonesopzeros)r   r   r   r   r   r   r   ZaxisZscalar_typer   Zweight_valueZ
bias_value r'   J/var/www/auris/lib/python3.10/site-packages/torch/onnx/symbolic_opset17.pyr
   &   s&   


r
   zquantized::layer_normc           
      C   s8   t | |\}}}}t| |||||d}	t | |	||S )NF)r   Zdequantize_helperr
   Zquantize_helper)
r   xr   r   r   r   Zop_scaleZop_zero_point_outputr'   r'   r(   r   J   s   r   c                 C   s    | | d }| | | }||fS )zuHelper function to compute the sizes of the edges (left and right)
    of a given window centered within an FFT size.   r'   )n_fftZwindow_sizeleftrightr'   r'   r(   _compute_edge_sizes\   s   r0   z
aten::stftibFTr-   
hop_length
win_lengthwindow
normalizedonesidedreturn_complexalign_to_windowreturnc
              
   C   s  |r	t jd|d|	durt jd|d|dur|n|d }
| jdtj|
tjdd}| jdtj|tjdd}|}t|}|d	krW| d
|| jdtjdgtjdd}n|du s_|dkrjt jd| d|dtj|dd}|dur|ry|n|}||ksJ d| df||k rt	||\}}| jdt
|d}| jdt
|d}| jd|||dd}t|r|r||krt jd| d| d|dt	||\}}tt
|t|t
|f}nt|}|jd |ksJ | jd|d}| jd|tj| d}| jd|||||du s|rd	ndd}| jd|g dd}|d	kr=| d|| jdtjdgtjdd}|rZttj||  d}| d|| 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valueNz:STFT does not currently support the align_to_window option   r   r   r      Z	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 ()Z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.ZCast)Zto_iZSTFT)Z
onesided_iZ	Transpose)r   r,   r>      )Zperm_iZSqueezeDiv)r   ZSymbolicValueErrorr%   r#   ZtensorZint64r   Z_get_tensor_rankZ_get_tensor_dim_sizer0   r&   r"   Zhstackr$   shaper   r   r    Z	onnx_typesqrttyper   )r   r   r-   r3   r4   r5   r6   r7   r8   r9   Zframe_step_valueZframe_step_constZframe_length_constsignalZsignal_rankZn_winZwin_length_defaultr.   r/   Zleft_winZ	right_winZtorch_windowresultZ	sqrt_nfftr'   r'   r(   r   d   s   $





r   )NNNFTFN)__doc__	functoolscollections.abcr   typingr   r#   r   Z
torch.onnxr   r   r   Ztorch.onnx._internalr   r	   __all__partialZonnx_symbolicZ_onnx_symbolic
parse_argsZGraphContextValueintfloatboolr
   r   r0   r   r'   r'   r'   r(   <module>   s   "	
