
    AVh_(                        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 Z edddg      ej,                  dd              ZddZ edddg      ej,                  dd              Zy)zDiscrete Cosine Transform ops.    N)dtypes)ops)
smart_cond)tensor_shape)	array_ops)math_ops)fft_ops)dispatch)	tf_exportc                    |dk7  rt        d|z        ||dk  rt        d      |dvrt        d      |dk(  r<|dk(  rt        d	      | j                  d   | j                  d   d
k  rt        d      |dvrt        d|z        y)z>Checks that DCT/IDCT arguments are compatible and well formed.zaxis must be -1. Got: %sN   z&n should be a positive integer or Noner            z-Types I, II, III and IV (I)DCT are supported.orthoz2Normalization is not supported for the Type-I DCT.r   z9Type-I DCT requires the dimension to be greater than one.)Nr   z8Unknown normalization. Expected None or 'ortho', got: %s)NotImplementedError
ValueErrorshape)input_tensordct_typenaxisnorms        T/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/ops/signal/dct_ops.py_validate_dct_argumentsr      s    	RZ
84?
@@]q1u
=
>>\!
D
EE]wKLL")l.@.@.Dq.H
EG G 
 
BTIK K !    z
signal.dctzspectral.dct)v1c                 @    t        | ||||       t        | |||||      S )aE  Computes the 1D [Discrete Cosine Transform (DCT)][dct] of `input`.

  Types I, II, III and IV are supported.
  Type I is implemented using a length `2N` padded `tf.signal.rfft`.
  Type II is implemented using a length `2N` padded `tf.signal.rfft`, as
   described here: [Type 2 DCT using 2N FFT padded (Makhoul)]
   (https://dsp.stackexchange.com/a/10606).
  Type III is a fairly straightforward inverse of Type II
   (i.e. using a length `2N` padded `tf.signal.irfft`).
   Type IV is calculated through 2N length DCT2 of padded signal and
  picking the odd indices.

  @compatibility(scipy)
  Equivalent to [scipy.fftpack.dct]
   (https://docs.scipy.org/doc/scipy-1.4.0/reference/generated/scipy.fftpack.dct.html)
   for Type-I, Type-II, Type-III and Type-IV DCT.
  @end_compatibility

  Args:
    input: A `[..., samples]` `float32`/`float64` `Tensor` containing the
      signals to take the DCT of.
    type: The DCT type to perform. Must be 1, 2, 3 or 4.
    n: The length of the transform. If length is less than sequence length,
      only the first n elements of the sequence are considered for the DCT.
      If n is greater than the sequence length, zeros are padded and then
      the DCT is computed as usual.
    axis: For future expansion. The axis to compute the DCT along. Must be `-1`.
    norm: The normalization to apply. `None` for no normalization or `'ortho'`
      for orthonormal normalization.
    name: An optional name for the operation.

  Returns:
    A `[..., samples]` `float32`/`float64` `Tensor` containing the DCT of
    `input`.

  Raises:
    ValueError: If `type` is not `1`, `2`, `3` or `4`, `axis` is
      not `-1`, `n` is not `None` or greater than 0,
      or `norm` is not `None` or `'ortho'`.
    ValueError: If `type` is `1` and `norm` is `ortho`.

  [dct]: https://en.wikipedia.org/wiki/Discrete_cosine_transform
  r   _dct_internal)inputtyper   r   r   names         r   dctr&   2   s*    \ %q$5	udAtT4	88r   c           
      "    t        j                  |d g      5  t        j                          t        j                  d j                        }t	        j
                   j                  d         xs t        j                         d   ' fd} fd}t        j                  k  ||       t	        j
                   j                  d         xs t        j                         d   }	t        j                  |	 j                        }
|dk(  rTt        j                    d	d
ddf   gd      }t        j                  t        j                  |            }|cddd       S |dk(  rdt        j                  t        j                   |t        j"                  |
       t$        j&                  z  dz  |
z              z  }t        j                  t        j                   d|	z  g      d	d|	f   |z        }|dk(  rgdt        j(                  |
      z  }|t%        j*                  d      z  }t        j,                  t        j.                  |d      d|	dz
  gg|      }||z  }|cddd       S |dk(  r|dk(  ret        j*                  |
      }|t%        j*                  d      z  }t        j,                  t        j.                  |d      d|	dz
  gg|      } |z   n |
z   dt        j                  t        j                   |t        j"                  |
      t$        j&                  z  dz  |
