
    `iw                     :   d Z ddlZddlZddl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 g dZd Zd#d
Zd$dZ ej        ddd          Zd%dZ	 d&dZd Z ej        ddd          Zd Z	 d'dZ e	j        e	j        j                  d(d            Z e	j        e	j        j                  d(d            Z e	j        e	j        j                  d(d            Z e	j        e	j        j                  d(d            Zd%dZd Z e	j        e	j        j                   d)d            Z  e	j        e	j        j!                  d)d             Z! e	j        e	j        j"                  d)d!            Z" e	j        e	j        j#                  d)d"            Z#dS )*u  Real-to-real transforms

cuFFT does not implement real-to-real FFTs. This module implements forward
and inverse DCT-II and DCT-III transforms using FFTs.

A length N DCT can be computed using a length N FFT and some additional
multiplications and reordering of entries.

The approach taken here is based on the work in [1]_, [2]_ and is discussed in
the freely-available online resources [3]_, [4]_.

The implementation here follows that approach with only minor modification to
match the normalization conventions in SciPy.

The modifications to turn a type II or III DCT to a DST were implemented as
described in [5]_.

.. [1] J. Makhoul, "A fast cosine transform in one and two dimensions," in
    IEEE Transactions on Acoustics, Speech, and Signal Processing, vol. 28,
    no. 1, pp. 27-34, February 1980.

.. [2] M.J. Narasimha and A.M. Peterson, “On the computation of the discrete
    cosine  transform,” IEEE Trans. Commun., vol. 26, no. 6, pp. 934–936, 1978.

.. [3] http://fourier.eng.hmc.edu/e161/lectures/dct/node2.html

.. [4] https://dsp.stackexchange.com/questions/2807/fast-cosine-transform-via-fft

.. [5] X. Shao, S. G. Johnson. Type-II/III DCT/DST algorithms with reduced
    number of arithmetic operations, Signal Processing, Volume 88, Issue 6,
    pp. 1553-1564, 2008.
    N)_core)_cook_shape)_fft)	AxisError)dctdctndstdstnidctidctnidstidstnc                     | j         j        dv rt          j        }n$t          j        | j         t          j                  }|                     |d          S )NbuiF)copy)dtypekindcupyfloat64promote_typesfloat32astype)xfloat_dtypes     s/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupyx/scipy/fft/_realtransforms.py_promote_dtyper   /   sF    w|ul($,??88Ke8,,,       c                     |dk    rdS |dk    rdnd}d| |z   z  }|dk    rd|z  }n-|dk    rdt          j        |          z  }nt          d          |S )	a]  Normalization factors for DCT/DST I-IV.

    Parameters
    ----------
    n : int
        Data size.
    inorm : {'none', 'sqrt', 'full'}
        When `inorm` is 'none', the scaling factor is 1.0 (unnormalized). When
        `inorm` is 1, scaling by ``1/sqrt(d)`` as needed for an orthogonal
        transform is used. When `inorm` is 2, normalization by ``1/d`` is
        applied. The value of ``d`` depends on both `n` and the `dct_type`.
    dct_type : {1, 2, 3, 4}
        Which type of DCT or DST is being normalized?.

    Returns
    -------
    fct : float
        The normalization factor.
    none   r   r   fullsqrtz)expected inorm = "none", "sqrt" or "full")mathr$   
ValueError)ninormdct_typedeltadfcts         r   _get_dct_norm_factorr-   8   su    ( qa--BBQE	QYA!e	&$)A,,DEEEJr   Fc                    t          d          g| j        z  }t          ddd          ||<   t          |          }t          d          g| j        z  }|dz  r$t          ddd          ||<   t          |          }n#t          ddd          ||<   t          |          }|r&t          j        | |         | |          f|          } n$t          j        | |         | |         f|          } | S );Reorder entries to allow computation of DCT/DST-II via FFT.Nr   r   )axis)slicendimtupler   concatenate)r   r'   r1   r	   sl_evensl_odds         r   _reshuffle_dct2r8   Y   s    T{{maf$G!T1%%GDMGnnGDkk]QV#F1u Rr**tvT4,,tv
 Aaj1V9*5DAAAaj!F)44@@@Hr   zR xr, int32 N, R norm_factorzC yzS
    C j(0., -1.);
    y = (R)2.0 * norm_factor * exp(j * (R)(i * M_PI / (2 * N)));)	in_params
out_params	operationc                     ||}t          j        |f| j                  }t          |j        |||           | j        dk    r|S dg| j        z  }|||<   t          |          }|                    |          S )z@Twiddle & scaling factors for computation of DCT/DST-II via FFT.Nr   r!   )r   emptyr   _mult_factor_dct2realr3   r4   reshape)r   r'   r1   norm_factor
n_truncatetmp	tmp_shapes          r   _exp_factor_dct2rF   u   s    

*j]!'
2
2
2Cch;444v{{
afI IdOi  I;;y!!!r   r"   Tc                 P   || j          k     s|| j         k    rt          d          |dk     r
|| j         z  }||dk     rt          d| d          t          | |f|fd          } | j        |         }t          | | j        |         ||          } |dk    rd	}n|d
k    r|rdnd}n|rdnd}t          ||d          }t          j        | ||d          } t          | |||          }	| |	z  } t          j        |           } |dk    r\t          d          g| j         z  }
t          d          |
|<   | t          |
          xx         t          j        d          dz  z  cc<   |rAt          d          g| j         z  }t          ddd          ||<   | t          |                   } | S )a  Forward DCT/DST-II (or inverse DCT/DST-III) along a single axis

    Parameters
    ----------
    x : cupy.ndarray
        The data to transform.
    n : int
        The size of the transform. If None, ``x.shape[axis]`` is used.
    axis : int
        Axis along which the transform is applied.
    forward : bool
        Set true to indicate that this is a forward DCT-II as opposed to an
        inverse DCT-III (The difference between the two is only in the
        normalization factor).
    norm : {None, 'ortho', 'forward', 'backward'}
        The normalization convention to use.
    dst : bool
        If True, a discrete sine transform is computed rather than the discrete
        cosine transform.
    overwrite_x : bool
        Indicates that it is okay to overwrite x. In practice, the current
        implementation never performs the transform in-place.

    Returns
    -------
    y: cupy.ndarray
        The transformed array.
    axis out of ranger   Nr!   invalid number of data points () specifiedR2Rorthor$   forwardr#   r    r   r(   r)   Tr'   r1   overwrite_x      ?r"   )r3   r   r&   r   shaper8   r-   r   fftrF   r   r@   r2   r4   r%   r$   )r   r'   r1   rM   normr	   rP   r(   rB   rD   sl0slrevs               r   _dct_or_dst_type2rW      s   > qvg~~+,,,axx}Q<a<<<
 
 	
 	AtdWe,,A	A174=$44Aw			!-v!-v&qBBBKad555A
1a{
3
3CHA	!AwT{{maf$!HHD		%**1++
 t&D$++deEllOHr   c                 F   t          j        |           }|dz   dz  }t          d          g| j        z  }t          ddd          ||<   t	          |          }t          d          g| j        z  }t          d|          ||<   | t	          |                   ||<   t          d          g| j        z  }t          ddd          ||<   t	          |          }t          d|dz
  d          ||<   |r| t	          |                    ||<   n| t	          |                   ||<   |S )r/   r!   r   Nr   r"   )r   
empty_liker2   r3   r4   )	yr'   r1   r	   r   n_halfr6   sl_halfr7   s	            r   _reshuffle_dct3r]      s   A!e\F T{{maf$G!T1%%GDMGnnGT{{maf$G!V$$GDM5>>"AgJ Dkk]QV#FD!$$F4L6]]F"fqj"--GDM
 &uW~~&&&		eGnn%&	Hr   zV
    C j(0., 1.);
    y = (R)(2 * N * norm_factor) * exp(j * (R)(i * M_PI / (2 * N)));c                     t          j        |f|          }t          |j        |||           | j        dk    r|S dg| j        z  }|||<   t          |          }|                    |          S )zATwiddle & scaling factors for computation of DCT/DST-III via FFT.r=   r!   )r   r>   _mult_factor_dct3r@   r3   r4   rA   )r   r'   r1   r   rB   rD   rE   s          r   _exp_factor_dct3r`      ss    
