
    Vpfcw                       d dl mZ d dlm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 d dlmZmZmZ d d	lmZ d d
lmZmZ d dlmZmZ ee         Zd?dZd@dZ	 	 	 dAdBdZ	 	 	 dAdBdZ eej         j!                  	 	 	 dAdBd            Z! eej         j"                  	 	 	 dAdBd            Z"dCd"Z#dDd$Z$	 	 dEdFd'Z 	 	 dEdFd(Z%	 	 dEdFd)Z&	 	 dEdFd*Z' eej         j(                  	 	 dEdFd+            Z( eej         j)                  	 	 dEdFd,            Z)dGd.Z*	 	 dHdId0Z+	 	 dHdId1Z, eej         j-                  	 	 dHdId2            Z- eej         j.                  	 	 dHdId3            Z. eej         j/        d45          dJdd7dKd9            Z/ eej         j0        d45          dJdd7dKd:            Z0 eej         j1                  dLdMd=            Z1 eej         j2                  dLdMd>            Z2dS )N    )annotations)SequenceN)dtypes)lax)
xla_client)safe_zip)check_arraylike
implementspromote_dtypes_inexact)	lax_numpy)ufuncs
reductions)Array	ArrayLikesr   	func_namestrnormreturnc                   |dk    rt          j        d          S t          |           \  } |dk    rd|                    d          r&t	          j        t          j        |                     n(dt	          j        t          j        |                     z  S |dk    r@|                    d          rt          j        |           ndt          j        |           z  S t          d| d          )Nbackward   orthoiforwardzInvalid norm value z,; should be "backward","ortho" or "forward".)	jnparrayr   
startswithr   sqrtr   prod
ValueError)r   r   r   s      R/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/_src/numpy/fft.py	_fft_normr#       s    	Z9Q<< a  "!	W__.7.B.B3.G.Gn6;zq))***Qv{[e[jkl[m[mOnOnMnny!*!5!5c!:!:T:?1*/RSBTBT@TT , , , , 	- 	- -    fft_typexla_client.FftTypear   Shape | NoneaxesSequence[int] | None
str | Nonec                   d|  }t          ||           t          j        |          |]t          t	          t
          j        |                    }t          j        t          j	        |d                    rt          d          |1|/t          |          t          |          k    rt          d          |}|A|t          j                  }n*t          j        t          |          z
  j                  }t          |          t          t          |                    k    rt          | d| d          t          |          dk    rt          |d|d	j        d          |Mt          t          j        t          |          z
  j                            }t          j        ||          |t!          j                  }t%          ||          D ]
\  }	}
|
||	<   |t&          j        j        k    r|d
         dz  dz   |d
<   t          t	          t,          |                             t          j        d t1          |j                  D                       ng|t&          j        j        k    rDfd|d d
         D             }|r+|t3          ddj        |d
                  dz
  z            gz  }nfd|D             }t5          j        |t          |                    }|-|t9          t          j        ||j                  | |          z  }|t          j        |||          }|S )Njax.numpy.fft.r   zShape should be non-negative.z&Shape and axes have different lengths.z* does not support repeated axes. Got axes .   z- only supports 1D, 2D, and 3D FFTs. Got axes z with input rank    r   c                "    g | ]\  }}d ||z
  fS )r    ).0xys      r"   
<listcomp>z_fft_core.<locals>.<listcomp>^   s$    BBBTQAaCBBBr$   c                *    g | ]}j         |         S r3   shaper4   axisarrs     r"   r7   z_fft_core.<locals>.<listcomp>a   s    
1
1
1t39T?
1
1
1r$   c                *    g | ]}j         |         S r3   r9   r;   s     r"   r7   z_fft_core.<locals>.<listcomp>e   s    
,
,
,t39T?
,
,
,r$   dtype)r	   r   asarraytuplemapoperatorindexnpanylessr!   lenrangendimsetmoveaxislistr:   r   r   FftTypeIRFFTslicepadzipmaxr   fftr#   r   r@   )r   r%   r'   r   r)   r   	full_name	orig_axesin_sr<   r5   transformedr=   s               @r"   	_fft_corerZ   /   sH    +y**))QA#]c(.!$$%%A	vbgamm 86777]t'CFFc$ii,?,?
=
>
>>)	\y38__dd38c!ff$ch//dYY#c$ii..  
GGGGGI I I 	YY]]
-6YY			3888	MN N N
 sx#d))+SX6677D
