o
    ?ei%                     @   sB  d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ dd ZedejdejdfddZedejdejdfddZedejejdfddZedejdejdfddZedejdejdfdd Zd!d" ZdS )#z*Ops for computing common window functions.    N)constant_op)dtypes)ops)tensor_util)	array_ops)cond)math_ops)nn_ops)special_math_ops)dispatch)	tf_exportc                 C   s2   |j s	td| tj| tjd} | jd | S )aR  Check window_length and dtype params.

  Args:
    window_length: A scalar value or `Tensor`.
    dtype: The data type to produce. Must be a floating point type.

  Returns:
    window_length converted to a tensor of type int32.

  Raises:
    ValueError: If `dtype` is not a floating point type or window_length is not
      a scalar.
  -dtype must be a floating point type. Found %sdtyper   )is_floating
ValueErrorr   convert_to_tensorr   int32shapeassert_has_rank)window_lengthr    r   h/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/ops/signal/window_ops.py_check_params    s
   r   zsignal.kaiser_windowg      (@c           
      C   s  t |d| t| |} t| }|dkr$tjdg|dW  d   S tj| t	j
dd d }tj| |d t	j
d}tj||d}tj||d}tjd|d}tj||d}|tt|t||   }t|| t|t|  }	W d   |	S 1 sw   Y  |	S )a  Generate a [Kaiser window][kaiser].

  Args:
    window_length: A scalar `Tensor` indicating the window length to generate.
    beta: Beta parameter for Kaiser window, see reference below.
    dtype: The data type to produce. Must be a floating point type.
    name: An optional name for the operation.

  Returns:
    A `Tensor` of shape `[window_length]` of type `dtype`.

  [kaiser]:
    https://docs.scipy.org/doc/numpy/reference/generated/numpy.kaiser.html
  kaiser_window   r   Ng      ?       @g?)r   
name_scoper   r   constant_valuer   onesr   castr   float32rangesqrtr	   ZreluZsquareexpr
   Z
bessel_i0e)
r   betar   namewindow_length_constZhalflen_floatargonenumwindowr   r   r   r   5   s2   



r   z#signal.kaiser_bessel_derived_windowc           	      C   s   t |d; t| |} | d }t|d ||d}t|}t|dd |d  }tj||ddd fdd}W d   |S 1 sDw   Y  |S )	a  Generate a [Kaiser Bessel derived window][kbd].

  Args:
    window_length: A scalar `Tensor` indicating the window length to generate.
    beta: Beta parameter for Kaiser window.
    dtype: The data type to produce. Must be a floating point type.
    name: An optional name for the operation.

  Returns:
    A `Tensor` of shape `[window_length]` of type `dtype`.

  [kbd]:
    https://en.wikipedia.org/wiki/Kaiser_window#Kaiser%E2%80%93Bessel-derived_(KBD)_window
  kaiser_bessel_derived_window   r   r   Nr   )Zaxis)	r   r   r   r   r   Zcumsumr#   r   concat)	r   r%   r   r&   ZhalflenZkaiserwZkaiserw_csumZhalfwr+   r   r   r   r,   \   s   


r,   zsignal.vorbis_windowc                 C   s   t |d5 t| |} tjt| |d}ttjd t	ttjtj| |d |d  d }W d   |S 1 s>w   Y  |S )a  Generate a [Vorbis power complementary window][vorbis].

  Args:
    window_length: A scalar `Tensor` indicating the window length to generate.
    dtype: The data type to produce. Must be a floating point type.
    name: An optional name for the operation.

  Returns:
    A `Tensor` of shape `[window_length]` of type `dtype`.

  [vorbis]:
    https://en.wikipedia.org/wiki/Modified_discrete_cosine_transform#Window_functions
  vorbis_windowr   r         ?N)
r   r   r   r   r    r"   sinnppipow)r   r   r&   r(   r+   r   r   r   r0   x   s   


r0   zsignal.hann_windowTc                 C   s   t |d| ||ddS )a  Generate a [Hann window][hann].

  Args:
    window_length: A scalar `Tensor` indicating the window length to generate.
    periodic: A bool `Tensor` indicating whether to generate a periodic or
      symmetric window. Periodic windows are typically used for spectral
      analysis while symmetric windows are typically used for digital
      filter design.
    dtype: The data type to produce. Must be a floating point type.
    name: An optional name for the operation.

  Returns:
    A `Tensor` of shape `[window_length]` of type `dtype`.

  Raises:
    ValueError: If `dtype` is not a floating point type.

  [hann]: https://en.wikipedia.org/wiki/Window_function#Hann_and_Hamming_windows
  hann_windowr1   _raised_cosine_windowr   periodicr   r&   r   r   r   r6      s   
r6   zsignal.hamming_windowc                 C   s   t |d| ||ddS )a  Generate a [Hamming][hamming] window.

  Args:
    window_length: A scalar `Tensor` indicating the window length to generate.
    periodic: A bool `Tensor` indicating whether to generate a periodic or
      symmetric window. Periodic windows are typically used for spectral
      analysis while symmetric windows are typically used for digital
      filter design.
    dtype: The data type to produce. Must be a floating point type.
    name: An optional name for the operation.

  Returns:
    A `Tensor` of shape `[window_length]` of type `dtype`.

  Raises:
    ValueError: If `dtype` is not a floating point type.

  [hamming]:
    https://en.wikipedia.org/wiki/Window_function#Hann_and_Hamming_windows
  hamming_windowgHzG?gq=
ףp?r7   r9   r   r   r   r;      s   
r;   c              	      sv  j s	td t| ||g tjtjddjd t	
}|dkr:tjdgdW  d   S ttj|tjddtj}|jd dtd	 }tj||  d d}	tt}
tjd	tj d|
 |	 |durtj t  dW  d   S ttdfd
d fddW  d   S 1 sw   Y  dS )a  Helper function for computing a raised cosine window.

  Args:
    name: Name to use for the scope.
    default_name: Default name to use for the scope.
    window_length: A scalar `Tensor` or integer indicating the window length.
    periodic: A bool `Tensor` indicating whether to generate a periodic or
      symmetric window.
    dtype: A floating point `DType`.
    a: The alpha parameter to the raised cosine window.
    b: The beta parameter to the raised cosine window.

  Returns:
    A `Tensor` of shape `[window_length]` of type `dtype`.

  Raises:
    ValueError: If `dtype` is not a floating point type or `window_length` is
      not scalar or `periodic` is not scalar.
  r   r   )r   r&   r   r   r   Nr:   r-   c                      s   t jg dS Nr   )r   r   r   )r   r   r   r   <lambda>   s    z'_raised_cosine_window.<locals>.<lambda>c                      s   t j t   dS r<   )r   r    cosr   )abcos_argr   r   r   r=      s    )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    boolmodr"   r   Zconstantr3   r4   r>   r   equal)r&   default_namer   r:   r   r?   r@   r'   Zevenncountr   )r?   r@   rA   r   r   r   r8      s:   


$r8   )__doc__numpyr3   Ztensorflow.python.frameworkr   r   r   r   Ztensorflow.python.opsr   r   r   r	   r
   Ztensorflow.python.utilr   Z tensorflow.python.util.tf_exportr   r   Zadd_dispatch_supportr!   r   r,   r0   r6   r;   r8   r   r   r   r   <module>   sD   %