*aT
'
'
'Cch;444v{{
afIIdOi  I;;y!!!r   c                    || j          k     s|| j         k    rt          d          |dk     r
|| j         z  }||dk     rt          d| d          t          | |f|fd          } | j        |         }|dk    rd	t          j        d
          z  }d}n3|dk    r	d	}|rdnd}n$|dk    s|	d	}|rdnd}nt          d| d          t          ||d          }	t          j	        | t          j
                  }
t          d          g| j         z  }t          d          ||<   |rt          d          g| j         z  }t          ddd          ||<   | t          |                   } |dk    rt          j	        | j        t          j                  }| j        |k    r|                     |          } n|s|                                 } | t          |          xx         t          j        d
          z  cc<   d	}t#          | |||
|	          }| |z  } | t          |          xx         |z  cc<   t%          j        | ||d          } t          j        |           } t+          | |||          S )a  Forward DCT/DST-III (or inverse DCT/DST-II) along a single axis.

    Parameters
    ----------
    x : cupy.ndarray
        The data to transform.
    n : int
        The size of the transform. If None, ``x.shape[axis]`` is used.
    axis : int
        Axis along which the transform is applied.
    forward : bool
        Set true to indicate that this is a forward DCT-II as opposed to an
        inverse DCT-III (The difference between the two is only in the
        normalization factor).
    norm : {None, 'ortho', 'forward', 'backward'}
        The normalization convention to use.
    dst : bool
        If True, a discrete sine transform is computed rather than the discrete
        cosine transform.
    overwrite_x : bool
        Indicates that it is okay to overwrite x. In practice, the current
        implementation never performs the transform in-place.

    Returns
    -------
    y: cupy.ndarray
        The transformed array.

    rH   r   Nr!   rI   rJ   rK   rL   rQ   r   r$   rM   r#   r    backwardzInvalid norm value "z-", should be "backward", "ortho" or "forward"   rN   r"   TrO   )r3   r   r&   r   rR   r%   r$   r-   r   r   	complex64r2   r4   r   r   r   r   r`   r   ifftr@   r]   )r   r'   r1   rT   rM   r	   rP   	sl0_scaler(   rB   r   rU   rV   r   rD   s                  r   _dct_or_dst_type3rg      s   @ qvg~~+,,,axx}Q<a<<<
 
 	
 	AtdWe,,A	A w$)A,,&					!-v			t|	!-v 0 0 0 0 1 1 	1&qBBBKq$.11E;;-!&
 CaCI
 t&D$++deEllO7??,QWdlCCKw+%%HH[))  FFHHeCjjMMMTYq\\)MMMI 1auk
