function x = ifft(x, varargin)
%IFFT Inverse discrete Fourier transform
%   Y = IFFT(X)
%   Y = IFFT(X,M)
%   Y = IFFT(X,[],DIM)
%   Y = IFFT(X,M,DIM)
%   Y = IFFT(..., 'symmetric')
%   Y = IFFT(..., 'nonsymmetric')
%
%   Input X must be unformatted.
%
%   The order of operations within the IFFT operation can change based on
%   the internal storage order of the dlarray. This can result in
%   differences on the order of round-off for two dlarrays that are
%   otherwise equal.
%
%   With the 'symmetric' option, ifft treats the input X as exactly
%   symmetric. The derivative computed using automatic differentiation is
%   also exactly symmetric. If X is non-symmetric, then the function and
%   gradient behavior might not match. To ensure that function and gradient
%   behavior match for non-symmetric inputs, explicitly symmetrize X.
%
%   See also IFFT, DLARRAY, GPUARRAY/IFFT, DLARRAY/FFT.

%   Copyright 2021-2023 The MathWorks, Inc.

if nargin > 1 && ~isa(x, 'dlarray')
    varargin = extractDlarrayCell(varargin);
    x = ifft(x, varargin{:});
    return;
end

[x, fdx, xdata, args] = helperFFT(x, 'ifft', 'deep:dlarray:AcceleratedInverseLengthNotSupported', varargin);

xdata = ifft(xdata, args{:});

x.FormattedData = insertData(fdx, xdata);
end