z              z  }t        j                  t        j0                  |t        j                    |      z  d|	z  g            d	d|	f   }|cddd       S |dk(  r[t3         dd|	z  |d      }|d	dddf   }|dk(  r.|t%        j*                  d      t        j(                  |
      z  z  }|cddd       S 	 ddd       y# 1 sw Y   yxY w)a  Computes the 1D Discrete Cosine Transform (DCT) of `input`.

  This internal version of `dct` does not perform any validation and accepts a
  dynamic value for `n` in the form of a rank 0 tensor.

  Args:
    input: A `[..., samples]` `float32`/`float64` `Tensor` containing the
      signals to take the DCT of.
    type: The DCT type to perform. Must be 1, 2, 3 or 4.
    n: The length of the transform. If length is less than sequence length,
      only the first n elements of the sequence are considered for the DCT.
      If n is greater than the sequence length, zeros are padded and then
      the DCT is computed as usual. Can be an int or rank 0 tensor.
    axis: For future expansion. The axis to compute the DCT along. Must be `-1`.
    norm: The normalization to apply. `None` for no normalization or `'ortho'`
      for orthonormal normalization.
    name: An optional name for the operation.

  Returns:
    A `[..., samples]` `float32`/`float64` `Tensor` containing the DCT of
    `input`.
  r&   g        dtyper   Nc                       ddf   S )N.r    )r#   r   s   r   truncate_inputz%_dct_internal.<locals>.truncate_input   s    S!A#Xr   c                      t        j                        } t        |       D cg c]  }ddg }}z
  || dz
     d<   t        j                  |t
        j                        }t        j                  |      S c c}w )Nr   r   r(   )paddings)	lenr   range_opsconvert_to_tensor_dtypesint32
_array_opspad)rank_paddingr#   r   seq_lens      r   	pad_inputz _dct_internal.<locals>.pad_input   so    5;;#(;/aAq6// 7{q!((F~~eg66 0s   A;r   .r   )r   r   g       @g      ?)
fft_lengthr   )constant_valuesr   r   )r$   r   r   r   )r1   
name_scoper2   r)   r   dimension_valuer   r5   r   	_math_opscastconcatrealr	   rfftexpcomplexr0   _mathpirsqrtsqrtr6   expand_dimsirfftr"   )r#   r$   r   r   r   r%   zeror,   r;   axis_dimaxis_dim_float
dct1_inputdct1scaledct2n1n2weightsdct3dct4r:   s   ` `                 @r   r"   r"   d   s   . tUUG, U""5)E!!#U[[9D 	$$U[[_5 	$#  	}7 ##AL.)Le,,U[[_= /##E*2. ^^Hekk:Nqy$$eU31R<-@%AKj^^GLL45d9U U< qyIMM


Y__^44uxx?#E e ^^
,,X003YhY@BGHId 
9??>22%**S/!..""2q)Q1,=+>  	gU Uj 
	^^N+%**S/!..""2q)Q1,=+>  	IMM


oon-83> e
 ^^
--i''t44h,)* +.yy.:d
 UU UX 
5qAhJTMd #qt!t)_d	

3)//."AAAkU UX 
YU U Us!   EP-DP9DPAPPzsignal.idctzspectral.idctc                 V    t        | ||||       ddddd|   }t        | |||||      S )a  Computes the 1D [Inverse Discrete Cosine Transform (DCT)][idct] of `input`.

  Currently Types I, II, III, IV are supported. Type III is the inverse of
  Type II, and vice versa.

  Note that you must re-normalize by 1/(2n) to obtain an inverse if `norm` is
  not `'ortho'`. That is:
  `signal == idct(dct(signal)) * 0.5 / signal.shape[-1]`.
  When `norm='ortho'`, we have:
  `signal == idct(dct(signal, norm='ortho'), norm='ortho')`.

  @compatibility(scipy)
  Equivalent to [scipy.fftpack.idct]
   (https://docs.scipy.org/doc/scipy-1.4.0/reference/generated/scipy.fftpack.idct.html)
   for Type-I, Type-II, Type-III and Type-IV DCT.
  @end_compatibility

  Args:
    input: A `[..., samples]` `float32`/`float64` `Tensor` containing the
      signals to take the DCT of.
    type: The IDCT type to perform. Must be 1, 2, 3 or 4.
    n: For future expansion. The length of the transform. Must be `None`.
    axis: For future expansion. The axis to compute the DCT along. Must be `-1`.
    norm: The normalization to apply. `None` for no normalization or `'ortho'`
      for orthonormal normalization.
    name: An optional name for the operation.

  Returns:
    A `[..., samples]` `float32`/`float64` `Tensor` containing the IDCT of
    `input`.

  Raises:
    ValueError: If `type` is not `1`, `2` or `3`, `n` is not `None, `axis` is
      not `-1`, or `norm` is not `None` or `'ortho'`.

  [idct]:
  https://en.wikipedia.org/wiki/Discrete_cosine_transform#Inverse_transforms
  r   r   r   r   r   )r$   r   r   r   r%   r!   )r#   r$   r   r   r   r%   inverse_types          r   idctr\      sD    R %q$51q)$/,	,!$T
F Fr   )r   Nr   NN)__doc__mathrH   tensorflow.python.frameworkr   r3   r   r1   r   r   tensorflow.python.opsr   r5   r   rA   tensorflow.python.ops.signalr	   tensorflow.python.utilr
    tensorflow.python.util.tf_exportr   r   add_dispatch_supportr&   r"   r\   r+   r   r   <module>re      s    %  9 3 2 4 9 7 0 + 6K* <\>:;	-9  <-9`l` =m_=>	*F  ?*Fr   