:
:C	CAeCjjMMMYMMM 		!qt666A	!A 1as+++r   c           
      d   | j         j        dk    r:t          | j        |||||          }|dt          | j        |||||          z  z   }|S t          |           } |dk    rt          | |||dd          S |dk    rt          | |||dd          S |dv rt          d	          t          d
          )a  Return the Discrete Cosine Transform of an array, x.

    Parameters
    ----------
    x : cupy.ndarray
        The input array.
    type : {1, 2, 3, 4}, optional
        Type of the DCT (see Notes). Default type is 2. Currently CuPy only
        supports types 2 and 3.
    n : int, optional:
        Length of the transform.  If ``n < x.shape[axis]``, `x` is
        truncated. If ``n > x.shape[axis]``, `x` is zero-padded.
        The default results in ``n = x.shape[axis]``.
    axis : int, optional
        Axis along which the dct is computed; the default is over the
        last axis (i.e., ``axis=-1``).
    norm : {"backward", "ortho", "forward"}, optional
        Normalization mode (see Notes). Default is "backward".
    overwrite_x : bool, optional
        If True, the contents of `x` can be destroyed; the default is False.

    Returns
    -------
    y : cupy.ndarray of real
        The transformed input array.

    See Also
    --------
    :func:`scipy.fft.dct`

    Notes
    -----
    For a single dimension array ``x``, ``dct(x, norm='ortho')`` is equal
    to MATLAB ``dct(x)``.

    For ``norm="ortho"`` both the `dct` and `idct` are scaled by the same
    overall factor in both directions. By default, the transform is also
    orthogonalized which for types 1, 2 and 3 means the transform definition is
    modified to give orthogonality of the DCT matrix (see below).

    For ``norm="backward"``, there is no scaling on `dct` and the `idct` is
    scaled by ``1/N`` where ``N`` is the "logical" size of the DCT. For
    ``norm="forward"`` the ``1/N`` normalization is applied to the forward
    `dct` instead and the `idct` is unnormalized.

    CuPy currently only supports DCT types 2 and 3. 'The' DCT generally
    refers to DCT type 2, and 'the' Inverse DCT generally refers to DCT
    type 3 [1]_. See the :func:`scipy.fft.dct` documentation for a full
    description of each type.

    References
    ----------
    .. [1] Wikipedia, "Discrete cosine transform",
           https://en.wikipedia.org/wiki/Discrete_cosine_transform

    c              ?r   TFr'   r1   rT   rM   r	   rc   r!      .Only DCT-II and DCT-III have been implemented.invalid DCT type)
