o
    闦i                     @   sZ  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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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)	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                 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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_value r/   Y/home/ubuntu/transcripts/venv/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   dequantize_helperr
   quantize_helper)
r   xr   r   r   r   op_scaleop_zero_point_outputr/   r/   r0   r   I   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_fftwindow_sizeleftrightr/   r/   r0   _compute_edge_sizes[   s   r=   z
aten::stftibFTr9   
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u sT|dkr_t jd| d|dtj|d
d}|dur|rn|n|}||ks}J 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r2| d|| jdtjd
gtjdd}|rOt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   r   r   r      	Unsqueezer   r8   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   r8   rJ      )perm_iSqueezeDiv)r   SymbolicValueErrorr)   r'   tensorint64r   _get_tensor_rank_get_tensor_dim_sizer=   r*   r&   hstackr(   shaper   r#   r$   	onnx_typesqrttyper   )r   r   r9   r@   rA   rB   rC   rD   rE   frame_step_valueframe_step_constframe_length_constsignalsignal_rankn_winwin_length_defaultr;   r<   left_win	right_wintorch_windowresult	sqrt_nfftr/   r/   r0   r   c   s   #





r   )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   r=   r   r/   r/   r/   r0   <module>   sx   "	
