a
    hg                     @   s@  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ejejee ejejeedddZedejdddZdd Zededdddddddd	d!ejejeee ee eej eee ee ee ejd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|rJtj	||	d}
| j
d|
d}t|rpt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'   I/var/www/auris/lib/python3.9/site-packages/torch/onnx/symbolic_opset17.pyr
   &   s&    


r
   zquantized::layer_norm)r   c           
      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bFT)r   r   r-   
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r4|n|d }
| jdtj|
tjdd}| jdtj|tjdd}|}t|}|d	kr| d
|| jdtjdgtjdd}n&|du s|dkrt jd| d|dtj|dd}|durh|r|n|}||ksJ d| df||k rht	||\}}| 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 s8|r<d	ndd}| jd|g dd}|d	kr| d|| jdtjdgtjdd}|rt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.)Z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tensor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>   sZ   "       