,sIt
,
,C]	??DD!$$  ad4jj:%+++r(a-!#d2h
eCt$$%%
&C
'#BBSsy-A-ABBB
C
CCC:%+++
1
1
1
1tCRCy
1
1
1a	 5	c!Q#)DH-123344
,
,
,
,t
,
,
,aXuQxx00+	9	!;,---y$@ @ @K ,{D)<<K	r$   c                H    t          dt          j        j        | |||          S )a@
  Compute a multidimensional discrete Fourier transform along given axes.

  JAX implementation of :func:`numpy.fft.fftn`.

  Args:
    a: input array
    s: sequence of integers. Specifies the shape of the result. If not specified,
      it will default to the shape of ``a`` along the specified ``axes``.
    axes: sequence of integers, default=None. Specifies the axes along which the
      transform is computed.
    norm: string. The normalization mode. "backward", "ortho" and "forward" are
      supported.

  Returns:
    An array containing the multidimensional discrete Fourier transform of ``a``.

  See also:
    - :func:`jax.numpy.fft.fft`: Computes a one-dimensional discrete Fourier
      transform.
    - :func:`jax.numpy.fft.ifft`: Computes a one-dimensional inverse discrete
      Fourier transform.
    - :func:`jax.numpy.fft.ifftn`: Computes a multidimensional inverse discrete
      Fourier transform.

  Examples:
    ``jnp.fft.fftn`` computes the transform along all the axes by default when
    ``axes`` argument is ``None``.

    >>> x = jnp.array([[1, 2, 5, 6],
    ...                [4, 1, 3, 7],
    ...                [5, 9, 2, 1]])
    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   jnp.fft.fftn(x)
    Array([[ 46.  +0.j  ,   0.  +2.j  ,  -6.  +0.j  ,   0.  -2.j  ],
           [ -2.  +1.73j,   6.12+6.73j,   0.  -1.73j, -18.12-3.27j],
           [ -2.  -1.73j, -18.12+3.27j,   0.  +1.73j,   6.12-6.73j]],      dtype=complex64)

    When ``s=[2]``, dimension of the transform along ``axis -1`` will be ``2``
    and dimension along other axes will be the same as that of input.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jax.numpy.fft.fftn(x, s=[2]))
    [[ 3.+0.j -1.+0.j]
     [ 5.+0.j  3.+0.j]
     [14.+0.j -4.+0.j]]

    When ``s=[2]`` and ``axes=[0]``, dimension of the transform along ``axis 0``
    will be ``2`` and dimension along other axes will be same as that of input.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jax.numpy.fft.fftn(x, s=[2], axes=[0]))
    [[ 5.+0.j  3.+0.j  8.+0.j 13.+0.j]
     [-3.+0.j  1.+0.j  2.+0.j -1.+0.j]]

    When ``s=[2, 3]``, shape of the transform will be ``(2, 3)``.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jax.numpy.fft.fftn(x, s=[2, 3]))
    [[16. +0.j   -0.5+4.33j -0.5-4.33j]
     [ 0. +0.j   -4.5+0.87j -4.5-0.87j]]

    ``jnp.fft.ifftn`` can be used to reconstruct ``x`` from the result of
    ``jnp.fft.fftn``.

    >>> x_fftn = jnp.fft.fftn(x)
    >>> jnp.allclose(x, jnp.fft.ifftn(x_fftn))
    Array(True, dtype=bool)
  fftn)rZ   r   rO   FFTr'   r   r)   r   s       r"   r\   r\   p   s#    N 