r   r   r   r@   imagr   rW   rg   NotImplementedErrorr&   r   typer'   r1   rT   rP   outs          r   r   r   U  s    t 	w|s!&$4{;;BQVT1dD+FFFF
qAqyy D$E
 
 
 	
 
 D$E
 
 
 	
 
!<
 
 	
 +,,,r   c           
      d   | j         j        dk    r:t          | j        |||||          }|dt          | j        |||||          z  z   }|S t          |           } |dk    rt          | |||dd          S |dk    rt          | |||dd          S |dv rt          d          t          d	          )
a  Return the Discrete Sine Transform of an array, x.

    Parameters
    ----------
    x : cupy.ndarray
        The input array.
    type : {1, 2, 3, 4}, optional
        Type of the DST (see Notes). Default type is 2.
    n : int, optional
        Length of the transform.  If ``n < x.shape[axis]``, `x` is
        truncated.  If ``n > x.shape[axis]``, `x` is zero-padded. The
        default results in ``n = x.shape[axis]``.
    axis : int, optional
        Axis along which the dst is computed; the default is over the
        last axis (i.e., ``axis=-1``).
    norm : {"backward", "ortho", "forward"}, optional
        Normalization mode (see Notes). Default is "backward".
    overwrite_x : bool, optional
        If True, the contents of `x` can be destroyed; the default is False.

    Returns
    -------
    dst : cupy.ndarray of real
        The transformed input array.

    See Also
    --------
    :func:`scipy.fft.dst`

    Notes
    -----

    For ``norm="ortho"`` both the `dst` and `idst` are scaled by the same
    overall factor in both directions. By default, the transform is also
    orthogonalized which for types 2 and 3 means the transform definition is
    modified to give orthogonality of the DST matrix (see below).

    For ``norm="backward"``, there is no scaling on the `dst` and the `idst` is
    scaled by ``1/N`` where ``N`` is the "logical" size of the DST.

    See the :func:`scipy.fft.dst` documentation for a full description of each
    type. CuPy currently only supports DST types 2 and 3.
    ri   rj   r   Trk   rc   rl   .Only DST-II and DST-III have been implemented.invalid DST type)
