
    `i%                     t    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Z	d Z
dd
ZddZddZddZdS )    N)_core)internal)_util)specialFc                    t           j        t           j        g}|s|t           j        t           j        gz  }| L|j        |v r!t          j        |j        |j                  } nt          j        |j        |d                   } ndt          |           t          u r/| |vrt          d          t          j        |j        |           } n| j        |j        k    rt          d          | S )Ndtypezoutput type not supportedzoutput shape not correct)
cupy	complex64
complex128float32float64r	   emptyshapetypeRuntimeError)outputinputcomplex_onlytypess       p/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupyx/scipy/ndimage/_fourier.py_get_output_fourierr   
   s    ^T_-E .$,--~;%Z5;???FFZ59===FF	f		:;;;EKv666		$	$5666M    c                 `    d|z  | j         fz   d||z
  dz
  z  z   }|                     |          S )z>Promote a 1d array to ndim with non-singleton size along axis.)   r   )sizereshape)arrndimaxisnd_shapes       r   _reshape_ndr#      s8    d{ch[(44$;?+CCH;;x   r   r
   c                    | j         }t          ||           }t          j        ||          }t	          j        ||d          }t          j        | |           t          t          ||j
                            D ]\  }\  }}	||k    r,|dk    r&t          j        |	|j        j                  }
|
|z  }
nt          j                            |	          }
|
                    |j        j        d          }
|
|
z  }
||z  dz  }|
dt$          j        z  t$          j        z  |z  z  }
t          j        |
|
           t+          |
||	          }
||
z  }|S )
a  Multidimensional Gaussian shift filter.

    The array is multiplied with the Fourier transform of a (separable)
    Gaussian kernel.

    Args:
        input (cupy.ndarray): The input array.
        sigma (float or sequence of float):  The sigma of the Gaussian kernel.
            If a float, `sigma` is the same for all axes. If a sequence,
            `sigma` has to contain one value for each axis.
        n (int, optional):  If `n` is negative (default), then the input is
            assumed to be the result of a complex fft. If `n` is larger than or
            equal to zero, the input is assumed to be the result of a real fft,
            and `n` gives the length of the array before transformation along
            the real transform direction.
        axis (int, optional): The axis of the real transform (only used when
            ``n > -1``).
        output (cupy.ndarray, optional):
            If given, the result of shifting the input is placed in this array.

    Returns:
        output (cupy.ndarray): The filtered output.
    sigmar   r   Fcopy   outr    r!   )r    r   r   _normalize_axis_indexr   _fix_sequence_argr   elementwise_copy	enumeratezipr   r   arangerealr	   fftfftfreqastypenumpypiexpr#   )r   r%   nr!   r   r    sigmasaxsigmakax_sizer   scales               r   fourier_gaussianr@   #   sV   0 :D //F)$55D$UD'::F	5&)))!*3vv|+D+D!E!E  VW ::!a%%+gV[->???C1HCC(""7++Cjj*j77 	s
"$EHux'500# #Dr222#Mr   c                 R   | j         }t          ||           }t          j        ||          }t	          j        ||d          }t          j        | |           t          t          ||j
                            D ]\  }\  }}||k    r,|dk    r&t          j        ||j        j                  }	|	|z  }	nt          j                            |          }	|	                    |j        j        d          }	|	|z  }	t          j        |	|	           t'          |	||          }	||	z  }|S )a  Multidimensional uniform shift filter.

    The array is multiplied with the Fourier transform of a box of given size.

    Args:
        input (cupy.ndarray): The input array.
        size (float or sequence of float):  The sigma of the box used for
            filtering. If a float, `size` is the same for all axes. If a
            sequence, `size` has to contain one value for each axis.
        n (int, optional):  If `n` is negative (default), then the input is
            assumed to be the result of a complex fft. If `n` is larger than or
            equal to zero, the input is assumed to be the result of a real fft,
            and `n` gives the length of the array before transformation along
            the real transform direction.
        axis (int, optional): The axis of the real transform (only used when
            ``n > -1``).
        output (cupy.ndarray, optional):
            If given, the result of shifting the input is placed in this array.

    Returns:
        output (cupy.ndarray): The filtered output.
    r   r   r   Fr&   r*   r,   )r    r   r   r-   r   r.   r   r/   r0   r1   r   r   r2   r3   r	   r4   r5   r6   sincr#   )