6:-11at	D	DDr$   c                H    t          dt          j        j        | |||          S )a	  Compute a multidimensional inverse discrete Fourier transform.

  JAX implementation of :func:`numpy.fft.ifftn`.

  Args:
    a: input array
    s: sequence of integers. Specifies the shape of the result. If not specified,
      it will default to the shape of ``a`` along the specified ``axes``.
    axes: sequence of integers, default=None. Specifies the axes along which the
      transform is computed. If None, computes the transform along all the axes.
    norm: string. The normalization mode. "backward", "ortho" and "forward" are
      supported.

  Returns:
    An array containing the multidimensional inverse discrete Fourier transform
    of ``a``.

  See also:
    - :func:`jax.numpy.fft.fftn`: Computes a multidimensional discrete Fourier
      transform.
    - :func:`jax.numpy.fft.fft`: Computes a one-dimensional discrete Fourier
      transform.
    - :func:`jax.numpy.fft.ifft`: Computes a one-dimensional inverse discrete
      Fourier transform.

  Examples:
    ``jnp.fft.ifftn`` computes the transform along all the axes by default when
    ``axes`` argument is ``None``.

    >>> x = jnp.array([[1, 2, 5, 3],
    ...                [4, 1, 2, 6],
    ...                [5, 3, 2, 1]])
    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jnp.fft.ifftn(x))
    [[ 2.92+0.j    0.08-0.33j  0.25+0.j    0.08+0.33j]
     [-0.08+0.14j -0.04-0.03j  0.  -0.29j -1.05-0.11j]
     [-0.08-0.14j -1.05+0.11j  0.  +0.29j -0.04+0.03j]]

    When ``s=[3]``, dimension of the transform along ``axis -1`` will be ``3``
    and dimension along other axes will be the same as that of input.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jnp.fft.ifftn(x, s=[3]))
    [[ 2.67+0.j   -0.83-0.87j -0.83+0.87j]
     [ 2.33+0.j    0.83-0.29j  0.83+0.29j]
     [ 3.33+0.j    0.83+0.29j  0.83-0.29j]]

    When ``s=[2]`` and ``axes=[0]``, dimension of the transform along ``axis 0``
    will be ``2`` and dimension along other axes will be same as that of input.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jnp.fft.ifftn(x, s=[2], axes=[0]))
    [[ 2.5+0.j  1.5+0.j  3.5+0.j  4.5+0.j]
     [-1.5+0.j  0.5+0.j  1.5+0.j -1.5+0.j]]

    When ``s=[2, 3]``, shape of the transform will be ``(2, 3)``.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jnp.fft.ifftn(x, s=[2, 3]))
    [[ 2.5 +0.j    0.  -0.58j  0.  +0.58j]
     [ 0.17+0.j   -0.83-0.29j -0.83+0.29j]]
  ifftn)rZ   r   rO   IFFTr^   s       r"   r`   r`      s#    B 
7J.3Q4	F	FFr$   c                H    t          dt          j        j        | |||          S )Nrfftn)rZ   r   rO   RFFTr^   s       r"   rc   rc      s"     
7J.3Q4	F	FFr$   c                H    t          dt          j        j        | |||          S )Nirfftn)rZ   r   rO   rP   r^   s       r"   rf   rf     s"     
8Z/5q!T4	H	HHr$   r<   
int | Nonec                x    d|  }t          |t          t          f          rt          |d|d|d          d S )Nr-   z, does not support multiple axes. Please use zn. Got axis = r.   )
isinstancerN   rB   r!   )r   r<   rV   s      r"   _axis_check_1drj     sY    *y**)tUm$$ 
%IIyyy$$$	8   r$   nc                f    t          | |           |d n|g}|d n|g}t          | |||||          S N)rj   rZ   )r   r%   r'   rk   r<   r   r)   r   s           r"   _fft_core_1drn     sJ     D!!!D6$iddaS!	9h1dD	9	99r$   r0   intc                J    t          dt          j        j        | |||          S )a  Compute a one-dimensional discrete Fourier transform along a given axis.

  JAX implementation of :func:`numpy.fft.fft`.

  Args:
    a: input array
    n: int. Specifies the dimension of the result along ``axis``. If not specified,
      it will default to the dimension of ``a`` along ``axis``.
    axis: int, default=-1. Specifies the axis along which the transform is computed.
      If not specified, the transform is computed along axis -1.
    norm: string. The normalization mode. "backward", "ortho" and "forward" are
      supported.

  Returns:
    An array containing the one-dimensional discrete Fourier transform of ``a``.

  See also:
    - :func:`jax.numpy.fft.ifft`: Computes a one-dimensional inverse discrete
      Fourier transform.
    - :func:`jax.numpy.fft.fftn`: Computes a multidimensional discrete Fourier
      transform.
    - :func:`jax.numpy.fft.ifftn`: Computes a multidimensional inverse discrete
      Fourier transform.

  Examples:
    ``jnp.fft.fft`` computes the transform along ``axis -1`` by default.

    >>> x = jnp.array([[1, 2, 4, 7],
    ...                [5, 3, 1, 9]])
    >>> jnp.fft.fft(x)
    Array([[14.+0.j, -3.+5.j, -4.+0.j, -3.-5.j],
           [18.+0.j,  4.+6.j, -6.+0.j,  4.-6.j]], dtype=complex64)

    When ``n=3``, dimension of the transform along axis -1 will be ``3`` and
    dimension along other axes will be the same as that of input.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jnp.fft.fft(x, n=3))
    [[ 7.+0.j   -2.+1.73j -2.-1.73j]
     [ 9.+0.j    3.-1.73j  3.+1.73j]]

    When ``n=3`` and ``axis=0``, dimension of the transform along ``axis 0`` will
    be ``3`` and dimension along other axes will be same as that of input.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jnp.fft.fft(x, n=3, axis=0))
    [[ 6. +0.j    5. +0.j    5. +0.j   16. +0.j  ]
     [-1.5-4.33j  0.5-2.6j   3.5-0.87j  2.5-7.79j]
     [-1.5+4.33j  0.5+2.6j   3.5+0.87j  2.5+7.79j]]

    ``jnp.fft.ifft`` can be used to reconstruct ``x`` from the result of
    ``jnp.fft.fft``.

    >>> x_fft = jnp.fft.fft(x)
    >>> jnp.allclose(x, jnp.fft.ifft(x_fft))
    Array(True, dtype=bool)
  rU   rk   r<   r   )rn   r   rO   r]   r'   rk   r<   r   s       r"   rU   rU     s/    v 