r   r   r	   r@   rp   r   rW   rg   rq   r&   rr   s          r   r	   r	     s    Z 	w|s!&$4{;;BQVT1dD+FFFF
qAqyy D$D
 
 
 	
 
 D$D
 
 
 	
 
!<
 
 	
 +,,,r   c           
      `   | j         j        dk    r:t          | j        |||||          }|dt          | j        |||||          z  z   }|S t          |           } |dk    rt          | |||d          S |dk    rt          | |||d          S |dv rt          d          t          d	          )
a  Return the Inverse Discrete Cosine Transform of an array, x.

    Parameters
    ----------
    x : cupy.ndarray
        The input array.
    type : {1, 2, 3, 4}, optional
        Type of the DCT (see Notes). Default type is 2.
    n : int, optional
        Length of the transform.  If ``n < x.shape[axis]``, `x` is
        truncated.  If ``n > x.shape[axis]``, `x` is zero-padded. The
        default results in ``n = x.shape[axis]``.
    axis : int, optional
        Axis along which the idct is computed; the default is over the
        last axis (i.e., ``axis=-1``).
    norm : {"backward", "ortho", "forward"}, optional
        Normalization mode (see Notes). Default is "backward".
    overwrite_x : bool, optional
        If True, the contents of `x` can be destroyed; the default is False.

    Returns
    -------
    idct : cupy.ndarray of real
        The transformed input array.

    See Also
    --------
    :func:`scipy.fft.idct`

    Notes
    -----
    For a single dimension array `x`, ``idct(x, norm='ortho')`` is equal to
    MATLAB ``idct(x)``.

    For ``norm="ortho"`` both the `dct` and `idct` are scaled by the same
    overall factor in both directions. By default, the transform is also
    orthogonalized which for types 1, 2 and 3 means the transform definition is
    modified to give orthogonality of the IDCT matrix (see `dct` for the full
    definitions).

    'The' IDCT is the IDCT-II, which is the same as the normalized DCT-III
    [1]_. See the :func:`scipy.fft.dct` documentation for a full description of
    each type. CuPy currently only supports DCT types 2 and 3.

    References
    ----------
    .. [1] Wikipedia, "Discrete sine transform",
           https://en.wikipedia.org/wiki/Discrete_sine_transform
    ri   rj   r   F)r'   r1   rT   rM   rc   rl   rn   ro   )
r   r   r   r@   rp   r   rg   rW   rq   r&   rr   s          r   r   r     s    f 	w|s164D$<<BafdAtT;GGGG
qAqyy aduMMMM	 aduMMMM	!<
 
 	
 +,,,r   c           
      d   | j         j        dk    r:t          | j        |||||          }|dt          | j        |||||          z  z   }|S t          |           } |dk    rt          | |||dd          S |dk    rt          | |||dd          S |dv rt          d	          t          d
          )a>  Return the Inverse Discrete Sine Transform of an array, x.

    Parameters
    ----------
    x : cupy.ndarray
        The input array.
    type : {1, 2, 3, 4}, optional
        Type of the DST (see Notes). Default type is 2.
    n : int, optional
        Length of the transform. If ``n < x.shape[axis]``, `x` is
        truncated.  If ``n > x.shape[axis]``, `x` is zero-padded. The
        default results in ``n = x.shape[axis]``.
    axis : int, optional
        Axis along which the idst is computed; the default is over the
        last axis (i.e., ``axis=-1``).
    norm : {"backward", "ortho", "forward"}, optional
        Normalization mode (see Notes). Default is "backward".
    overwrite_x : bool, optional
        If True, the contents of `x` can be destroyed; the default is False.

    Returns
    -------
    idst : cupy.ndarray of real
        The transformed input array.

    See Also
    --------
    :func:`scipy.fft.idst`

    Notes
    -----
    For full details of the DST types and normalization modes, as well as
    references, see :func:`scipy.fft.dst`.
    ri   rj   r   FTrk   rc   rl   rv   rw   )
r   r   r   r@   rp   r   rg   rW   rq   r&   rr   s          r   r   r   5  s    H 	w|s164D$<<BafdAtT;GGGG
qAqyy D%T
 
 
 	
 
 D%T
 
 
 	
 
!<
 
 	
 +,,,r   c                     t          | t          j                  r| f} 	 d | D             } n)# t          $ r}|pd}t	          | d          |d}~ww xY w| S )z-Convert ``x`` to an iterable sequence of int.c                 6    g | ]}t          j        |          S  )operatorindex).0as     r   
<listcomp>z$_iterable_of_int.<locals>.<listcomp>y  s"    ***1X^A***r   valuez) must be a scalar or iterable of integersN)
isinstancenumbersNumber	TypeErrorr&   )r   namees      r   _iterable_of_intr   s  s    !W^$$ D*****   w>>>
 
	 Hs   , 
AAAc                 B    |du }|du }|st          |d          } fd|D             }t           fd|D                       rt          d          t          t	          |                    t          |          k    rt          d          |st          |d          }t          |          }|r"t          |          |k    rt          d          |rD| j        k    rt          d	          t           j        t          |          z
   j                  } fd
t          ||          D             }n9|r)t           j	                  }t           j                  }n fd|D             }t          d |D                       rt          d| d          ||fS )z3Handles shape and axes arguments for nd transforms.Naxesc                 4    g | ]}|d k     r
|j         z   n|S )r   r3   r   r   r   s     r   r   z+_init_nd_shape_and_axes.<locals>.<listcomp>  s+    999qa!eeAF

999r   c              3   :   K   | ]}|j         k    p|d k     V  dS )r   Nr   r   s     r   	<genexpr>z*_init_nd_shape_and_axes.<locals>.<genexpr>  s2      22qAF{#a!e222222r   z$axes exceeds dimensionality of inputzall axes must be uniquerR   zBwhen given, axes and shape arguments have to be of the same lengthz)shape requires more axes than are presentc                 @    g | ]\  }}|d k    rj         |         n|S )r"   rR   )r   sr   r   s      r   r   z+_init_nd_shape_and_axes.<locals>.<listcomp>  s/    KKK$!QqBwwAKKKr   c                 *    g | ]}j         |         S r|   r   r   s     r   r   z+_init_nd_shape_and_axes.<locals>.<listcomp>  s    ******r   c              3   "   K   | ]
}|d k     V  dS )r!   Nr|   )r   r   s     r   r   z*_init_nd_shape_and_axes.<locals>.<genexpr>  s&      
 
 Q1q5
 
 
 
 
 
 r   rI   rJ   )
r   anyr&   lensetr3   rangeziplistrR   )r   rR   r   noshapenoaxesnshapes   `     r   _init_nd_shape_and_axesr     s   tmGT\F 8f--9999D9992222T22222 	ECDDDs4yy>>SYY&&6777 + 00U 	CII''1    	6 !LMMM#e**,af55DKKKK#eT:J:JKKK	 +QWQV}}****T***

 
 %
 
 
    
@e@@@
 
 	
 $;r   c           
      `   | j         j        dk    r:t          | j        |||||          }|dt          | j        |||||          z  z   }|S t          | ||          \  }}t          |           } t          |          dk    r| S t          ||          D ]\  }}	t          | |||	||          } | S )a  Compute a multidimensional Discrete Cosine Transform.

    Parameters
    ----------
    x : cupy.ndarray
        The input array.
    type : {1, 2, 3, 4}, optional
        Type of the DCT (see Notes). Default type is 2.
    s : int or array_like of ints or None, optional
        The shape of the result. If both `s` and `axes` (see below) are None,
        `s` is ``x.shape``; if `s` is None but `axes` is not None, then `s` is
        ``numpy.take(x.shape, axes, axis=0)``.
        If ``s[i] > x.shape[i]``, the ith dimension is padded with zeros.
        If ``s[i] < x.shape[i]``, the ith dimension is truncated to length
        ``s[i]``.
        If any element of `s` is -1, the size of the corresponding dimension of
        `x` is used.
    axes : int or array_like of ints or None, optional
        Axes over which the DCT is computed. If not given, the last ``len(s)``
        axes are used, or all axes if `s` is also not specified.
    norm : {"backward", "ortho", "forward"}, optional
        Normalization mode (see Notes). Default is "backward".
    overwrite_x : bool, optional
        If True, the contents of `x` can be destroyed; the default is False.

    Returns
    -------
    y : cupy.ndarray of real
        The transformed input array.

    See Also
    --------
    :func:`scipy.fft.dctn`

    Notes
    -----
    For full details of the DCT types and normalization modes, as well as
    references, see `dct`.
    ri   rj   r   rs   r'   r1   rT   rP   )
r   r   r   r@   rp   r   r   r   r   r   
r   rs   r   r   rT   rP   rt   rR   r'   r1   s
             r   r   r         R 	w|s164D$<<BafdAtT;GGGG
)!Q55KE4qA
4yyA~~ud## 
 
4DADt
 
 
 Hr   c           
      `   | j         j        dk    r:t          | j        |||||          }|dt          | j        |||||          z  z   }|S t          | ||          \  }}t          |           } t          |          dk    r| S t          ||          D ]\  }}	t          | |||	||          } | S )a  Compute a multidimensional Discrete Cosine Transform.

    Parameters
    ----------
    x : cupy.ndarray
        The input array.
    type : {1, 2, 3, 4}, optional
        Type of the DCT (see Notes). Default type is 2.
    s : int or array_like of ints or None, optional
        The shape of the result. If both `s` and `axes` (see below) are None,
        `s` is ``x.shape``; if `s` is None but `axes` is not None, then `s` is
        ``numpy.take(x.shape, axes, axis=0)``.
        If ``s[i] > x.shape[i]``, the ith dimension is padded with zeros.
        If ``s[i] < x.shape[i]``, the ith dimension is truncated to length
        ``s[i]``.
        If any element of `s` is -1, the size of the corresponding dimension of
        `x` is used.
    axes : int or array_like of ints or None, optional
        Axes over which the IDCT is computed. If not given, the last ``len(s)``
        axes are used, or all axes if `s` is also not specified.
    norm : {"backward", "ortho", "forward"}, optional
        Normalization mode (see Notes). Default is "backward".
    overwrite_x : bool, optional
        If True, the contents of `x` can be destroyed; the default is False.

    Returns
    -------
    y : cupy.ndarray of real
        The transformed input array.

    See Also
    --------
    :func:`scipy.fft.idctn`

    Notes
    -----
    For full details of the IDCT types and normalization modes, as well as
    references, see :func:`scipy.fft.idct`.
    ri   rj   r   r   )
