o
    ii                     @   sL  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mZ ddg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dd Zede
ddddddddej						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'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)	_beartype	jit_utilsregistration
layer_normstft   )Zopsetzaten::layer_normvisfnoneginputnormalized_shapeweightbiasepscudnn_enablec                 C   s    t | }| jd|||||dS )NZLayerNormalization)Z	epsilon_faxis_i)lenop)r   r   r   r   r   r   r   Zaxis r   j/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/torch/onnx/symbolic_opset17.pyr   "   s   
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   r"   z
aten::stftibFTr   
hop_length
win_lengthwindow
normalizedonesidedreturn_complexreturnc	              
   C   s  |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rL| d	|| jdtjd
gtjdd}n|dkr[t jd| d|dtj|d
d}|dur|rj|n|}||ksyJ 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}|rKt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valueN   Constant)dtype)Zvalue_t   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   r1      )Zperm_iZSqueezeDiv)r   ZSymbolicValueErrorr   torchZtensorZint64r   Z_get_tensor_rankZ_get_tensor_dim_sizer"   ZzerosZ_is_noneZhstackZonesshaper   ZJitScalarType
from_valueZ	onnx_typesqrttyper0   )r   r   r   r%   r&   r'   r(   r)   r*   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   $





)NNNFTF)__doc__	functoolstypingr   r   r6   r   Z
torch.onnxr   r   r   Ztorch.onnx._internalr   r	   r
   __all__partialZonnx_symbolicZ_onnx_symbolic
parse_argsZGraphContextValueintfloatboolr   r"   Zbeartyper   r   r   r   r   <module>   sr    	