eZ/3Q!$
! 
! 
! !r$   c                J    t          dt          j        j        | |||          S )a&  Compute a one-dimensional inverse discrete Fourier transform.

  JAX implementation of :func:`numpy.fft.ifft`.

  Args:
    a: input array
    n: int. Specifies the dimension of the result along ``axis``. If not specified,
      it will default to the dimension of ``a`` along ``axis``.
    axis: int, default=-1. Specifies the axis along which the transform is computed.
      If not specified, the transform is computed along axis -1.
    norm: string. The normalization mode. "backward", "ortho" and "forward" are
      supported.

  Returns:
    An array containing the one-dimensional discrete Fourier transform of ``a``.

  See also:
    - :func:`jax.numpy.fft.fft`: Computes a one-dimensional discrete Fourier
      transform.
    - :func:`jax.numpy.fft.fftn`: Computes a multidimensional discrete Fourier
      transform.
    - :func:`jax.numpy.fft.ifftn`: Computes a multidimensional inverse of discrete
      Fourier transform.

  Examples:
    ``jnp.fft.ifft`` computes the transform along ``axis -1`` by default.

    >>> x = jnp.array([[3, 1, 4, 6],
    ...                [2, 5, 7, 1]])
    >>> jnp.fft.ifft(x)
    Array([[ 3.5 +0.j  , -0.25-1.25j,  0.  +0.j  , -0.25+1.25j],
          [ 3.75+0.j  , -1.25+1.j  ,  0.75+0.j  , -1.25-1.j  ]],      dtype=complex64)

    When ``n=5``, dimension of the transform along axis -1 will be ``5`` and
    dimension along other axes will be the same as that of input.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jnp.fft.ifft(x, n=5))
    [[ 2.8 +0.j   -0.96-0.04j  1.06+0.5j   1.06-0.5j  -0.96+0.04j]
     [ 3.  +0.j   -0.59+1.66j  0.09-0.55j  0.09+0.55j -0.59-1.66j]]

    When ``n=3`` and ``axis=0``, dimension of the transform along ``axis 0`` will
    be ``3`` and dimension along other axes will be same as that of input.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   print(jnp.fft.ifft(x, n=3, axis=0))
    [[ 1.67+0.j    2.  +0.j    3.67+0.j    2.33+0.j  ]
     [ 0.67+0.58j -0.5 +1.44j  0.17+2.02j  1.83+0.29j]
     [ 0.67-0.58j -0.5 -1.44j  0.17-2.02j  1.83-0.29j]]
  ifftrq   )rn   r   rO   ra   rr   s       r"   rt   rt   \  s/    h 