r   r   r   r@   rp   r   r   r   r   r   r   s
             r   r   r         R 	w|sAFD!T4==BqvtQdKHHHH
)!Q55KE4qA
4yyA~~ud## 
 
4DADt
 
 
 Hr   c           
      `   | j         j        dk    r:t          | j        |||||          }|dt          | j        |||||          z  z   }|S t          | ||          \  }}t          |           } t          |          dk    r| S t          ||          D ]\  }}	t          | |||	||          } | S )a  Compute a multidimensional Discrete Sine Transform.

    Parameters
    ----------
    x : cupy.ndarray
        The input array.
    type : {1, 2, 3, 4}, optional
        Type of the DST (see Notes). Default type is 2.
    s : int or array_like of ints or None, optional
        The shape of the result. If both `s` and `axes` (see below) are None,
        `s` is ``x.shape``; if `s` is None but `axes` is not None, then `s` is
        ``numpy.take(x.shape, axes, axis=0)``.
        If ``s[i] > x.shape[i]``, the ith dimension is padded with zeros.
        If ``s[i] < x.shape[i]``, the ith dimension is truncated to length
        ``s[i]``.
        If any element of `s` is -1, the size of the corresponding dimension of
        `x` is used.
    axes : int or array_like of ints or None, optional
        Axes over which the DST is computed. If not given, the last ``len(s)``
        axes are used, or all axes if `s` is also not specified.
    norm : {"backward", "ortho", "forward"}, optional
        Normalization mode (see Notes). Default is "backward".
    overwrite_x : bool, optional
        If True, the contents of `x` can be destroyed; the default is False.

    Returns
    -------
    y : cupy.ndarray of real
        The transformed input array.

    See Also
    --------
    :func:`scipy.fft.dstn`

    Notes
    -----
    For full details of the DST types and normalization modes, as well as
    references, see :func:`scipy.fft.dst`.
    ri   rj   r   r   )
r   r   r
   r@   rp   r   r   r   r   r	   r   s
             r   r
   r
   %  r   r   c           
      `   | j         j        dk    r:t          | j        |||||          }|dt          | j        |||||          z  z   }|S t          | ||          \  }}t          |           } t          |          dk    r| S t          ||          D ]\  }}	t          | |||	||          } | S )a  Compute a multidimensional Discrete Sine Transform.

    Parameters
    ----------
    x : cupy.ndarray
        The input array.
    type : {1, 2, 3, 4}, optional
        Type of the DST (see Notes). Default type is 2.
    s : int or array_like of ints or None, optional
        The shape of the result. If both `s` and `axes` (see below) are None,
        `s` is ``x.shape``; if `s` is None but `axes` is not None, then `s` is
        ``numpy.take(x.shape, axes, axis=0)``.
        If ``s[i] > x.shape[i]``, the ith dimension is padded with zeros.
        If ``s[i] < x.shape[i]``, the ith dimension is truncated to length
        ``s[i]``.
        If any element of `s` is -1, the size of the corresponding dimension of
        `x` is used.
    axes : int or array_like of ints or None, optional
        Axes over which the IDST is computed. If not given, the last ``len(s)``
        axes are used, or all axes if `s` is also not specified.
    norm : {"backward", "ortho", "forward"}, optional
        Normalization mode (see Notes). Default is "backward".
    overwrite_x : bool, optional
        If True, the contents of `x` can be destroyed; the default is False.

    Returns
    -------
    y : cupy.ndarray of real
        The transformed input array.

    See Also
    --------
    :func:`scipy.fft.idstn`

    Notes
    -----
    For full details of the IDST types and normalization modes, as well as
    references, see :func:`scipy.fft.idst`.
    ri   rj   r   r   )
r   r   r   r@   rp   r   r   r   r   r   r   s
             r   r   r   a  r   r   )r   )F)N)Nr"   TNFF)Nr"   NTFF)r   Nr"   NF)r   NNNF)$__doc__r%   r   r}   r   r   cupy.fft._fftr   cupyx.scipy.fftr   cupy.exceptionsr   __all__r   r-   r8   ElementwiseKernelr?   rF   rW   r]   r_   r`   rg   _implements
_scipy_fftr   r	   r   r   r   r   r   r   r
   r   r|   r   r   <module>r      s\   B           % % % % % %             % % % % % %
J
J
J- - -   B   & ,E+,D   " " " "  IND D D DN  6 ,E+,H   
" 
" 
" INV, V, V, V,r $/%&&N- N- N- '&N-b $/%&&A- A- A- '&A-H $/&''E- E- E- ('E-P $/&'':- :- :- (':-z    ' ' 'T $/&''8 8 8 ('8v $/'((8 8 8 )(8v $/&''8 8 8 ('8v $/'((8 8 8 )(8 8 8r   