r   r   r:   r!   r   r    sizesr<   r>   r   s
             r   fourier_uniformrD   X   s+   . :D //F)$55D#D$77E	5&)))(UFL)A)ABB  OT7 ::!a%%+gV[->???C1HCC(""7++Cjj*j77 	t	#3 #Dr222#Mr   c                 ^   | j         }t          || d          }t          j        ||          }t	          j        ||d          }t          j        | |           t          t          ||j
                            D ]\  }\  }}	|dk    r||k    r:|dk    r4t          j        |	|j                  }
|
dt          j        z  |z  |z  z  }
n4t          j                            |	          }
|
dt          j        z  |z  z  }
t          j        |
|
           t'          |
||          }
||
z  }|S )	aF  Multidimensional Fourier shift filter.

    The array is multiplied with the Fourier transform of a shift operation.

    Args:
        input (cupy.ndarray): The input array. This should be in the Fourier
            domain.
        shift (float or sequence of float):  The size of shift. If a float,
            `shift` is the same for all axes. If a sequence, `shift` has to
            contain one value for each axis.
        n (int, optional):  If `n` is negative (default), then the input is
            assumed to be the result of a complex fft. If `n` is larger than or
            equal to zero, the input is assumed to be the result of a real fft,
            and `n` gives the length of the array before transformation along
            the real transform direction.
        axis (int, optional): The axis of the real transform (only used when
            ``n > -1``).
        output (cupy.ndarray, optional):
            If given, the result of shifting the input is placed in this array.

    Returns:
        output (cupy.ndarray): The shifted output (in the Fourier domain).
    T)r   shiftr   r   y              r*   r,   )r    r   r   r-   r   r.   r   r/   r0   r1   r   r   r2   r	   r7   r8   r4   r5   r9   r#   )r   rF   r:   r!   r   r    shiftsr<   shiftkr>   r   s              r   fourier_shiftrI      s9   0 :D TBBBF)$55D$UD'::F	5&)))!*3vv|+D+D!E!E  VWQ;;::!a%%+gV\:::C3>F*Q..CC(""7++Cux&01C# #Dr222#Mr   c                    | j         }|dk    rt          | ||||          S |dk    rt          d          t          ||           }t	          j        ||          }t          j        ||d          }t          j	        | |           d}t          t          ||j                            D ]\  }\  }}	||k    r<|dk    r6t          j        |	|j        j                  }
|
t"          j        |z  |z  z  }
n1t          j                            |	          }
|
t"          j        |z  z  }
|
                    |j        j        d          }
|
|
z  }
t-          |
||	          }
||
z   }t          j        ||
           |dk    r!t1          j        ||
           |dz  }||z  }nC|dk    r=t          j        ||
           ||t          j        |          z  z  }|dz  }||dz  z  }d|d|z  <   || z  }|S )a   Multidimensional ellipsoid Fourier filter.

    The array is multiplied with the fourier transform of a ellipsoid of
    given sizes.

    Args:
        input (cupy.ndarray): The input array.
        size (float or sequence of float):  The size of the box used for
            filtering. If a float, `size` is the same for all axes. If a
            sequence, `size` has to contain one value for each axis.
        n (int, optional):  If `n` is negative (default), then the input is
            assumed to be the result of a complex fft. If `n` is larger than or
            equal to zero, the input is assumed to be the result of a real fft,
            and `n` gives the length of the array before transformation along
            the real transform direction.
        axis (int, optional): The axis of the real transform (only used when
            ``n > -1``).
        output (cupy.ndarray, optional):
            If given, the result of shifting the input is placed in this array.

    Returns:
        output (cupy.ndarray): The filtered output.
    r      z'Only 1d, 2d and 3d inputs are supportedr   r   r   Fr&   r,   r*      g      ?)r   )r    rD   NotImplementedErrorr   r   r-   r   r.   r   r/   r0   r1   r   r   r2   r3   r	   r7   r8   r4   r5   r6   r#   sqrtr   j1sincos)r   r   r:   r!   r   r    rC   distancer<   r>   r   s              r   fourier_ellipsoidrS      s   0 :DqyyudAtV<<<axx ""KLLL //F)$55D#D$77E	5&))) H(UFL)A)ABB " "OT7::!a%%+gV[->???C58d?Q&&CC(""7++C58d?"Cjj*j77s
#Dr222c>IhH%%%%qyy
8((((!(	v&&&&(TXh////!(a-F4$;
eOFMr   )F)r
   r
   N)r7   r   r   
cupy._corer   cupyx.scipy.ndimager   cupyx.scipyr   r   r#   r@   rD   rI   rS    r   r   <module>rX      s                  % % % % % %         &! ! !2 2 2 2j/ / / /d. . . .bB B B B B Br   