fj05qAD
! 
! 
! !r$   c                J    t          dt          j        j        | |||          S )a&	  Compute a one-dimensional discrete Fourier transform of a real-valued array.

  JAX implementation of :func:`numpy.fft.rfft`.

  Args:
    a: real-valued input array.
    n: int. Specifies the effective dimension of the input along ``axis``. If not
      specified, it will default to the dimension of input along ``axis``.
    axis: int, default=-1. Specifies the axis along which the transform is computed.
      If not specified, the transform is computed along axis -1.
    norm: string. The normalization mode. "backward", "ortho" and "forward" are
      supported.

  Returns:
    An array containing the one-dimensional discrete Fourier transform of ``a``.
    The dimension of the array along ``axis`` is ``(n/2)+1``, if ``n`` is even and
    ``(n+1)/2``, if ``n`` is odd.

  See also:
    - :func:`jax.numpy.fft.fft`: Computes a one-dimensional discrete Fourier
      transform.
    - :func:`jax.numpy.fft.irfft`: Computes a one-dimensional inverse discrete
      Fourier transform for real input.
    - :func:`jax.numpy.fft.rfftn`: Computes a multidimensional discrete Fourier
      transform for real input.
    - :func:`jax.numpy.fft.irfftn`: Computes a multidimensional inverse discrete
      Fourier transform for real input.

  Examples:
    ``jnp.fft.rfft`` computes the transform along ``axis -1`` by default.

    >>> x = jnp.array([[1, 3, 5],
    ...                [2, 4, 6]])
    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   jnp.fft.rfft(x)
    Array([[ 9.+0.j  , -3.+1.73j],
           [12.+0.j  , -3.+1.73j]], dtype=complex64)

    When ``n=5``, dimension of the transform along axis -1 will be ``(5+1)/2 =3``
    and dimension along other axes will be the same as that of input.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   jnp.fft.rfft(x, n=5)
    Array([[ 9.  +0.j  , -2.12-5.79j,  0.12+2.99j],
           [12.  +0.j  , -1.62-7.33j,  0.62+3.36j]], dtype=complex64)

    When ``n=4`` and ``axis=0``, dimension of the transform along ``axis 0`` will
    be ``(4/2)+1 =3`` and dimension along other axes will be same as that of input.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   jnp.fft.rfft(x, n=4, axis=0)
    Array([[ 3.+0.j,  7.+0.j, 11.+0.j],
           [ 1.-2.j,  3.-4.j,  5.-6.j],
           [-1.+0.j, -1.+0.j, -1.+0.j]], dtype=complex64)
  rfftrq   )rn   r   rO   rd   rr   s       r"   rv   rv     s/    r 
fj05qAD
! 
! 
! !r$   c                J    t          dt          j        j        | |||          S )a  Compute a one-dimensional inverse discrete Fourier transform for real input.

  JAX implementation of :func:`numpy.fft.irfft`.

  Args:
    a: real-valued input array.
    n: int. Specifies the dimension of the result along ``axis``. If not specified,
      ``n = 2*(m-1)``, where ``m`` is the dimension of ``a`` along ``axis``.
    axis: int, default=-1. Specifies the axis along which the transform is computed.
      If not specified, the transform is computed along axis -1.
    norm: string. The normalization mode. "backward", "ortho" and "forward" are
      supported.

  Returns:
    An array containing the one-dimensional inverse discrete Fourier transform
    of ``a``, with a dimension of ``n`` along ``axis``.

  See also:
    - :func:`jax.numpy.fft.ifft`: Computes a one-dimensional inverse discrete
      Fourier transform.
    - :func:`jax.numpy.fft.irfft`: Computes a one-dimensional inverse discrete
      Fourier transform for real input.
    - :func:`jax.numpy.fft.rfftn`: Computes a multidimensional discrete Fourier
      transform for real input.
    - :func:`jax.numpy.fft.irfftn`: Computes a multidimensional inverse discrete
      Fourier transform for real input.

  Examples:
    ``jnp.fft.rfft`` computes the transform along ``axis -1`` by default.

    >>> x = jnp.array([[1, 3, 5],
    ...                [2, 4, 6]])
    >>> jnp.fft.irfft(x)
    Array([[ 3., -1.,  0., -1.],
           [ 4., -1.,  0., -1.]], dtype=float32)

    When ``n=3``, dimension of the transform along axis -1 will be ``3`` and
    dimension along other axes will be the same as that of input.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   jnp.fft.irfft(x, n=3)
    Array([[ 2.33, -0.67, -0.67],
           [ 3.33, -0.67, -0.67]], dtype=float32)

    When ``n=4`` and ``axis=0``, dimension of the transform along ``axis 0`` will
    be ``4`` and dimension along other axes will be same as that of input.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   jnp.fft.irfft(x, n=4, axis=0)
    Array([[ 1.25,  2.75,  4.25],
           [ 0.25,  0.75,  1.25],
           [-0.75, -1.25, -1.75],
           [ 0.25,  0.75,  1.25]], dtype=float32)
  irfftrq   )rn   r   rO   rP   rr   s       r"   rx   rx     s/    p 
gz17ad
! 
! 
! !r$   c                    t          j        |           }t          d|           ||j        |         dz
  dz  n|}t	          dt
          j        j        ||||          |z  S )Nhfftr   r1   rq   )r   conjrj   r:   rn   r   rO   rP   )r'   rk   r<   r   conj_anns         r"   rz   rz     sr     ;q>>&'(yTQ!##a"	fj06!$
! 
! 
!#%
& &r$   c                    t          d|           t          j        |           }||j        |         n|}t	          dt
          j        j        ||||          }t          j	        |          d|z  z  S )Nihfftrq   r   )
