
    Vhg                        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	
      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(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'              Zy))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   )opsetzaten::layer_normvisfnoneginputnormalized_shapeweightbiasepscudnn_enablec                    t        |       }t        j                  j                  |t        j                  j                        }|j                         }	t        j                  |      r*t        j                  ||	      }
| j                  d|
      }t        j                  |      r*t        j                  ||	      }| j                  d|      }| j                  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               K/home/dcms/DCMS/lib/python3.12/site-packages/torch/onnx/symbolic_opset17.pyr   r   &   s      !!D++66{((..K E'zz"2%@j,7%[[!1?
ttJ
t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   J   sL     !221a8JAq!Q1.c5IF**1fh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br>   
hop_length
win_lengthwindow
normalizedonesidedreturn_complexalign_to_windowreturnc
                    |rt        j                  d|      |	t        j                  d|      ||n|dz  }
| j                  dt        j                  |
t        j
                              }| j                  dt        j                  |t        j
                              }|}t        j                  |      }|dk(  rI| j                  d	|| j                  dt        j                  d
gt        j
                                    }n"||dkD  rt        j                  d| d|      t        j                  |d
      }||r|n|}||k(  sJ d| df       ||k  rqt        ||      \  }}| j                  dt        j                  |            }| j                  dt        j                  |            }| j                  d|||d
      }t        j                  |      r|r||kD  rt        j                  d| d| d|      t        ||      \  }}t        j                  t        j                  |      t        j                  |      t        j                  |      f      }nt        j                  |      }|j                  d
   |k(  sJ | j                  d|      }| j                  d|t        j                   j#                  |      j%                               }| j                  d||||||rdnd
      }| j                  d|g d      }|dk(  rH| j                  d|| j                  dt        j                  d
gt        j
                                    }|rjt        j&                  t        j                  ||j)                         j+                                     }| j                  d|| j                  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valuez:STFT does not currently support the align_to_window option   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<   rQ      )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   rK   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   d   s   H ''?u
 	
 "''L
 	
 &0%;z!ttELL)9M   ELLekkB  
 F!226:KaDDU\\1#U[[%IDJ

 
	a''))45HJ
 	
 00Q?E+5Z5** 	
KKP'QRT-
 	
* 5=-eU;KD%ttJD0AtBHZU1CDITT(HfiTJF 'E!//00:|>%PZ\  .eZ@KD% <<T"EJJz$:EKK<NOL
 !::e,L!!!$---j,7TT[66AA&ISSU  F
 TT (H1!  F TT+vlT;F aDDU\\1#U[[%IDJ
 JJu||E9L9L9NOP	eVQTT*iT%HIMr2   )NNNFTFN)__doc__	functoolscollections.abcr   typingr   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 9"""<#=#=RH "#CsCf=88 sm HH	
 (( 
  > $D '(OO )O" Cc3S#sCH
 !% $!%#%*&*II88I I 	I
 I RXXI I tnI TNI d^I XXI I Ir2   