rj   r   rA   r:   rn   r   rO   rd   r   r{   )r'   rk   r<   r   r=   r}   outputs          r"   r   r     st     $A#)sy"!3!8#!# # #&	V		B	''r$   Sequence[int]c                    d|  }t          |          dk    rt          |d|d          t          | |||||          S )Nr-   r1   z" only supports 2 axes. Got axes = r.   )rI   r!   rZ   )r   r%   r'   r   r)   r   rV   s          r"   _fft_core_2dr      s^     +y**)YY!^^
99ddd	   
9h1dD	9	99r$   r0   c                J    t          dt          j        j        | |||          S )a
  Compute a two-dimensional discrete Fourier transform along given axes.

  JAX implementation of :func:`numpy.fft.fft2`.

  Args:
    a: input array. Must have ``a.ndim >= 2``.
    s: optional length-2 sequence of integers. Specifies the size of the output
      along each specified axis. If not specified, it will default to the size
      of ``a`` along the specified ``axes``.
    axes: optional length-2 sequence of integers, default=(-2,-1). Specifies the
      axes along which the transform is computed.
    norm: string, default="backward". The normalization mode. "backward", "ortho"
      and "forward" are supported.

  Returns:
    An array containing the two-dimensional discrete Fourier transform of ``a``
    along given ``axes``.

  See also:
    - :func:`jax.numpy.fft.fft`: Computes a one-dimensional discrete Fourier
      transform.
    - :func:`jax.numpy.fft.fftn`: Computes a multidimensional discrete Fourier
      transform.
    - :func:`jax.numpy.fft.ifft2`: Computes a two-dimensional inverse discrete
      Fourier transform.

  Examples:
    ``jnp.fft.fft2`` computes the transform along the last two axes by default.

    >>> x = jnp.array([[[1, 3],
    ...                 [2, 4]],
    ...                [[5, 7],
    ...                 [6, 8]]])
    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   jnp.fft.fft2(x)
    Array([[[10.+0.j, -4.+0.j],
            [-2.+0.j,  0.+0.j]],
    <BLANKLINE>
           [[26.+0.j, -4.+0.j],
            [-2.+0.j,  0.+0.j]]], dtype=complex64)

    When ``s=[2, 3]``, dimension of the transform along ``axes (-2, -1)`` will be
    ``(2, 3)`` and dimension along other axes will be the same as that of input.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   jnp.fft.fft2(x, s=[2, 3])
    Array([[[10.  +0.j  , -0.5 -6.06j, -0.5 +6.06j],
            [-2.  +0.j  , -0.5 +0.87j, -0.5 -0.87j]],
    <BLANKLINE>
           [[26.  +0.j  ,  3.5-12.99j,  3.5+12.99j],
            [-2.  +0.j  , -0.5 +0.87j, -0.5 -0.87j]]], dtype=complex64)

    When ``s=[2, 3]`` and ``axes=(0, 1)``, shape of the transform along
    ``axes (0, 1)`` will be ``(2, 3)`` and dimension along other axes will be
    same as that of input.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   jnp.fft.fft2(x, s=[2, 3], axes=(0, 1))
    Array([[[14. +0.j  , 22. +0.j  ],
            [ 2. -6.93j,  4.-10.39j],
            [ 2. +6.93j,  4.+10.39j]],
    <BLANKLINE>
           [[-8. +0.j  , -8. +0.j  ],
            [-2. +3.46j, -2. +3.46j],
            [-2. -3.46j, -2. -3.46j]]], dtype=complex64)

    ``jnp.fft.ifft2`` can be used to reconstruct ``x`` from the result of
    ``jnp.fft.fft2``.

    >>> x_fft2 = jnp.fft.fft2(x)
    >>> jnp.allclose(x, jnp.fft.ifft2(x_fft2))
    Array(True, dtype=bool)
  fft2r   r)   r   )r   r   rO   r]   r^   s       r"   r   r   ,  s/    V 
fj04a14
! 
! 
! !r$   c                J    t          dt          j        j        | |||          S )a:
  Compute a two-dimensional inverse discrete Fourier transform.

  JAX implementation of :func:`numpy.fft.ifft2`.

  Args:
    a: input array. Must have ``a.ndim >= 2``.
    s: optional length-2 sequence of integers. Specifies the size of the output
      in each specified axis. If not specified, it will default to the size of
      ``a`` along the specified ``axes``.
    axes: optional length-2 sequence of integers, default=(-2,-1). Specifies the
      axes along which the transform is computed.
    norm: string, default="backward". The normalization mode. "backward", "ortho"
      and "forward" are supported.

  Returns:
    An array containing the two-dimensional inverse discrete Fourier transform
    of ``a`` along given ``axes``.

  See also:
    - :func:`jax.numpy.fft.ifft`: Computes a one-dimensional inverse discrete
      Fourier transform.
    - :func:`jax.numpy.fft.ifftn`: Computes a multidimensional inverse discrete
      Fourier transform.
    - :func:`jax.numpy.fft.fft2`: Computes a two-dimensional discrete Fourier
      transform.

  Examples:
    ``jnp.fft.ifft2`` computes the transform along the last two axes by default.

    >>> x = jnp.array([[[1, 3],
    ...                 [2, 4]],
    ...                [[5, 7],
    ...                 [6, 8]]])
    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   jnp.fft.ifft2(x)
    Array([[[ 2.5+0.j, -1. +0.j],
            [-0.5+0.j,  0. +0.j]],
    <BLANKLINE>
           [[ 6.5+0.j, -1. +0.j],
            [-0.5+0.j,  0. +0.j]]], dtype=complex64)

    When ``s=[2, 3]``, dimension of the transform along ``axes (-2, -1)`` will be
    ``(2, 3)`` and dimension along other axes will be the same as that of input.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   jnp.fft.ifft2(x, s=[2, 3])
    Array([[[ 1.67+0.j  , -0.08+1.01j, -0.08-1.01j],
            [-0.33+0.j  , -0.08-0.14j, -0.08+0.14j]],
    <BLANKLINE>
           [[ 4.33+0.j  ,  0.58+2.17j,  0.58-2.17j],
            [-0.33+0.j  , -0.08-0.14j, -0.08+0.14j]]], dtype=complex64)

    When ``s=[2, 3]`` and ``axes=(0, 1)``, shape of the transform along
    ``axes (0, 1)`` will be ``(2, 3)`` and dimension along other axes will be
    same as that of input.

    >>> with jnp.printoptions(precision=2, suppress=True):
    ...   jnp.fft.ifft2(x, s=[2, 3], axes=(0, 1))
    Array([[[ 2.33+0.j  ,  3.67+0.j  ],
            [ 0.33+1.15j,  0.67+1.73j],
            [ 0.33-1.15j,  0.67-1.73j]],
    <BLANKLINE>
           [[-1.33+0.j  , -1.33+0.j  ],
            [-0.33-0.58j, -0.33-0.58j],
            [-0.33+0.58j, -0.33+0.58j]]], dtype=complex64)
  ifft2r   )r   r   rO   ra   r^   s       r"   r   r   {  s/    H 
gz16QT
! 
! 
! !r$   c                J    t          dt          j        j        | |||          S )Nrfft2r   )r   r   rO   rd   r^   s       r"   r   r     s.     
gz16QT
! 
! 
! !r$   c                J    t          dt          j        j        | |||          S )Nirfft2r   )r   r   rO   rP   r^   s       r"   r   r     s.     
h
 2 8!qt
! 
! 
! !r$   z
dtype : Optional
    The dtype of the returned frequencies. If not specified, JAX's default
    floating point dtype will be used.
)extra_params      ?r?   dc                  |pt          j        t          j                  }t	          | t
          t          f          rt          dt          |           z            t	          |t
          t          f          rt          dt          |          z            t          j        | |          }| dz  dk    r||j	        d| dz           
                    t          j        d| dz  |                    }|j	        | dz  d          
                    t          j        |  dz  d|                    }n|j	        d| dz
  dz  dz            
                    t          j        d| dz
  dz  dz   |                    }|j	        | dz
  dz  dz   d          
                    t          j        | dz
   dz  d|                    }|t          j        || z  |          z  S )NzFThe n argument of jax.numpy.fft.fftfreq only takes an int. Got n = %s.zNThe d argument of jax.numpy.fft.fftfreq only takes a single value. Got d = %s.r?   r1   r   r   )r   canonicalize_dtyper   float_ri   rN   rB   r!   zerosatrL   aranger   rk   r   r@   ks       r"   fftfreqr     s    
86,SZ88%D%=!! #
q''"# # # !dE]## #
q''"# # # 
i!UaZZ	QQYSZ16???@@A 	
Q!VWW3:qbAgq>>>??AA 	
QQ1q  !%%cjQUqL14DE&R&R&RSSA 	
a!e\A##CJQx1}au$M$M$MNNA	
SYq1uE***	**r$   c                  |pt          j        t          j                  }t	          | t
          t          f          rt          dt          |           z            t	          |t
          t          f          rt          dt          |          z            | dz  dk    rt          j        d| dz  dz   |          }n t          j        d| dz
  dz  dz   |          }|t          j	        || z  |          z  S )NzGThe n argument of jax.numpy.fft.rfftfreq only takes an int. Got n = %s.zOThe d argument of jax.numpy.fft.rfftfreq only takes a single value. Got d = %s.r1   r   r   r?   )
r   r   r   r   ri   rN   rB   r!   r   r   r   s       r"   rfftfreqr     s    
86,SZ88%D%=!! #
q''"# # # !dE]## #
q''"# # # UaZZ
1a1fqj...AA 	
1q1ulQ&e444A	
SYq1uE***	**r$   r5   None | int | Sequence[int]c                J    t          d            t          j                    |3t          t	           j                            }d  j        D             }n4t          |t                    r j        |         dz  }n fd|D             }t          j	         ||          S )Nfftshiftc                    g | ]}|d z  S r1   r3   r4   dims     r"   r7   zfftshift.<locals>.<listcomp>  s    )))#SAX)))r$   r1   c                0    g | ]}j         |         d z  S r   r9   r4   axr5   s     r"   r7   zfftshift.<locals>.<listcomp>  s$    ---"QWR[A---r$   
r	   r   rA   rB   rJ   rK   r:   ri   ro   rollr5   r)   shifts   `  r"   r   r     s    *a   	k!nn!	\qvD)))))EE$ .GDMQEE-------E	!UD	!	!!r$   c                L    t          d            t          j                    |3t          t	           j                            }d  j        D             }n5t          |t                    r j        |         dz   }n fd|D             }t          j	         ||          S )N	ifftshiftc                    g | ]}|d z   	S r   r3   r   s     r"   r7   zifftshift.<locals>.<listcomp>#  s    ,,,Ssax[,,,r$   r1   c                2    g | ]}j         |         d z   S r   r9   r   s     r"   r7   zifftshift.<locals>.<listcomp>'  s'    000Rqwr{a 000r$   r   r   s   `  r"   r   r     s    +q!!!	k!nn!	\qvD,,AG,,,EE$ 1gdmq !EE00004000E	!UD	!	!!r$   )r   r   r   r   r   r   r   r   )r   r   r%   r&   r'   r   r   r(   r)   r*   r   r+   r   r   )NNN)
r'   r   r   r(   r)   r*   r   r+   r   r   )r   r   r<   rg   )r   r   r%   r&   r'   r   rk   rg   r<   rg   r   r+   r   r   )Nr0   N)
r'   r   rk   rg   r<   ro   r   r+   r   r   )r   r   r%   r&   r'   r   r   r(   r)   r   r   r+   r   r   )Nr   N)
r'   r   r   r(   r)   r   r   r+   r   r   )r   )rk   ro   r   r   r   r   rm   )r5   r   r)   r   r   r   )3
__future__r   collections.abcr   rD   numpyrF   jaxr   r   jax._src.libr   jax._src.utilr   jax._src.numpy.utilr	   r
   r   jax._src.numpyr   r   r   r   jax._src.typingr   r   ro   Shaper#   rZ   r\   r`   rU   rc   rf   rj   rn   rt   rv   rx   rz   r   r   r   r   r   r   r   r   r   r   r3   r$   r"   <module>r      s   # " " " " " $ $ $ $ $ $                  # # # # # # " " " " " " S S S S S S S S S S + + + + + + - - - - - - - - , , , , , , , ,- - - -> > > >B *.&* GE GE GE GE GET +/'+!AG AG AG AG AGH BFL*.'+!G G G G G BFM+/(,"I I I I I   : : : : '++/<! <! <! <! <!~ (,,05! 5! 5! 5! 5!p (,,0:! :! :! :! :!z )--19! 9! 9! 9! 9!v BFK'+,0& & & & & BFL(,-1( ( ( ( (	: 	: 	: 	: FM L! L! L! L! L!^ GN!E! E! E! E! E!N BFLFM!! ! ! ! !
 BFMGN"! ! ! ! ! BFN *   
+ + + + + + 
+< BFO +   
+$ + + + + + 
+* BFO" " " " " BF" " " " " " "r$   